diff options
Diffstat (limited to 'modules')
257 files changed, 0 insertions, 4223 deletions
diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index cc74674eff..a861b39537 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -53,7 +53,6 @@ aiBone *get_bone_by_name(const aiScene *scene, aiString bone_name) { // iterate over all the bones on the mesh for this node only! for (unsigned int boneIndex = 0; boneIndex < mesh->mNumBones; boneIndex++) { - aiBone *bone = mesh->mBones[boneIndex]; if (bone->mName == bone_name) { printf("matched bone by name: %s\n", bone->mName.C_Str()); @@ -66,7 +65,6 @@ aiBone *get_bone_by_name(const aiScene *scene, aiString bone_name) { } void EditorSceneImporterAssimp::get_extensions(List<String> *r_extensions) const { - const String import_setting_string = "filesystem/import/open_asset_import/"; Map<String, ImportFormat> import_format; @@ -156,14 +154,11 @@ Node *EditorSceneImporterAssimp::import_scene(const String &p_path, uint32_t p_f template <class T> struct EditorSceneImporterAssetImportInterpolate { - T lerp(const T &a, const T &b, float c) const { - return a + (b - a) * c; } T catmull_rom(const T &p0, const T &p1, const T &p2, const T &p3, float t) { - float t2 = t * t; float t3 = t2 * t; @@ -185,7 +180,6 @@ struct EditorSceneImporterAssetImportInterpolate { //thank you for existing, partial specialization template <> struct EditorSceneImporterAssetImportInterpolate<Quat> { - Quat lerp(const Quat &a, const Quat &b, float c) const { ERR_FAIL_COND_V_MSG(!a.is_normalized(), Quat(), "The quaternion \"a\" must be normalized."); ERR_FAIL_COND_V_MSG(!b.is_normalized(), Quat(), "The quaternion \"b\" must be normalized."); @@ -223,7 +217,6 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co switch (p_interp) { case AssetImportAnimation::INTERP_LINEAR: { - if (idx == -1) { return p_values[0]; } else if (idx >= p_times.size() - 1) { @@ -236,7 +229,6 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co } break; case AssetImportAnimation::INTERP_STEP: { - if (idx == -1) { return p_values[0]; } else if (idx >= p_times.size() - 1) { @@ -247,7 +239,6 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co } break; case AssetImportAnimation::INTERP_CATMULLROMSPLINE: { - if (idx == -1) { return p_values[1]; } else if (idx >= p_times.size() - 1) { @@ -260,7 +251,6 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co } break; case AssetImportAnimation::INTERP_CUBIC_SPLINE: { - if (idx == -1) { return p_values[1]; } else if (idx >= p_times.size() - 1) { @@ -310,7 +300,6 @@ EditorSceneImporterAssimp::_generate_scene(const String &p_path, aiScene *scene, // populate light map for (unsigned int l = 0; l < scene->mNumLights; l++) { - aiLight *ai_light = scene->mLights[l]; ERR_CONTINUE(ai_light == nullptr); state.light_cache[AssimpUtils::get_assimp_string(ai_light->mName)] = l; @@ -490,7 +479,6 @@ EditorSceneImporterAssimp::_generate_scene(const String &p_path, aiScene *scene, if (assimp_node->mNumMeshes > 0) { MeshInstance3D *mesh = create_mesh(state, assimp_node, node_name, parent_node, node_transform); if (mesh) { - parent_node->remove_child(mesh_template); // re-parent children @@ -530,7 +518,6 @@ EditorSceneImporterAssimp::_generate_scene(const String &p_path, aiScene *scene, } if (p_flags & IMPORT_ANIMATION && scene->mNumAnimations) { - state.animation_player = memnew(AnimationPlayer); state.root->add_child(state.animation_player); state.animation_player->set_owner(state.root); @@ -621,7 +608,6 @@ void EditorSceneImporterAssimp::_insert_animation_track(ImportState &scene, cons int skeleton_bone = skeleton->find_bone(node_name); if (skeleton_bone >= 0 && track_bone) { - Transform xform; xform.basis.set_quat_scale(rot, scale); xform.origin = pos; @@ -666,7 +652,6 @@ Node *EditorSceneImporterAssimp::get_node_by_name(ImportState &state, String nam /* Bone stack is a fifo handler for multiple armatures since armatures aren't a thing in assimp (yet) */ void EditorSceneImporterAssimp::RegenerateBoneStack(ImportState &state) { - state.bone_stack.clear(); // build bone stack list for (unsigned int mesh_id = 0; mesh_id < state.assimp_scene->mNumMeshes; ++mesh_id) { @@ -700,7 +685,6 @@ void EditorSceneImporterAssimp::RegenerateBoneStack(ImportState &state, aiMesh * // animation tracks are per bone void EditorSceneImporterAssimp::_import_animation(ImportState &state, int p_animation_index, int p_bake_fps) { - ERR_FAIL_INDEX(p_animation_index, (int)state.assimp_scene->mNumAnimations); const aiAnimation *anim = state.assimp_scene->mAnimations[p_animation_index]; @@ -795,7 +779,6 @@ void EditorSceneImporterAssimp::_import_animation(ImportState &state, int p_anim //blend shape tracks for (size_t i = 0; i < anim->mNumMorphMeshChannels; i++) { - const aiMeshMorphAnim *anim_mesh = anim->mMorphMeshChannels[i]; const String prop_name = AssimpUtils::get_assimp_string(anim_mesh->mName); @@ -816,14 +799,12 @@ void EditorSceneImporterAssimp::_import_animation(ImportState &state, int p_anim //add the tracks for this mesh int base_track = animation->get_track_count(); for (int j = 0; j < mesh->get_blend_shape_count(); j++) { - animation->add_track(Animation::TYPE_VALUE); animation->track_set_path(base_track + j, base_path + ":blend_shapes/" + mesh->get_blend_shape_name(j)); } for (size_t k = 0; k < anim_mesh->mNumKeys; k++) { for (size_t j = 0; j < anim_mesh->mKeys[k].mNumValuesAndWeights; j++) { - float t = anim_mesh->mKeys[k].mTime / ticks_per_second; float w = anim_mesh->mKeys[k].mWeights[j]; @@ -843,7 +824,6 @@ Ref<Mesh> EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &state, const Vector<int> &p_surface_indices, const aiNode *assimp_node, Ref<Skin> &skin, Skeleton3D *&skeleton_assigned) { - Ref<ArrayMesh> mesh; mesh.instance(); bool has_uvs = false; @@ -894,7 +874,6 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat int bone_index = skeleton_assigned->find_bone(bone_name); ERR_CONTINUE(bone_index == -1); for (size_t w = 0; w < bone->mNumWeights; w++) { - aiVertexWeight ai_weights = bone->mWeights[w]; BoneInfo bi; @@ -920,7 +899,6 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat st->begin(Mesh::PRIMITIVE_TRIANGLES); for (size_t j = 0; j < ai_mesh->mNumVertices; j++) { - // Get the texture coordinates if they exist if (ai_mesh->HasTextureCoords(0)) { has_uvs = true; @@ -956,7 +934,6 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat // We have vertex weights right? if (vertex_weights.has(j)) { - Vector<BoneInfo> bone_info = vertex_weights[j]; Vector<int> bones; bones.resize(bone_info.size()); @@ -1200,7 +1177,6 @@ EditorSceneImporterAssimp::_generate_mesh_from_surface_indices(ImportState &stat Mesh::PrimitiveType primitive = Mesh::PRIMITIVE_TRIANGLES; for (size_t j = 0; j < ai_mesh->mNumAnimMeshes; j++) { - String ai_anim_mesh_name = AssimpUtils::get_assimp_string(ai_mesh->mAnimMeshes[j]->mName); if (ai_anim_mesh_name.empty()) { @@ -1482,7 +1458,6 @@ Node3D *EditorSceneImporterAssimp::create_camera( void EditorSceneImporterAssimp::_generate_node( ImportState &state, const aiNode *assimp_node) { - ERR_FAIL_COND(assimp_node == nullptr); state.nodes.push_back(assimp_node); String parent_name = AssimpUtils::get_assimp_string(assimp_node->mParent->mName); diff --git a/modules/assimp/import_state.h b/modules/assimp/import_state.h index cda1a854f0..4a3bd17acb 100644 --- a/modules/assimp/import_state.h +++ b/modules/assimp/import_state.h @@ -55,7 +55,6 @@ namespace AssimpImporter { * This makes the code simpler and contains useful lookups. */ struct ImportState { - String path; Node3D *root; const aiScene *assimp_scene; diff --git a/modules/assimp/import_utils.h b/modules/assimp/import_utils.h index e3510c2cb3..dc85d06fed 100644 --- a/modules/assimp/import_utils.h +++ b/modules/assimp/import_utils.h @@ -162,7 +162,6 @@ public: } static String get_anim_string_from_assimp(const aiString &p_string) { - String name; name.parse_utf8(p_string.C_Str() /*,p_string.length*/); if (name.find(":") != -1) { @@ -354,7 +353,6 @@ public: * Load or load from cache image :) */ static Ref<Image> load_image(ImportState &state, const aiScene *p_scene, String p_path) { - Map<String, Ref<Image>>::Element *match = state.path_to_image_cache.find(p_path); // if our cache contains this image then don't bother diff --git a/modules/assimp/register_types.cpp b/modules/assimp/register_types.cpp index 3af8827bf9..6cb0fc982f 100644 --- a/modules/assimp/register_types.cpp +++ b/modules/assimp/register_types.cpp @@ -42,7 +42,6 @@ static void _editor_init() { #endif void register_assimp_types() { - #ifdef TOOLS_ENABLED ClassDB::APIType prev_api = ClassDB::get_current_api(); ClassDB::set_current_api(ClassDB::API_EDITOR); diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index f31c889a6d..d3cfcc0092 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -54,7 +54,6 @@ basist::etc1_global_selector_codebook *sel_codebook = nullptr; #ifdef TOOLS_ENABLED static Vector<uint8_t> basis_universal_packer(const Ref<Image> &p_image, Image::UsedChannels p_channels) { - Vector<uint8_t> budata; { @@ -163,7 +162,6 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) { switch (*(uint32_t *)(ptr)) { case BASIS_DECOMPRESS_RG: { - if (RS::get_singleton()->has_os_feature("rgtc")) { format = basist::transcoder_texture_format::cTFBC5; // get this from renderer imgfmt = Image::FORMAT_RGTC_RG; @@ -186,7 +184,6 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) { format = basist::transcoder_texture_format::cTFBC1; // get this from renderer imgfmt = Image::FORMAT_DXT1; } else if (RS::get_singleton()->has_os_feature("etc")) { - format = basist::transcoder_texture_format::cTFETC1; // get this from renderer imgfmt = Image::FORMAT_ETC; } else { @@ -249,7 +246,6 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) { int ofs = 0; tr.start_transcoding(ptr, size); for (uint32_t i = 0; i < info.m_total_levels; i++) { - basist::basisu_image_level_info level; tr.get_image_level_info(ptr, size, level, 0, i); @@ -279,7 +275,6 @@ void register_basis_universal_types() { } void unregister_basis_universal_types() { - #ifdef TOOLS_ENABLED delete sel_codebook; Image::basis_universal_packer = nullptr; diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp index f69f3a43a4..89947d1ef9 100644 --- a/modules/bmp/image_loader_bmp.cpp +++ b/modules/bmp/image_loader_bmp.cpp @@ -35,7 +35,6 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image, const uint8_t *p_color_buffer, const uint32_t color_table_size, const bmp_header_s &p_header) { - Error err = OK; if (p_buffer == nullptr) @@ -60,7 +59,6 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image, ERR_FAIL_COND_V(height % 2 != 0, ERR_UNAVAILABLE); } else if (bits_per_pixel == 16) { - ERR_FAIL_V(ERR_UNAVAILABLE); } @@ -201,7 +199,6 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image, Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { - bmp_header_s bmp_header; Error err = ERR_INVALID_DATA; @@ -290,7 +287,6 @@ Error ImageLoaderBMP::load_image(Ref<Image> p_image, FileAccess *f, void ImageLoaderBMP::get_recognized_extensions( List<String> *p_extensions) const { - p_extensions->push_back("bmp"); } diff --git a/modules/bullet/area_bullet.cpp b/modules/bullet/area_bullet.cpp index a4a86ab751..d5b03015a9 100644 --- a/modules/bullet/area_bullet.cpp +++ b/modules/bullet/area_bullet.cpp @@ -45,7 +45,6 @@ AreaBullet::AreaBullet() : RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_AREA) { - btGhost = bulletnew(btGhostObject); reload_shapes(); setupBulletCollisionObject(btGhost); @@ -91,7 +90,6 @@ void AreaBullet::dispatch_callbacks() { } void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer3D::AreaBodyStatus p_status) { - InOutEventCallback &event = eventsCallbacks[static_cast<int>(p_otherObject->getType())]; Object *areaGodoObject = ObjectDB::get_instance(event.event_callback_id); diff --git a/modules/bullet/btRayShape.cpp b/modules/bullet/btRayShape.cpp index 0f54f848dc..ee84354315 100644 --- a/modules/bullet/btRayShape.cpp +++ b/modules/bullet/btRayShape.cpp @@ -50,7 +50,6 @@ btRayShape::~btRayShape() { } void btRayShape::setLength(btScalar p_length) { - m_length = p_length; reload_cache(); } @@ -61,7 +60,6 @@ void btRayShape::setMargin(btScalar margin) { } void btRayShape::setSlipsOnSlope(bool p_slipsOnSlope) { - slipsOnSlope = p_slipsOnSlope; } @@ -101,7 +99,6 @@ void btRayShape::getPreferredPenetrationDirection(int index, btVector3 &penetrat } void btRayShape::reload_cache() { - m_cacheScaledLength = m_length * m_localScaling[2]; m_cacheSupportPoint.setIdentity(); diff --git a/modules/bullet/btRayShape.h b/modules/bullet/btRayShape.h index df6dd93d57..d9ecde81e6 100644 --- a/modules/bullet/btRayShape.h +++ b/modules/bullet/btRayShape.h @@ -42,7 +42,6 @@ /// Ray shape around z axis ATTRIBUTE_ALIGNED16(class) btRayShape : public btConvexInternalShape { - btScalar m_length; bool slipsOnSlope; /// The default axis is the z diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index 09a5f6f983..c20fade011 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -88,35 +88,27 @@ RID BulletPhysicsServer3D::shape_create(ShapeType p_shape) { switch (p_shape) { case SHAPE_PLANE: { - shape = bulletnew(PlaneShapeBullet); } break; case SHAPE_SPHERE: { - shape = bulletnew(SphereShapeBullet); } break; case SHAPE_BOX: { - shape = bulletnew(BoxShapeBullet); } break; case SHAPE_CAPSULE: { - shape = bulletnew(CapsuleShapeBullet); } break; case SHAPE_CYLINDER: { - shape = bulletnew(CylinderShapeBullet); } break; case SHAPE_CONVEX_POLYGON: { - shape = bulletnew(ConvexPolygonShapeBullet); } break; case SHAPE_CONCAVE_POLYGON: { - shape = bulletnew(ConcavePolygonShapeBullet); } break; case SHAPE_HEIGHTMAP: { - shape = bulletnew(HeightMapShapeBullet); } break; case SHAPE_RAY: { @@ -176,7 +168,6 @@ RID BulletPhysicsServer3D::space_create() { } void BulletPhysicsServer3D::space_set_active(RID p_space, bool p_active) { - SpaceBullet *space = space_owner.getornull(p_space); ERR_FAIL_COND(!space); @@ -371,7 +362,6 @@ void BulletPhysicsServer3D::area_set_param(RID p_area, AreaParameter p_param, co space->set_param(p_param, p_value); } } else { - AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); @@ -497,7 +487,6 @@ PhysicsServer3D::BodyMode BulletPhysicsServer3D::body_get_mode(RID p_body) const } void BulletPhysicsServer3D::body_add_shape(RID p_body, RID p_shape, const Transform &p_transform, bool p_disabled) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_body); ERR_FAIL_COND(!body); @@ -651,7 +640,6 @@ void BulletPhysicsServer3D::body_set_kinematic_safe_margin(RID p_body, real_t p_ ERR_FAIL_COND(!body); if (body->get_kinematic_utilities()) { - body->get_kinematic_utilities()->setSafeMargin(p_margin); } } @@ -661,7 +649,6 @@ real_t BulletPhysicsServer3D::body_get_kinematic_safe_margin(RID p_body) const { ERR_FAIL_COND_V(!body, 0); if (body->get_kinematic_utilities()) { - return body->get_kinematic_utilities()->safe_margin; } @@ -1487,7 +1474,6 @@ int BulletPhysicsServer3D::generic_6dof_joint_get_precision(RID p_joint) { void BulletPhysicsServer3D::free(RID p_rid) { if (shape_owner.owns(p_rid)) { - ShapeBullet *shape = shape_owner.getornull(p_rid); // Notify the shape is configured @@ -1498,7 +1484,6 @@ void BulletPhysicsServer3D::free(RID p_rid) { shape_owner.free(p_rid); bulletdelete(shape); } else if (rigid_body_owner.owns(p_rid)) { - RigidBodyBullet *body = rigid_body_owner.getornull(p_rid); body->set_space(nullptr); @@ -1509,7 +1494,6 @@ void BulletPhysicsServer3D::free(RID p_rid) { bulletdelete(body); } else if (soft_body_owner.owns(p_rid)) { - SoftBodyBullet *body = soft_body_owner.getornull(p_rid); body->set_space(nullptr); @@ -1518,7 +1502,6 @@ void BulletPhysicsServer3D::free(RID p_rid) { bulletdelete(body); } else if (area_owner.owns(p_rid)) { - AreaBullet *area = area_owner.getornull(p_rid); area->set_space(nullptr); @@ -1529,14 +1512,12 @@ void BulletPhysicsServer3D::free(RID p_rid) { bulletdelete(area); } else if (joint_owner.owns(p_rid)) { - JointBullet *joint = joint_owner.getornull(p_rid); joint->destroy_internal_constraint(); joint_owner.free(p_rid); bulletdelete(joint); } else if (space_owner.owns(p_rid)) { - SpaceBullet *space = space_owner.getornull(p_rid); space->remove_all_collision_objects(); @@ -1545,7 +1526,6 @@ void BulletPhysicsServer3D::free(RID p_rid) { space_owner.free(p_rid); bulletdelete(space); } else { - ERR_FAIL_MSG("Invalid ID."); } } @@ -1561,7 +1541,6 @@ void BulletPhysicsServer3D::step(float p_deltaTime) { BulletPhysicsDirectBodyState3D::singleton_setDeltaTime(p_deltaTime); for (int i = 0; i < active_spaces_count; ++i) { - active_spaces[i]->step(p_deltaTime); } } diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp index 9ad74ad262..0d456a155a 100644 --- a/modules/bullet/collision_object_bullet.cpp +++ b/modules/bullet/collision_object_bullet.cpp @@ -184,7 +184,6 @@ int CollisionObjectBullet::get_godot_object_flags() const { } void CollisionObjectBullet::set_transform(const Transform &p_global_transform) { - set_body_scale(p_global_transform.basis.get_scale_abs()); btTransform bt_transform; @@ -323,7 +322,6 @@ void RigidCollisionObjectBullet::shape_changed(int p_shape_index) { } void RigidCollisionObjectBullet::reload_shapes() { - if (mainShape && mainShape->isCompound()) { // Destroy compound bulletdelete(mainShape); diff --git a/modules/bullet/cone_twist_joint_bullet.cpp b/modules/bullet/cone_twist_joint_bullet.cpp index aac51034b8..b4735fa9e9 100644 --- a/modules/bullet/cone_twist_joint_bullet.cpp +++ b/modules/bullet/cone_twist_joint_bullet.cpp @@ -42,7 +42,6 @@ ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &rbAFrame, const Transform &rbBFrame) : JointBullet() { - Transform scaled_AFrame(rbAFrame.scaled(rbA->get_body_scale())); scaled_AFrame.basis.rotref_posscale_decomposition(scaled_AFrame.basis); @@ -50,7 +49,6 @@ ConeTwistJointBullet::ConeTwistJointBullet(RigidBodyBullet *rbA, RigidBodyBullet G_TO_B(scaled_AFrame, btFrameA); if (rbB) { - Transform scaled_BFrame(rbBFrame.scaled(rbB->get_body_scale())); scaled_BFrame.basis.rotref_posscale_decomposition(scaled_BFrame.basis); diff --git a/modules/bullet/constraint_bullet.h b/modules/bullet/constraint_bullet.h index 125940439f..538808be51 100644 --- a/modules/bullet/constraint_bullet.h +++ b/modules/bullet/constraint_bullet.h @@ -45,7 +45,6 @@ class SpaceBullet; class btTypedConstraint; class ConstraintBullet : public RIDBullet { - protected: SpaceBullet *space = nullptr; btTypedConstraint *constraint = nullptr; diff --git a/modules/bullet/generic_6dof_joint_bullet.cpp b/modules/bullet/generic_6dof_joint_bullet.cpp index 638944df76..56a66dba45 100644 --- a/modules/bullet/generic_6dof_joint_bullet.cpp +++ b/modules/bullet/generic_6dof_joint_bullet.cpp @@ -42,7 +42,6 @@ Generic6DOFJointBullet::Generic6DOFJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB) : JointBullet() { - for (int i = 0; i < 3; i++) { for (int j = 0; j < PhysicsServer3D::G6DOF_JOINT_FLAG_MAX; j++) { flags[i][j] = false; diff --git a/modules/bullet/godot_collision_configuration.cpp b/modules/bullet/godot_collision_configuration.cpp index 8e29845a36..ec7a1dbd9a 100644 --- a/modules/bullet/godot_collision_configuration.cpp +++ b/modules/bullet/godot_collision_configuration.cpp @@ -41,7 +41,6 @@ GodotCollisionConfiguration::GodotCollisionConfiguration(const btDiscreteDynamicsWorld *world, const btDefaultCollisionConstructionInfo &constructionInfo) : btDefaultCollisionConfiguration(constructionInfo) { - void *mem = nullptr; mem = btAlignedAlloc(sizeof(GodotRayWorldAlgorithm::CreateFunc), 16); @@ -60,44 +59,33 @@ GodotCollisionConfiguration::~GodotCollisionConfiguration() { } btCollisionAlgorithmCreateFunc *GodotCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1) { - if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - // This collision is not supported return m_emptyCreateFunc; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) { - return m_rayWorldCF; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - return m_swappedRayWorldCF; } else { - return btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0, proxyType1); } } btCollisionAlgorithmCreateFunc *GodotCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1) { - if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - // This collision is not supported return m_emptyCreateFunc; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) { - return m_rayWorldCF; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - return m_swappedRayWorldCF; } else { - return btDefaultCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(proxyType0, proxyType1); } } GodotSoftCollisionConfiguration::GodotSoftCollisionConfiguration(const btDiscreteDynamicsWorld *world, const btDefaultCollisionConstructionInfo &constructionInfo) : btSoftBodyRigidBodyCollisionConfiguration(constructionInfo) { - void *mem = nullptr; mem = btAlignedAlloc(sizeof(GodotRayWorldAlgorithm::CreateFunc), 16); @@ -116,37 +104,27 @@ GodotSoftCollisionConfiguration::~GodotSoftCollisionConfiguration() { } btCollisionAlgorithmCreateFunc *GodotSoftCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1) { - if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - // This collision is not supported return m_emptyCreateFunc; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) { - return m_rayWorldCF; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - return m_swappedRayWorldCF; } else { - return btSoftBodyRigidBodyCollisionConfiguration::getCollisionAlgorithmCreateFunc(proxyType0, proxyType1); } } btCollisionAlgorithmCreateFunc *GodotSoftCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1) { - if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0 && CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - // This collision is not supported return m_emptyCreateFunc; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType0) { - return m_rayWorldCF; } else if (CUSTOM_CONVEX_SHAPE_TYPE == proxyType1) { - return m_swappedRayWorldCF; } else { - return btSoftBodyRigidBodyCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(proxyType0, proxyType1); } } diff --git a/modules/bullet/godot_motion_state.h b/modules/bullet/godot_motion_state.h index e2c1b10e94..90d1614a77 100644 --- a/modules/bullet/godot_motion_state.h +++ b/modules/bullet/godot_motion_state.h @@ -46,7 +46,6 @@ class RigidBodyBullet; /// DOC: /// http://www.bulletphysics.org/mediawiki-1.5.8/index.php/MotionStates#What.27s_a_MotionState.3F class GodotMotionState : public btMotionState { - /// This data is used to store the new world position for kinematic body btTransform bodyKinematicWorldTransf; /// This data is used to store last world position diff --git a/modules/bullet/godot_ray_world_algorithm.cpp b/modules/bullet/godot_ray_world_algorithm.cpp index 2caa75c2a7..fbb336ca56 100644 --- a/modules/bullet/godot_ray_world_algorithm.cpp +++ b/modules/bullet/godot_ray_world_algorithm.cpp @@ -61,7 +61,6 @@ GodotRayWorldAlgorithm::~GodotRayWorldAlgorithm() { } void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap, const btDispatcherInfo &dispatchInfo, btManifoldResult *resultOut) { - if (!m_manifoldPtr) { if (m_isSwapped) { m_manifoldPtr = m_dispatcher->getNewManifold(body1Wrap->getCollisionObject(), body0Wrap->getCollisionObject()); @@ -79,13 +78,11 @@ void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *bo const btCollisionObjectWrapper *other_co_wrapper; if (m_isSwapped) { - ray_shape = static_cast<const btRayShape *>(body1Wrap->getCollisionShape()); ray_transform = body1Wrap->getWorldTransform(); other_co_wrapper = body0Wrap; } else { - ray_shape = static_cast<const btRayShape *>(body0Wrap->getCollisionShape()); ray_transform = body0Wrap->getWorldTransform(); @@ -99,7 +96,6 @@ void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *bo m_world->rayTestSingleInternal(ray_transform, to, other_co_wrapper, btResult); if (btResult.hasHit()) { - btScalar depth(ray_shape->getScaledLength() * (btResult.m_closestHitFraction - 1)); if (depth > -RAY_PENETRATION_DEPTH_EPSILON) diff --git a/modules/bullet/godot_ray_world_algorithm.h b/modules/bullet/godot_ray_world_algorithm.h index ec7f68dc51..45344186f5 100644 --- a/modules/bullet/godot_ray_world_algorithm.h +++ b/modules/bullet/godot_ray_world_algorithm.h @@ -42,7 +42,6 @@ class btDiscreteDynamicsWorld; class GodotRayWorldAlgorithm : public btActivatingCollisionAlgorithm { - const btDiscreteDynamicsWorld *m_world; btPersistentManifold *m_manifoldPtr; bool m_ownManifold = false; @@ -61,7 +60,6 @@ public: manifoldArray.push_back(m_manifoldPtr); } struct CreateFunc : public btCollisionAlgorithmCreateFunc { - const btDiscreteDynamicsWorld *m_world; CreateFunc(const btDiscreteDynamicsWorld *world); @@ -72,7 +70,6 @@ public: }; struct SwappedCreateFunc : public btCollisionAlgorithmCreateFunc { - const btDiscreteDynamicsWorld *m_world; SwappedCreateFunc(const btDiscreteDynamicsWorld *world); diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index ad20a7e451..b9c2a00b34 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -126,7 +126,6 @@ bool GodotKinClosestConvexResultCallback::needsCollision(btBroadphaseProxy *prox if (gObj == m_self_object) { return false; } else { - // A kinematic body can't be stopped by a rigid body since the mass of kinematic body is infinite if (m_infinite_inertia && !btObj->isStaticOrKinematicObject()) return false; @@ -201,12 +200,10 @@ bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) co } btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { - if (m_count >= m_resultMax) return cp.getDistance(); if (cp.getDistance() <= 0) { - PhysicsDirectSpaceState3D::ShapeResult &result = m_results[m_count]; // Penetrated @@ -295,7 +292,6 @@ bool GodotRestInfoContactResultCallback::needsCollision(btBroadphaseProxy *proxy } btScalar GodotRestInfoContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { - if (cp.getDistance() <= m_min_distance) { m_min_distance = cp.getDistance(); @@ -325,7 +321,6 @@ btScalar GodotRestInfoContactResultCallback::addSingleResult(btManifoldPoint &cp } void GodotDeepPenetrationContactResultCallback::addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorldOnB, btScalar depth) { - if (m_penetration_distance > depth) { // Has penetration? const bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject(); diff --git a/modules/bullet/hinge_joint_bullet.cpp b/modules/bullet/hinge_joint_bullet.cpp index e7f3d75c10..2338277565 100644 --- a/modules/bullet/hinge_joint_bullet.cpp +++ b/modules/bullet/hinge_joint_bullet.cpp @@ -42,7 +42,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameA, const Transform &frameB) : JointBullet() { - Transform scaled_AFrame(frameA.scaled(rbA->get_body_scale())); scaled_AFrame.basis.rotref_posscale_decomposition(scaled_AFrame.basis); @@ -50,7 +49,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c G_TO_B(scaled_AFrame, btFrameA); if (rbB) { - Transform scaled_BFrame(frameB.scaled(rbB->get_body_scale())); scaled_BFrame.basis.rotref_posscale_decomposition(scaled_BFrame.basis); @@ -59,7 +57,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c hingeConstraint = bulletnew(btHingeConstraint(*rbA->get_bt_rigid_body(), *rbB->get_bt_rigid_body(), btFrameA, btFrameB)); } else { - hingeConstraint = bulletnew(btHingeConstraint(*rbA->get_bt_rigid_body(), btFrameA)); } @@ -68,7 +65,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Vector3 &pivotInA, const Vector3 &pivotInB, const Vector3 &axisInA, const Vector3 &axisInB) : JointBullet() { - btVector3 btPivotA; btVector3 btAxisA; G_TO_B(pivotInA * rbA->get_body_scale(), btPivotA); @@ -82,7 +78,6 @@ HingeJointBullet::HingeJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, c hingeConstraint = bulletnew(btHingeConstraint(*rbA->get_bt_rigid_body(), *rbB->get_bt_rigid_body(), btPivotA, btPivotB, btAxisA, btAxisB)); } else { - hingeConstraint = bulletnew(btHingeConstraint(*rbA->get_bt_rigid_body(), btPivotA, btAxisA)); } diff --git a/modules/bullet/joint_bullet.h b/modules/bullet/joint_bullet.h index 9cb8aab276..c70cea817e 100644 --- a/modules/bullet/joint_bullet.h +++ b/modules/bullet/joint_bullet.h @@ -42,7 +42,6 @@ class RigidBodyBullet; class btTypedConstraint; class JointBullet : public ConstraintBullet { - public: JointBullet(); virtual ~JointBullet(); diff --git a/modules/bullet/pin_joint_bullet.cpp b/modules/bullet/pin_joint_bullet.cpp index 68b40d7405..1cfbc65c78 100644 --- a/modules/bullet/pin_joint_bullet.cpp +++ b/modules/bullet/pin_joint_bullet.cpp @@ -42,7 +42,6 @@ PinJointBullet::PinJointBullet(RigidBodyBullet *p_body_a, const Vector3 &p_pos_a, RigidBodyBullet *p_body_b, const Vector3 &p_pos_b) : JointBullet() { if (p_body_b) { - btVector3 btPivotA; btVector3 btPivotB; G_TO_B(p_pos_a * p_body_a->get_body_scale(), btPivotA); diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 7a244b8c32..69a81f6f15 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -257,7 +257,6 @@ void RigidBodyBullet::KinematicUtilities::just_delete_shapes(int new_size) { RigidBodyBullet::RigidBodyBullet() : RigidCollisionObjectBullet(CollisionObjectBullet::TYPE_RIGID_BODY) { - godotMotionState = bulletnew(GodotMotionState(this)); // Initial properties @@ -337,7 +336,6 @@ void RigidBodyBullet::set_space(SpaceBullet *p_space) { void RigidBodyBullet::dispatch_callbacks() { /// The check isFirstTransformChanged is necessary in order to call integrated forces only when the first transform is sent if ((btBody->isKinematicObject() || btBody->isActive() || previousActiveState != btBody->isActive()) && force_integration_callback && can_integrate_forces) { - if (omit_forces_integration) btBody->clearForces(); @@ -371,7 +369,6 @@ void RigidBodyBullet::dispatch_callbacks() { } void RigidBodyBullet::set_force_integration_callback(ObjectID p_id, const StringName &p_method, const Variant &p_udata) { - if (force_integration_callback) { memdelete(force_integration_callback); force_integration_callback = nullptr; @@ -398,7 +395,6 @@ void RigidBodyBullet::on_collision_filters_change() { } void RigidBodyBullet::on_collision_checker_start() { - prev_collision_count = collisionsCount; collisionsCount = 0; @@ -414,7 +410,6 @@ void RigidBodyBullet::on_collision_checker_end() { } bool RigidBodyBullet::add_collision_object(RigidBodyBullet *p_otherObject, const Vector3 &p_hitWorldLocation, const Vector3 &p_hitLocalLocation, const Vector3 &p_hitNormal, const float &p_appliedImpulse, int p_other_shape_index, int p_local_shape_index) { - if (collisionsCount >= maxCollisionsDetection) { return false; } @@ -565,7 +560,6 @@ PhysicsServer3D::BodyMode RigidBodyBullet::get_mode() const { } void RigidBodyBullet::set_state(PhysicsServer3D::BodyState p_state, const Variant &p_variant) { - switch (p_state) { case PhysicsServer3D::BODY_STATE_TRANSFORM: set_transform(p_variant); @@ -714,7 +708,6 @@ bool RigidBodyBullet::is_axis_locked(PhysicsServer3D::BodyAxis p_axis) const { } void RigidBodyBullet::reload_axis_lock() { - btBody->setLinearFactor(btVector3(float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_X)), float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_Y)), float(!is_axis_locked(PhysicsServer3D::BODY_AXIS_LINEAR_Z)))); if (PhysicsServer3D::BODY_MODE_CHARACTER == mode) { /// When character angular is always locked @@ -793,10 +786,8 @@ void RigidBodyBullet::set_transform__bullet(const btTransform &p_global_transfor const btTransform &RigidBodyBullet::get_transform__bullet() const { if (is_static()) { - return RigidCollisionObjectBullet::get_transform__bullet(); } else { - return godotMotionState->getCurrentWorldTransform(); } } @@ -831,7 +822,6 @@ void RigidBodyBullet::on_enter_area(AreaBullet *p_area) { return; } for (int i = 0; i < areaWhereIamCount; ++i) { - if (nullptr == areasWhereIam[i]) { // This area has the highest priority areasWhereIam.write[i] = p_area; @@ -901,7 +891,6 @@ void RigidBodyBullet::reload_space_override_modificator() { bool stopped = false; for (int i = areaWhereIamCount - 1; (0 <= i) && !stopped; --i) { - currentArea = areasWhereIam[i]; if (!currentArea || PhysicsServer3D::AREA_SPACE_OVERRIDE_DISABLED == currentArea->get_spOv_mode()) { @@ -910,7 +899,6 @@ void RigidBodyBullet::reload_space_override_modificator() { /// Here is calculated the gravity if (currentArea->is_spOv_gravityPoint()) { - /// It calculates the direction of new gravity support_gravity = currentArea->get_transform().xform(currentArea->get_spOv_gravityVec()) - get_transform().get_origin(); real_t distanceMag = support_gravity.length(); @@ -1004,7 +992,6 @@ void RigidBodyBullet::notify_transform_changed() { } void RigidBodyBullet::_internal_set_mass(real_t p_mass) { - btVector3 localInertia(0, 0, 0); int clearedCurrentFlags = btBody->getCollisionFlags(); @@ -1013,7 +1000,6 @@ void RigidBodyBullet::_internal_set_mass(real_t p_mass) { // Rigidbody is dynamic if and only if mass is non Zero, otherwise static const bool isDynamic = p_mass != 0.f; if (isDynamic) { - if (PhysicsServer3D::BODY_MODE_RIGID != mode && PhysicsServer3D::BODY_MODE_CHARACTER != mode) return; @@ -1022,10 +1008,8 @@ void RigidBodyBullet::_internal_set_mass(real_t p_mass) { mainShape->calculateLocalInertia(p_mass, localInertia); if (PhysicsServer3D::BODY_MODE_RIGID == mode) { - btBody->setCollisionFlags(clearedCurrentFlags); // Just set the flags without Kin and Static } else { - btBody->setCollisionFlags(clearedCurrentFlags | btCollisionObject::CF_CHARACTER_OBJECT); } @@ -1035,16 +1019,13 @@ void RigidBodyBullet::_internal_set_mass(real_t p_mass) { btBody->forceActivationState(DISABLE_DEACTIVATION); // DISABLE_DEACTIVATION 4 } } else { - if (PhysicsServer3D::BODY_MODE_STATIC != mode && PhysicsServer3D::BODY_MODE_KINEMATIC != mode) return; m_isStatic = true; if (PhysicsServer3D::BODY_MODE_STATIC == mode) { - btBody->setCollisionFlags(clearedCurrentFlags | btCollisionObject::CF_STATIC_OBJECT); } else { - btBody->setCollisionFlags(clearedCurrentFlags | btCollisionObject::CF_KINEMATIC_OBJECT); set_transform__bullet(btBody->getWorldTransform()); // Set current Transform using kinematic method } diff --git a/modules/bullet/rigid_body_bullet.h b/modules/bullet/rigid_body_bullet.h index f94dea8036..6d159504b8 100644 --- a/modules/bullet/rigid_body_bullet.h +++ b/modules/bullet/rigid_body_bullet.h @@ -142,7 +142,6 @@ public: }; class RigidBodyBullet : public RigidCollisionObjectBullet { - public: struct CollisionData { RigidBodyBullet *otherObject; @@ -249,7 +248,6 @@ public: virtual void on_collision_checker_end(); void set_max_collisions_detection(int p_maxCollisionsDetection) { - ERR_FAIL_COND(0 > p_maxCollisionsDetection); maxCollisionsDetection = p_maxCollisionsDetection; diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp index e3b869ad8d..424daf7726 100644 --- a/modules/bullet/shape_bullet.cpp +++ b/modules/bullet/shape_bullet.cpp @@ -89,7 +89,6 @@ void ShapeBullet::remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFrom } bool ShapeBullet::is_owner(ShapeOwnerBullet *p_owner) const { - return owners.has(p_owner); } @@ -394,7 +393,6 @@ void ConcavePolygonShapeBullet::setup(Vector<Vector3> p_faces) { } int src_face_count = faces.size(); if (0 < src_face_count) { - // It counts the faces and assert the array contains the correct number of vertices. ERR_FAIL_COND(src_face_count % 3); @@ -513,7 +511,6 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) { // Compute min and max heights if not specified. if (!d.has("min_height") && !d.has("max_height")) { - const real_t *r = l_heights.ptr(); int heights_size = l_heights.size(); @@ -564,13 +561,11 @@ RayShapeBullet::RayShapeBullet() : ShapeBullet() {} void RayShapeBullet::set_data(const Variant &p_data) { - Dictionary d = p_data; setup(d["length"], d["slips_on_slope"]); } Variant RayShapeBullet::get_data() const { - Dictionary d; d["length"] = length; d["slips_on_slope"] = slips_on_slope; diff --git a/modules/bullet/shape_bullet.h b/modules/bullet/shape_bullet.h index 88b62b6dc9..b24ded574f 100644 --- a/modules/bullet/shape_bullet.h +++ b/modules/bullet/shape_bullet.h @@ -50,7 +50,6 @@ class ShapeOwnerBullet; class btBvhTriangleMeshShape; class ShapeBullet : public RIDBullet { - Map<ShapeOwnerBullet *, int> owners; real_t margin = 0.04; @@ -95,7 +94,6 @@ public: }; class PlaneShapeBullet : public ShapeBullet { - Plane plane; public: @@ -111,7 +109,6 @@ private: }; class SphereShapeBullet : public ShapeBullet { - real_t radius; public: @@ -128,7 +125,6 @@ private: }; class BoxShapeBullet : public ShapeBullet { - btVector3 half_extents; public: @@ -145,7 +141,6 @@ private: }; class CapsuleShapeBullet : public ShapeBullet { - real_t height; real_t radius; @@ -164,7 +159,6 @@ private: }; class CylinderShapeBullet : public ShapeBullet { - real_t height; real_t radius; @@ -183,7 +177,6 @@ private: }; class ConvexPolygonShapeBullet : public ShapeBullet { - public: btAlignedObjectArray<btVector3> vertices; @@ -218,7 +211,6 @@ private: }; class HeightMapShapeBullet : public ShapeBullet { - public: Vector<real_t> heights; int width; @@ -238,7 +230,6 @@ private: }; class RayShapeBullet : public ShapeBullet { - public: real_t length = 1; bool slips_on_slope = false; diff --git a/modules/bullet/slider_joint_bullet.cpp b/modules/bullet/slider_joint_bullet.cpp index de47c91e5d..c248b78acf 100644 --- a/modules/bullet/slider_joint_bullet.cpp +++ b/modules/bullet/slider_joint_bullet.cpp @@ -42,7 +42,6 @@ SliderJointBullet::SliderJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, const Transform &frameInA, const Transform &frameInB) : JointBullet() { - Transform scaled_AFrame(frameInA.scaled(rbA->get_body_scale())); scaled_AFrame.basis.rotref_posscale_decomposition(scaled_AFrame.basis); @@ -50,7 +49,6 @@ SliderJointBullet::SliderJointBullet(RigidBodyBullet *rbA, RigidBodyBullet *rbB, G_TO_B(scaled_AFrame, btFrameA); if (rbB) { - Transform scaled_BFrame(frameInB.scaled(rbB->get_body_scale())); scaled_BFrame.basis.rotref_posscale_decomposition(scaled_BFrame.basis); diff --git a/modules/bullet/soft_body_bullet.cpp b/modules/bullet/soft_body_bullet.cpp index bbaa23e064..3047a3eed1 100644 --- a/modules/bullet/soft_body_bullet.cpp +++ b/modules/bullet/soft_body_bullet.cpp @@ -105,14 +105,12 @@ void SoftBodyBullet::update_rendering_server(SoftBodyRenderingServerHandler *p_r } void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) { - if (p_mesh.is_null()) soft_mesh.unref(); else soft_mesh = p_mesh; if (soft_mesh.is_null()) { - destroy_soft_body(); return; } @@ -123,7 +121,6 @@ void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) { } void SoftBodyBullet::destroy_soft_body() { - if (!bt_soft_body) return; @@ -223,7 +220,6 @@ void SoftBodyBullet::reset_all_node_positions() { const Vector3 *vs_vertices_read = vs_vertices.ptr(); for (int vertex_index = bt_soft_body->m_nodes.size() - 1; 0 <= vertex_index; --vertex_index) { - G_TO_B(vs_vertices_read[indices_table[vertex_index][0]], bt_soft_body->m_nodes[vertex_index].m_x); bt_soft_body->m_nodes[vertex_index].m_q = bt_soft_body->m_nodes[vertex_index].m_x; @@ -331,7 +327,6 @@ void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector const Vector3 *p_vertices_read = p_vertices.ptr(); for (int vs_vertex_index = 0; vs_vertex_index < vs_vertices_size; ++vs_vertex_index) { - Map<Vector3, int>::Element *e = unique_vertices.find(p_vertices_read[vs_vertex_index]); int vertex_id; if (e) { @@ -387,7 +382,6 @@ void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector } void SoftBodyBullet::setup_soft_body() { - if (!bt_soft_body) return; diff --git a/modules/bullet/soft_body_bullet.h b/modules/bullet/soft_body_bullet.h index d28af7d61d..da8a2412ed 100644 --- a/modules/bullet/soft_body_bullet.h +++ b/modules/bullet/soft_body_bullet.h @@ -56,7 +56,6 @@ */ class SoftBodyBullet : public CollisionObjectBullet { - private: btSoftBody *bt_soft_body = nullptr; Vector<Vector<int>> indices_table; diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index aff203d7b4..433f1109c9 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -63,7 +63,6 @@ BulletPhysicsDirectSpaceState::BulletPhysicsDirectSpaceState(SpaceBullet *p_spac space(p_space) {} int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - if (p_result_max <= 0) return 0; @@ -86,7 +85,6 @@ int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, Shape } bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas, bool p_pick_ray) { - btVector3 btVec_from; btVector3 btVec_to; @@ -238,7 +236,6 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & } bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_collide_with_bodies, bool p_collide_with_areas) { - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); @@ -276,7 +273,6 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh } Vector3 BulletPhysicsDirectSpaceState::get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const { - RigidCollisionObjectBullet *rigid_object = space->get_physics_server()->get_rigid_collisin_object(p_object); ERR_FAIL_COND_V(!rigid_object, Vector3()); @@ -320,12 +316,10 @@ Vector3 BulletPhysicsDirectSpaceState::get_closest_point_to_object_volume(RID p_ } if (shapes_found) { - Vector3 out; B_TO_G(out_closest_point, out); return out; } else { - // no shapes found, use distance to origin. return rigid_object->get_transform().get_origin(); } @@ -539,7 +533,6 @@ void onBulletPreTickCallback(btDynamicsWorld *p_dynamicsWorld, btScalar timeStep } void onBulletTickCallback(btDynamicsWorld *p_dynamicsWorld, btScalar timeStep) { - const btCollisionObjectArray &colObjArray = p_dynamicsWorld->getCollisionObjectArray(); // Notify all Collision objects the collision checker is started @@ -561,17 +554,14 @@ BulletPhysicsDirectSpaceState *SpaceBullet::get_direct_state() { } btScalar calculateGodotCombinedRestitution(const btCollisionObject *body0, const btCollisionObject *body1) { - return CLAMP(body0->getRestitution() + body1->getRestitution(), 0, 1); } btScalar calculateGodotCombinedFriction(const btCollisionObject *body0, const btCollisionObject *body1) { - return ABS(MIN(body0->getFriction(), body1->getFriction())); } void SpaceBullet::create_empty_world(bool p_create_soft_world) { - gjk_epa_pen_solver = bulletnew(btGjkEpaPenetrationDepthSolver); gjk_simplex_solver = bulletnew(btVoronoiSimplexSolver); @@ -624,7 +614,6 @@ void SpaceBullet::create_empty_world(bool p_create_soft_world) { } void SpaceBullet::destroy_world() { - /// The world elements (like: Collision Objects, Constraints, Shapes) are managed by godot dynamicsWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(nullptr); @@ -648,7 +637,6 @@ void SpaceBullet::destroy_world() { } void SpaceBullet::check_ghost_overlaps() { - /// Algorithm support variables btCollisionShape *other_body_shape; btConvexShape *area_shape; @@ -681,7 +669,6 @@ void SpaceBullet::check_ghost_overlaps() { // For each overlapping for (i = ghostOverlaps.size() - 1; 0 <= i; --i) { - bool hasOverlap = false; btCollisionObject *overlapped_bt_co = ghostOverlaps[i]; RigidCollisionObjectBullet *otherObject = static_cast<RigidCollisionObjectBullet *>(overlapped_bt_co->getUserPointer()); @@ -714,7 +701,6 @@ void SpaceBullet::check_ghost_overlaps() { // For each other object shape for (z = otherObject->get_shape_count() - 1; 0 <= z; --z) { - other_body_shape = static_cast<btCollisionShape *>(otherObject->get_bt_shape(z)); btTransform other_shape_transform(otherObject->get_bt_shape_transform(z)); @@ -725,7 +711,6 @@ void SpaceBullet::check_ghost_overlaps() { other_shape_transform; if (other_body_shape->isConvex()) { - btPointCollector result; btGjkPairDetector gjk_pair_detector( area_shape, @@ -740,7 +725,6 @@ void SpaceBullet::check_ghost_overlaps() { } } else { - btCollisionObjectWrapper obA(nullptr, area_shape, area->get_bt_ghost(), gjk_input.m_transformA, -1, y); btCollisionObjectWrapper obB(nullptr, other_body_shape, otherObject->get_bt_collision_object(), gjk_input.m_transformB, -1, z); @@ -823,7 +807,6 @@ void SpaceBullet::check_body_collision() { pt.getDistance() <= 0.0 || bodyA->was_colliding(bodyB) || bodyB->was_colliding(bodyA)) { - Vector3 collisionWorldPosition; Vector3 collisionLocalPosition; Vector3 normalOnB; @@ -883,7 +866,6 @@ static Ref<StandardMaterial3D> blue_mat; #endif bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult *r_result, bool p_exclude_raycast_shapes) { - #if debug_test_motion /// Yes I know this is not good, but I've used it as fast debugging hack. /// I'm leaving it here just for speedup the other eventual debugs @@ -1000,7 +982,6 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f B_TO_G(motion + initial_recover_motion + __rec, r_result->motion); if (has_penetration) { - const btRigidBody *btRigid = static_cast<const btRigidBody *>(r_recover_result.other_collision_object); CollisionObjectBullet *collisionObject = static_cast<CollisionObjectBullet *>(btRigid->getUserPointer()); @@ -1034,7 +1015,6 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f } int SpaceBullet::test_ray_separation(RigidBodyBullet *p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, PhysicsServer3D::SeparationResult *r_results, int p_result_max, float p_margin) { - btTransform body_transform; G_TO_B(p_transform, body_transform); UNSCALE_BT_BASIS(body_transform); @@ -1099,14 +1079,12 @@ public: self_collision_object(p_self_collision_object), collision_layer(p_collision_layer), collision_mask(p_collision_mask) { - bounds = btDbvtVolume::FromMM(p_aabb_min, p_aabb_max); } virtual ~RecoverPenetrationBroadPhaseCallback() {} 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)) { @@ -1150,13 +1128,11 @@ public: }; bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result) { - // Calculate the cumulative AABB of all shapes of the kinematic body btVector3 aabb_min, aabb_max; bool shapes_found = false; for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { - const RigidBodyBullet::KinematicShape &kin_shape(p_body->get_kinematic_utilities()->shapes[kinIndex]); if (!kin_shape.is_active()) { continue; @@ -1201,7 +1177,6 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran // Perform narrowphase per shape for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { - const RigidBodyBullet::KinematicShape &kin_shape(p_body->get_kinematic_utilities()->shapes[kinIndex]); if (!kin_shape.is_active()) { continue; @@ -1230,23 +1205,19 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran if (cs->getChildShape(shape_idx)->isConvex()) { if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(cs->getChildShape(shape_idx)), otherObject, kinIndex, shape_idx, shape_transform, otherObject->getWorldTransform() * cs->getChildTransform(shape_idx), p_recover_movement_scale, r_delta_recover_movement, r_recover_result)) { - penetration = true; } } else { if (RFP_convex_world_test(kin_shape.shape, cs->getChildShape(shape_idx), p_body->get_bt_collision_object(), otherObject, kinIndex, shape_idx, shape_transform, otherObject->getWorldTransform() * cs->getChildTransform(shape_idx), p_recover_movement_scale, r_delta_recover_movement, r_recover_result)) { - penetration = true; } } } else if (otherObject->getCollisionShape()->isConvex()) { /// Execute GJK test against object shape if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(otherObject->getCollisionShape()), otherObject, kinIndex, 0, shape_transform, otherObject->getWorldTransform(), p_recover_movement_scale, r_delta_recover_movement, r_recover_result)) { - penetration = true; } } else { if (RFP_convex_world_test(kin_shape.shape, otherObject->getCollisionShape(), p_body->get_bt_collision_object(), otherObject, kinIndex, 0, shape_transform, otherObject->getWorldTransform(), p_recover_movement_scale, r_delta_recover_movement, r_recover_result)) { - penetration = true; } } @@ -1257,7 +1228,6 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran } bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result) { - // Initialize GJK input btGjkPairDetector::ClosestPointInput gjk_input; gjk_input.m_transformA = p_transformA; @@ -1288,7 +1258,6 @@ bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const bt } bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btScalar p_recover_movement_scale, btVector3 &r_delta_recover_movement, RecoverResult *r_recover_result) { - /// Contact test btTransform tA(p_transformA); @@ -1325,7 +1294,6 @@ bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btC } int SpaceBullet::add_separation_result(PhysicsServer3D::SeparationResult *r_result, const SpaceBullet::RecoverResult &p_recover_result, int p_shape_id, const btCollisionObject *p_other_object) const { - // optimize results (ignore non-colliding) if (p_recover_result.penetration_distance < 0.0) { const btRigidBody *btRigid = static_cast<const btRigidBody *>(p_other_object); @@ -1347,13 +1315,11 @@ int SpaceBullet::add_separation_result(PhysicsServer3D::SeparationResult *r_resu } int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btTransform &p_body_position, btScalar p_recover_movement_scale, bool p_infinite_inertia, int p_result_max, btVector3 &r_delta_recover_movement, PhysicsServer3D::SeparationResult *r_results) { - // Calculate the cumulative AABB of all shapes of the kinematic body btVector3 aabb_min, aabb_max; bool shapes_found = false; for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { - const RigidBodyBullet::KinematicShape &kin_shape(p_body->get_kinematic_utilities()->shapes[kinIndex]); if (!kin_shape.is_active()) { continue; @@ -1397,7 +1363,6 @@ int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btT // Perform narrowphase per shape for (int kinIndex = p_body->get_kinematic_utilities()->shapes.size() - 1; 0 <= kinIndex; --kinIndex) { - if (ray_count >= p_result_max) { break; } @@ -1429,14 +1394,11 @@ int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btT RecoverResult recover_result; if (RFP_convex_world_test(kin_shape.shape, cs->getChildShape(shape_idx), p_body->get_bt_collision_object(), otherObject, kinIndex, shape_idx, shape_transform, otherObject->getWorldTransform() * cs->getChildTransform(shape_idx), p_recover_movement_scale, r_delta_recover_movement, &recover_result)) { - ray_count = add_separation_result(&r_results[ray_count], recover_result, kinIndex, otherObject); } } else { - RecoverResult recover_result; if (RFP_convex_world_test(kin_shape.shape, otherObject->getCollisionShape(), p_body->get_bt_collision_object(), otherObject, kinIndex, 0, shape_transform, otherObject->getWorldTransform(), p_recover_movement_scale, r_delta_recover_movement, &recover_result)) { - ray_count = add_separation_result(&r_results[ray_count], recover_result, kinIndex, otherObject); } } diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h index 6fe4571bba..2dad965de8 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -87,7 +87,6 @@ public: }; class SpaceBullet : public RIDBullet { - friend class AreaBullet; friend void onBulletTickCallback(btDynamicsWorld *world, btScalar timeStep); friend class BulletPhysicsDirectSpaceState; diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index a6951a9320..ccd1b89fb5 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -37,12 +37,10 @@ // Static helper functions. inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2, real_t p_distance) { - return (p_point1 - p_point2).length_squared() < p_distance * p_distance; } 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) return p_uvs[0]; @@ -54,7 +52,6 @@ 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) return p_uvs[0]; if (p_interpolation_point.distance_squared_to(p_vertices[1]) < CMP_EPSILON2) @@ -83,7 +80,6 @@ inline static Vector2 interpolate_triangle_uv(const Vector2 p_vertices[3], const } static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 p_vertices[3], float p_tolerance, Vector3 &r_intersection_point) { - Vector3 edge1 = p_vertices[1] - p_vertices[0]; Vector3 edge2 = p_vertices[2] - p_vertices[0]; Vector3 h = p_dir.cross(edge2); @@ -115,7 +111,6 @@ static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3 } inline bool is_point_in_triangle(const Vector3 &p_point, const Vector3 p_vertices[3], int p_shifted = 0) { - real_t det = p_vertices[0].dot(p_vertices[1].cross(p_vertices[2])); // If determinant is, zero try shift the triangle and the point. @@ -149,7 +144,6 @@ inline bool is_point_in_triangle(const Vector3 &p_point, const Vector3 p_vertice } inline static bool are_segements_parallel(const Vector2 p_segment1_points[2], const Vector2 p_segment2_points[2], float p_vertex_snap2) { - Vector2 segment1 = p_segment1_points[1] - p_segment1_points[0]; Vector2 segment2 = p_segment2_points[1] - p_segment2_points[0]; real_t segment1_length2 = segment1.dot(segment1); @@ -172,7 +166,6 @@ inline static bool are_segements_parallel(const Vector2 p_segment1_points[2], co // CSGBrush void CSGBrush::_regen_face_aabbs() { - for (int i = 0; i < faces.size(); i++) { faces.write[i].aabb = AABB(); faces.write[i].aabb.position = faces[i].vertices[0]; @@ -182,7 +175,6 @@ void CSGBrush::_regen_face_aabbs() { } void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector<Vector2> &p_uvs, const Vector<bool> &p_smooth, const Vector<Ref<Material>> &p_materials, const Vector<bool> &p_invert_faces) { - faces.clear(); int vc = p_vertices.size(); @@ -204,7 +196,6 @@ void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector< faces.resize(p_vertices.size() / 3); for (int i = 0; i < faces.size(); i++) { - Face &f = faces.write[i]; f.vertices[0] = rv[i * 3 + 0]; f.vertices[1] = rv[i * 3 + 1]; @@ -227,10 +218,8 @@ void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector< f.invert = false; if (mc == vc / 3) { - Ref<Material> mat = rm[i]; if (mat.is_valid()) { - const Map<Ref<Material>, int>::Element *E = material_map.find(mat); if (E) { @@ -255,7 +244,6 @@ void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector< } void CSGBrush::copy_from(const CSGBrush &p_brush, const Transform &p_xform) { - faces = p_brush.faces; materials = p_brush.materials; @@ -271,7 +259,6 @@ void CSGBrush::copy_from(const CSGBrush &p_brush, const Transform &p_xform) { // CSGBrushOperation void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_brush_a, const CSGBrush &p_brush_b, CSGBrush &r_merged_brush, float p_vertex_snap) { - // Check for face collisions and add necessary faces. Build2DFaceCollection build2DFaceCollection; for (int i = 0; i < p_brush_a.faces.size(); i++) { @@ -287,7 +274,6 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b mesh_merge.vertex_snap = p_vertex_snap; for (int i = 0; i < p_brush_a.faces.size(); i++) { - Ref<Material> material; if (p_brush_a.faces[i].material != -1) { material = p_brush_a.materials[p_brush_a.faces[i].material]; @@ -307,7 +293,6 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b } for (int i = 0; i < p_brush_b.faces.size(); i++) { - Ref<Material> material; if (p_brush_b.faces[i].material != -1) { material = p_brush_b.materials[p_brush_b.faces[i].material]; @@ -333,9 +318,7 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b r_merged_brush.faces.clear(); switch (p_operation) { - case OPERATION_UNION: { - int outside_count = 0; for (int i = 0; i < mesh_merge.faces.size(); i++) { @@ -349,7 +332,6 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b outside_count = 0; for (int i = 0; i < mesh_merge.faces.size(); i++) { - if (mesh_merge.faces[i].inside) continue; @@ -369,7 +351,6 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b } break; case OPERATION_INTERSECTION: { - int inside_count = 0; for (int i = 0; i < mesh_merge.faces.size(); i++) { @@ -383,7 +364,6 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b inside_count = 0; for (int i = 0; i < mesh_merge.faces.size(); i++) { - if (!mesh_merge.faces[i].inside) continue; @@ -403,7 +383,6 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b } break; case OPERATION_SUBSTRACTION: { - int face_count = 0; for (int i = 0; i < mesh_merge.faces.size(); i++) { @@ -419,7 +398,6 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b face_count = 0; for (int i = 0; i < mesh_merge.faces.size(); i++) { - if (mesh_merge.faces[i].from_b && !mesh_merge.faces[i].inside) continue; if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside) @@ -460,7 +438,6 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b #define BVH_LIMIT 8 int CSGBrushOperation::MeshMerge::_create_bvh(FaceBVH *facebvhptr, FaceBVH **facebvhptrptr, int p_from, int p_size, int p_depth, int &r_max_depth, int &r_max_alloc) { - if (p_depth > r_max_depth) { r_max_depth = p_depth; } @@ -485,7 +462,6 @@ int CSGBrushOperation::MeshMerge::_create_bvh(FaceBVH *facebvhptr, FaceBVH **fac int li = aabb.get_longest_axis_index(); switch (li) { - case Vector3::AXIS_X: { SortArray<FaceBVH *, FaceBVHCmpX> sort_x; sort_x.nth_element(0, p_size, p_size / 2, &facebvhptrptr[p_from]); @@ -521,7 +497,6 @@ int CSGBrushOperation::MeshMerge::_create_bvh(FaceBVH *facebvhptr, FaceBVH **fac } void CSGBrushOperation::MeshMerge::_add_distance(List<real_t> &r_intersectionsA, List<real_t> &r_intersectionsB, bool p_from_B, real_t p_distance) const { - List<real_t> &intersections = p_from_B ? r_intersectionsB : r_intersectionsA; // Check if distance exists. @@ -533,7 +508,6 @@ void CSGBrushOperation::MeshMerge::_add_distance(List<real_t> &r_intersectionsA, } bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_depth, int p_bvh_first, int p_face_idx) const { - Face face = faces[p_face_idx]; Vector3 face_points[3] = { points[face.points[0]], @@ -563,22 +537,16 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de stack[0] = pos; while (true) { - uint32_t node = stack[level] & NODE_IDX_MASK; const FaceBVH *current_facebvhptr = &(facebvhptr[node]); bool done = false; switch (stack[level] >> VISITED_BIT_SHIFT) { - case TEST_AABB_BIT: { - if (current_facebvhptr->face >= 0) { - while (current_facebvhptr) { - if (p_face_idx != current_facebvhptr->face && current_facebvhptr->aabb.intersects_ray(face_center, face_normal)) { - const Face ¤t_face = faces[current_facebvhptr->face]; Vector3 current_points[3] = { points[current_face.points[0]], @@ -610,7 +578,6 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; } else { - bool valid = current_facebvhptr->aabb.intersects_ray(face_center, face_normal); if (!valid) { @@ -623,7 +590,6 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de } case VISIT_LEFT_BIT: { - stack[level] = (VISIT_RIGHT_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = current_facebvhptr->left | TEST_AABB_BIT; level++; @@ -631,7 +597,6 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de } case VISIT_RIGHT_BIT: { - stack[level] = (VISIT_DONE_BIT << VISITED_BIT_SHIFT) | node; stack[level + 1] = current_facebvhptr->right | TEST_AABB_BIT; level++; @@ -639,7 +604,6 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de } case VISIT_DONE_BIT: { - if (level == 0) { done = true; break; @@ -658,7 +622,6 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de } void CSGBrushOperation::MeshMerge::mark_inside_faces() { - // Mark faces that are inside. This helps later do the boolean ops when merging. // This approach is very brute force with a bunch of optimizations, // such as BVH and pre AABB intersection test. @@ -719,7 +682,6 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() { _create_bvh(facebvh, bvhptr, 0, faces.size(), 1, max_depth, max_alloc); for (int i = 0; i < faces.size(); i++) { - // Check if face AABB intersects the intersection AABB. if (!intersection_aabb.intersects_inclusive(facebvh[i].aabb)) continue; @@ -730,10 +692,8 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() { } void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vector2 p_uvs[], bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b) { - int indices[3]; for (int i = 0; i < 3; i++) { - VertexKey vk; vk.x = int((double(p_points[i].x) + double(vertex_snap) * 0.31234) / double(vertex_snap)); vk.y = int((double(p_points[i].y) + double(vertex_snap) * 0.31234) / double(vertex_snap)); @@ -781,7 +741,6 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vect // CSGBrushOperation::Build2DFaces int CSGBrushOperation::Build2DFaces::_get_point_idx(const Vector2 &p_point) { - for (int vertex_idx = 0; vertex_idx < vertices.size(); ++vertex_idx) { if ((p_point - vertices[vertex_idx].point).length_squared() < vertex_snap2) return vertex_idx; @@ -790,7 +749,6 @@ int CSGBrushOperation::Build2DFaces::_get_point_idx(const Vector2 &p_point) { } int CSGBrushOperation::Build2DFaces::_add_vertex(const Vertex2D &p_vertex) { - // Check if vertex exists. int vertex_id = _get_point_idx(p_vertex.point); if (vertex_id != -1) @@ -801,7 +759,6 @@ int CSGBrushOperation::Build2DFaces::_add_vertex(const Vertex2D &p_vertex) { } void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vertex_indices, int p_new_vertex_index) { - if (p_new_vertex_index >= 0 && r_vertex_indices.find(p_new_vertex_index) == -1) { ERR_FAIL_COND_MSG(p_new_vertex_index >= vertices.size(), "Invalid vertex index."); @@ -814,7 +771,6 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert // The second vertex. if (r_vertex_indices.size() == 1) { - Vector2 first_point = vertices[r_vertex_indices[0]].point; Vector2 new_point = vertices[p_new_vertex_index].point; @@ -857,14 +813,12 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert } void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_indices) { - int segments = p_segment_indices.size() - 1; if (segments < 2) return; // Faces around an inner vertex are merged by moving the inner vertex to the first vertex. for (int sorted_idx = 1; sorted_idx < segments; ++sorted_idx) { - int closest_idx = 0; int inner_idx = p_segment_indices[sorted_idx]; @@ -893,7 +847,6 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ // Create the new faces. for (int merge_idx = 0; merge_idx < merge_faces.size(); ++merge_idx) { - int outer_edge_idx[2]; outer_edge_idx[0] = merge_faces[merge_idx].vertex_idx[(merge_faces_inner_vertex_idx[merge_idx] + 1) % 3]; outer_edge_idx[1] = merge_faces[merge_idx].vertex_idx[(merge_faces_inner_vertex_idx[merge_idx] + 2) % 3]; @@ -937,7 +890,6 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ // Split faces using degenerate points. for (int face_idx = 0; face_idx < faces.size(); ++face_idx) { - Face2D face = faces[face_idx]; Vertex2D face_vertices[3] = { vertices[face.vertex_idx[0]], @@ -951,7 +903,6 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ }; for (int point_idx = 0; point_idx < degenerate_points.size(); ++point_idx) { - int degenerate_idx = degenerate_points[point_idx]; Vector2 point_2D = vertices[degenerate_idx].point; @@ -968,7 +919,6 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ // Check if point is on an each edge. for (int face_edge_idx = 0; face_edge_idx < 3; ++face_edge_idx) { - Vector2 edge_points[2] = { face_points[face_edge_idx], face_points[(face_edge_idx + 1) % 3] @@ -976,7 +926,6 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ Vector2 closest_point = Geometry::get_closest_point_to_segment_2d(point_2D, edge_points); if ((closest_point - point_2D).length_squared() < vertex_snap2) { - int opposite_vertex_idx = face.vertex_idx[(face_edge_idx + 2) % 3]; // If new vertex snaps to degenerate vertex, just delete this face. @@ -1014,10 +963,8 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ } void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_segment_points[2], Vector<int> &r_segment_indices) { - // For each face. for (int face_idx = 0; face_idx < faces.size(); ++face_idx) { - Face2D face = faces[face_idx]; Vertex2D face_vertices[3] = { vertices[face.vertex_idx[0]], @@ -1027,7 +974,6 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s // Check each edge. for (int face_edge_idx = 0; face_edge_idx < 3; ++face_edge_idx) { - Vector2 edge_points[2] = { face_vertices[face_edge_idx].point, face_vertices[(face_edge_idx + 1) % 3].point @@ -1050,7 +996,6 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s // Else check if the segment intersects the edge. if (on_edge || Geometry::segment_intersects_segment_2d(p_segment_points[0], p_segment_points[1], edge_points[0], edge_points[1], &intersection_point)) { - // Check if intersection point is an edge point. if ((intersection_point - edge_points[0]).length_squared() < vertex_snap2 || (intersection_point - edge_points[1]).length_squared() < vertex_snap2) @@ -1113,11 +1058,9 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s } int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { - int new_vertex_idx = -1; for (int face_idx = 0; face_idx < faces.size(); ++face_idx) { - Face2D face = faces[face_idx]; Vertex2D face_vertices[3] = { vertices[face.vertex_idx[0]], @@ -1144,7 +1087,6 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { // Check if point is on an each edge. bool on_edge = false; for (int face_edge_idx = 0; face_edge_idx < 3; ++face_edge_idx) { - Vector2 edge_points[2] = { points[face_edge_idx], points[(face_edge_idx + 1) % 3] @@ -1206,7 +1148,6 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { // If not on an edge, check if the point is inside the face. if (!on_edge && Geometry::is_point_in_triangle(p_point, face_vertices[0].point, face_vertices[1].point, face_vertices[2].point)) { - // Add the point as a new vertex. Vertex2D new_vertex; new_vertex.point = p_point; @@ -1216,7 +1157,6 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { // Create three new faces around this point and remove this face. // The new vertex is the last vertex. for (int i = 0; i < 3; ++i) { - // Don't create degenerate triangles. Vector2 edge[2] = { points[i], points[(i + 1) % 3] }; Vector2 new_edge1[2] = { vertices[new_vertex_idx].point, points[i] }; @@ -1243,7 +1183,6 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { } void CSGBrushOperation::Build2DFaces::insert(const CSGBrush &p_brush, int p_face_idx) { - // Find edge points that cross the plane and face points that are in the plane. // Map those points to 2D. // Create new faces from those points. @@ -1252,7 +1191,6 @@ void CSGBrushOperation::Build2DFaces::insert(const CSGBrush &p_brush, int p_face int points_count = 0; for (int i = 0; i < 3; i++) { - Vector3 point_3D = p_brush.faces[p_face_idx].vertices[i]; if (plane.has_point(point_3D)) { @@ -1262,7 +1200,6 @@ void CSGBrushOperation::Build2DFaces::insert(const CSGBrush &p_brush, int p_face points_2D[points_count++] = Vector2(point_2D.x, point_2D.y); } else { - Vector3 next_point_3D = p_brush.faces[p_face_idx].vertices[(i + 1) % 3]; if (plane.has_point(next_point_3D)) @@ -1315,7 +1252,6 @@ void CSGBrushOperation::Build2DFaces::insert(const CSGBrush &p_brush, int p_face } void CSGBrushOperation::Build2DFaces::addFacesToMesh(MeshMerge &r_mesh_merge, bool p_smooth, bool p_invert, const Ref<Material> &p_material, bool p_from_b) { - for (int face_idx = 0; face_idx < faces.size(); ++face_idx) { Face2D face = faces[face_idx]; Vertex2D fv[3] = { @@ -1339,7 +1275,6 @@ void CSGBrushOperation::Build2DFaces::addFacesToMesh(MeshMerge &r_mesh_merge, bo CSGBrushOperation::Build2DFaces::Build2DFaces(const CSGBrush &p_brush, int p_face_idx, float p_vertex_snap2) : vertex_snap2(p_vertex_snap2 * p_vertex_snap2) { - // Convert 3D vertex points to 2D. Vector3 points_3D[3] = { p_brush.faces[p_face_idx].vertices[0], @@ -1368,7 +1303,6 @@ CSGBrushOperation::Build2DFaces::Build2DFaces(const CSGBrush &p_brush, int p_fac } void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face_idx_a, const CSGBrush &p_brush_b, const int p_face_idx_b, Build2DFaceCollection &p_collection, float p_vertex_snap) { - Vector3 vertices_a[3] = { p_brush_a.faces[p_face_idx_a].vertices[0], p_brush_a.faces[p_face_idx_a].vertices[1], @@ -1437,14 +1371,11 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face // Check for intersection using the SAT theorem. { - // Edge pair cross product combinations. for (int i = 0; i < 3; i++) { - Vector3 axis_a = (vertices_a[i] - vertices_a[(i + 1) % 3]).normalized(); for (int j = 0; j < 3; j++) { - Vector3 axis_b = (vertices_b[j] - vertices_b[(j + 1) % 3]).normalized(); Vector3 sep_axis = axis_a.cross(axis_b); diff --git a/modules/csg/csg.h b/modules/csg/csg.h index d389cbc283..34ee239c17 100644 --- a/modules/csg/csg.h +++ b/modules/csg/csg.h @@ -44,7 +44,6 @@ #include "scene/resources/material.h" struct CSGBrush { - struct Face { Vector3 vertices[3]; Vector2 uvs[3]; @@ -65,7 +64,6 @@ struct CSGBrush { }; struct CSGBrushOperation { - enum Operation { OPERATION_UNION, OPERATION_INTERSECTION, @@ -75,7 +73,6 @@ struct CSGBrushOperation { void merge_brushes(Operation p_operation, const CSGBrush &p_brush_a, const CSGBrush &p_brush_b, CSGBrush &r_merged_brush, float p_vertex_snap); struct MeshMerge { - struct Face { bool from_b; bool inside; @@ -156,7 +153,6 @@ struct CSGBrushOperation { }; struct Build2DFaces { - struct Vertex2D { Vector2 point; Vector2 uv; diff --git a/modules/csg/csg_gizmos.cpp b/modules/csg/csg_gizmos.cpp index a859ef80a6..ad04d9941b 100644 --- a/modules/csg/csg_gizmos.cpp +++ b/modules/csg/csg_gizmos.cpp @@ -33,7 +33,6 @@ /////////// CSGShape3DGizmoPlugin::CSGShape3DGizmoPlugin() { - Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/csg", Color(0.0, 0.4, 1, 0.15)); create_material("shape_union_material", gizmo_color); create_material("shape_union_solid_material", gizmo_color); @@ -50,44 +49,36 @@ CSGShape3DGizmoPlugin::CSGShape3DGizmoPlugin() { } String CSGShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const { - CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node()); if (Object::cast_to<CSGSphere3D>(cs)) { - return "Radius"; } if (Object::cast_to<CSGBox3D>(cs)) { - static const char *hname[3] = { "Width", "Height", "Depth" }; return hname[p_idx]; } if (Object::cast_to<CSGCylinder3D>(cs)) { - return p_idx == 0 ? "Radius" : "Height"; } if (Object::cast_to<CSGTorus3D>(cs)) { - return p_idx == 0 ? "InnerRadius" : "OuterRadius"; } return ""; } Variant CSGShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const { - CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node()); if (Object::cast_to<CSGSphere3D>(cs)) { - CSGSphere3D *s = Object::cast_to<CSGSphere3D>(cs); return s->get_radius(); } if (Object::cast_to<CSGBox3D>(cs)) { - CSGBox3D *s = Object::cast_to<CSGBox3D>(cs); switch (p_idx) { case 0: @@ -100,13 +91,11 @@ Variant CSGShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int } if (Object::cast_to<CSGCylinder3D>(cs)) { - CSGCylinder3D *s = Object::cast_to<CSGCylinder3D>(cs); return p_idx == 0 ? s->get_radius() : s->get_height(); } if (Object::cast_to<CSGTorus3D>(cs)) { - CSGTorus3D *s = Object::cast_to<CSGTorus3D>(cs); return p_idx == 0 ? s->get_inner_radius() : s->get_outer_radius(); } @@ -114,7 +103,6 @@ Variant CSGShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int return Variant(); } void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) { - CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node()); Transform gt = cs->get_global_transform(); @@ -127,7 +115,6 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) }; if (Object::cast_to<CSGSphere3D>(cs)) { - CSGSphere3D *s = Object::cast_to<CSGSphere3D>(cs); Vector3 ra, rb; @@ -144,7 +131,6 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca } if (Object::cast_to<CSGBox3D>(cs)) { - CSGBox3D *s = Object::cast_to<CSGBox3D>(cs); Vector3 axis; @@ -173,7 +159,6 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca } if (Object::cast_to<CSGCylinder3D>(cs)) { - CSGCylinder3D *s = Object::cast_to<CSGCylinder3D>(cs); Vector3 axis; @@ -195,7 +180,6 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca } if (Object::cast_to<CSGTorus3D>(cs)) { - CSGTorus3D *s = Object::cast_to<CSGTorus3D>(cs); Vector3 axis; @@ -217,7 +201,6 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca } } void CSGShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) { - CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node()); if (Object::cast_to<CSGSphere3D>(cs)) { @@ -337,7 +320,6 @@ bool CSGShape3DGizmoPlugin::is_selectable_when_hidden() const { } void CSGShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { - CSGShape3D *cs = Object::cast_to<CSGShape3D>(p_gizmo->get_spatial_node()); p_gizmo->clear(); diff --git a/modules/csg/csg_gizmos.h b/modules/csg/csg_gizmos.h index 7763989b2a..48a414d9c7 100644 --- a/modules/csg/csg_gizmos.h +++ b/modules/csg/csg_gizmos.h @@ -36,7 +36,6 @@ #include "editor/node_3d_editor_gizmos.h" class CSGShape3DGizmoPlugin : public EditorNode3DGizmoPlugin { - GDCLASS(CSGShape3DGizmoPlugin, EditorNode3DGizmoPlugin); public: diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index a5b664eeab..8a0e1097c2 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -32,7 +32,6 @@ #include "scene/3d/path_3d.h" void CSGShape3D::set_use_collision(bool p_enable) { - if (use_collision == p_enable) return; @@ -71,12 +70,10 @@ void CSGShape3D::set_collision_layer(uint32_t p_layer) { } uint32_t CSGShape3D::get_collision_layer() const { - return collision_layer; } void CSGShape3D::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; if (root_collision_instance.is_valid()) { PhysicsServer3D::get_singleton()->body_set_collision_mask(root_collision_instance, p_mask); @@ -84,12 +81,10 @@ void CSGShape3D::set_collision_mask(uint32_t p_mask) { } uint32_t CSGShape3D::get_collision_mask() const { - return collision_mask; } void CSGShape3D::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -99,12 +94,10 @@ void CSGShape3D::set_collision_mask_bit(int p_bit, bool p_value) { } bool CSGShape3D::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } void CSGShape3D::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_layer(); if (p_value) mask |= 1 << p_bit; @@ -114,12 +107,10 @@ void CSGShape3D::set_collision_layer_bit(int p_bit, bool p_value) { } bool CSGShape3D::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); } bool CSGShape3D::is_root_shape() const { - return !parent; } @@ -132,7 +123,6 @@ float CSGShape3D::get_snap() const { } void CSGShape3D::_make_dirty() { - if (!is_inside_tree()) return; @@ -151,7 +141,6 @@ void CSGShape3D::_make_dirty() { } CSGBrush *CSGShape3D::_get_brush() { - if (dirty) { if (brush) { memdelete(brush); @@ -161,7 +150,6 @@ CSGBrush *CSGShape3D::_get_brush() { CSGBrush *n = _build_brush(); for (int i = 0; i < get_child_count(); i++) { - CSGShape3D *child = Object::cast_to<CSGShape3D>(get_child(i)); if (!child) continue; @@ -177,7 +165,6 @@ CSGBrush *CSGShape3D::_get_brush() { n->copy_from(*n2, child->get_transform()); } else { - CSGBrush *nn = memnew(CSGBrush); CSGBrush *nn2 = memnew(CSGBrush); nn2->copy_from(*n2, child->get_transform()); @@ -263,7 +250,6 @@ void CSGShape3D::mikktGetTexCoord(const SMikkTSpaceContext *pContext, float fvTe void CSGShape3D::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fvBiTangent[], const float fMagS, const float fMagT, const tbool bIsOrientationPreserving, const int iFace, const int iVert) { - ShapeUpdateSurface &surface = *((ShapeUpdateSurface *)pContext->m_pUserData); int i = iFace * 3 + iVert; @@ -280,7 +266,6 @@ void CSGShape3D::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const } void CSGShape3D::_update_shape() { - if (parent) return; @@ -325,7 +310,6 @@ void CSGShape3D::_update_shape() { //create arrays for (int i = 0; i < surfaces.size(); i++) { - surfaces.write[i].vertices.resize(face_count[i] * 3); surfaces.write[i].normals.resize(face_count[i] * 3); surfaces.write[i].uvs.resize(face_count[i] * 3); @@ -348,13 +332,11 @@ void CSGShape3D::_update_shape() { // Update collision faces. if (root_collision_shape.is_valid()) { - Vector<Vector3> physics_faces; physics_faces.resize(n->faces.size() * 3); Vector3 *physicsw = physics_faces.ptrw(); for (int i = 0; i < n->faces.size(); i++) { - int order[3] = { 0, 1, 2 }; if (n->faces[i].invert) { @@ -372,7 +354,6 @@ void CSGShape3D::_update_shape() { //fill arrays { for (int i = 0; i < n->faces.size(); i++) { - int order[3] = { 0, 1, 2 }; if (n->faces[i].invert) { @@ -388,7 +369,6 @@ void CSGShape3D::_update_shape() { Plane p(n->faces[i].vertices[0], n->faces[i].vertices[1], n->faces[i].vertices[2]); for (int j = 0; j < 3; j++) { - Vector3 v = n->faces[i].vertices[j]; Vector3 normal = p.normal; @@ -398,7 +378,6 @@ void CSGShape3D::_update_shape() { } if (n->faces[i].invert) { - normal = -normal; } @@ -491,14 +470,11 @@ Vector<Vector3> CSGShape3D::get_brush_faces() { } Vector<Face3> CSGShape3D::get_faces(uint32_t p_usage_flags) const { - return Vector<Face3>(); } void CSGShape3D::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - Node *parentn = get_parent(); if (parentn) { parent = Object::cast_to<CSGShape3D>(parentn); @@ -523,21 +499,18 @@ void CSGShape3D::_notification(int p_what) { } if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { - if (parent) { parent->_make_dirty(); } } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (parent) { parent->_make_dirty(); } } if (p_what == NOTIFICATION_EXIT_TREE) { - if (parent) parent->_make_dirty(); parent = nullptr; @@ -552,7 +525,6 @@ void CSGShape3D::_notification(int p_what) { } void CSGShape3D::set_operation(Operation p_operation) { - operation = p_operation; _make_dirty(); update_gizmo(); @@ -582,7 +554,6 @@ void CSGShape3D::_validate_property(PropertyInfo &property) const { } Array CSGShape3D::get_meshes() const { - if (root_mesh.is_valid()) { Array arr; arr.resize(2); @@ -594,7 +565,6 @@ Array CSGShape3D::get_meshes() const { return Array(); } void CSGShape3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update_shape"), &CSGShape3D::_update_shape); ClassDB::bind_method(D_METHOD("is_root_shape"), &CSGShape3D::is_root_shape); @@ -660,7 +630,6 @@ CSGShape3D::~CSGShape3D() { ////////////////////////////////// CSGBrush *CSGCombiner3D::_build_brush() { - return nullptr; //does not build anything } @@ -670,7 +639,6 @@ CSGCombiner3D::CSGCombiner3D() { ///////////////////// CSGBrush *CSGPrimitive3D::_create_brush_from_arrays(const Vector<Vector3> &p_vertices, const Vector<Vector2> &p_uv, const Vector<bool> &p_smooth, const Vector<Ref<Material>> &p_materials) { - CSGBrush *brush = memnew(CSGBrush); Vector<bool> invert; @@ -688,7 +656,6 @@ CSGBrush *CSGPrimitive3D::_create_brush_from_arrays(const Vector<Vector3> &p_ver } void CSGPrimitive3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_invert_faces", "invert_faces"), &CSGPrimitive3D::set_invert_faces); ClassDB::bind_method(D_METHOD("is_inverting_faces"), &CSGPrimitive3D::is_inverting_faces); @@ -715,7 +682,6 @@ CSGPrimitive3D::CSGPrimitive3D() { ///////////////////// CSGBrush *CSGMesh3D::_build_brush() { - if (!mesh.is_valid()) return nullptr; @@ -726,7 +692,6 @@ CSGBrush *CSGMesh3D::_build_brush() { Ref<Material> material = get_material(); for (int i = 0; i < mesh->get_surface_count(); i++) { - if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { continue; } @@ -781,7 +746,6 @@ CSGBrush *CSGMesh3D::_build_brush() { const int *ir = aindices.ptr(); for (int j = 0; j < is; j += 3) { - Vector3 vertex[3]; Vector3 normal[3]; Vector2 uv[3]; @@ -825,7 +789,6 @@ CSGBrush *CSGMesh3D::_build_brush() { Ref<Material> *mw = materials.ptrw(); for (int j = 0; j < is; j += 3) { - Vector3 vertex[3]; Vector3 normal[3]; Vector2 uv[3]; @@ -875,12 +838,10 @@ void CSGMesh3D::set_material(const Ref<Material> &p_material) { } Ref<Material> CSGMesh3D::get_material() const { - return material; } void CSGMesh3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CSGMesh3D::set_mesh); ClassDB::bind_method(D_METHOD("get_mesh"), &CSGMesh3D::get_mesh); @@ -892,7 +853,6 @@ void CSGMesh3D::_bind_methods() { } void CSGMesh3D::set_mesh(const Ref<Mesh> &p_mesh) { - if (mesh == p_mesh) return; if (mesh.is_valid()) { @@ -914,7 +874,6 @@ Ref<Mesh> CSGMesh3D::get_mesh() { //////////////////////////////// CSGBrush *CSGSphere3D::_build_brush() { - // set our bounding box CSGBrush *brush = memnew(CSGBrush); @@ -938,7 +897,6 @@ CSGBrush *CSGSphere3D::_build_brush() { invert.resize(face_count); { - Vector3 *facesw = faces.ptrw(); Vector2 *uvsw = uvs.ptrw(); bool *smoothw = smooth.ptrw(); @@ -959,7 +917,6 @@ CSGBrush *CSGSphere3D::_build_brush() { double u1 = double(i) / rings; for (int j = radial_segments; j >= 1; j--) { - double lng0 = 2 * Math_PI * (double)(j - 1) / radial_segments; double x0 = Math::cos(lng0); double y0 = Math::sin(lng0); @@ -986,7 +943,6 @@ CSGBrush *CSGSphere3D::_build_brush() { }; if (i < rings) { - //face 1 facesw[face * 3 + 0] = v[0]; facesw[face * 3 + 1] = v[1]; @@ -1096,13 +1052,11 @@ bool CSGSphere3D::get_smooth_faces() const { } void CSGSphere3D::set_material(const Ref<Material> &p_material) { - material = p_material; _make_dirty(); } Ref<Material> CSGSphere3D::get_material() const { - return material; } @@ -1117,7 +1071,6 @@ CSGSphere3D::CSGSphere3D() { /////////////// CSGBrush *CSGBox3D::_build_brush() { - // set our bounding box CSGBrush *brush = memnew(CSGBrush); @@ -1141,7 +1094,6 @@ CSGBrush *CSGBox3D::_build_brush() { invert.resize(face_count); { - Vector3 *facesw = faces.ptrw(); Vector2 *uvsw = uvs.ptrw(); bool *smoothw = smooth.ptrw(); @@ -1153,21 +1105,17 @@ CSGBrush *CSGBox3D::_build_brush() { Vector3 vertex_mul(width * 0.5, height * 0.5, depth * 0.5); { - for (int i = 0; i < 6; i++) { - Vector3 face_points[4]; float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 }; for (int j = 0; j < 4; j++) { - float v[3]; v[0] = 1.0; v[1] = 1 - 2 * ((j >> 1) & 1); v[2] = v[1] * (1 - 2 * (j & 1)); for (int k = 0; k < 3; k++) { - if (i < 3) face_points[j][(i + k) % 3] = v[k]; else @@ -1274,14 +1222,12 @@ float CSGBox3D::get_depth() const { } void CSGBox3D::set_material(const Ref<Material> &p_material) { - material = p_material; _make_dirty(); update_gizmo(); } Ref<Material> CSGBox3D::get_material() const { - return material; } @@ -1295,7 +1241,6 @@ CSGBox3D::CSGBox3D() { /////////////// CSGBrush *CSGCylinder3D::_build_brush() { - // set our bounding box CSGBrush *brush = memnew(CSGBrush); @@ -1319,7 +1264,6 @@ CSGBrush *CSGCylinder3D::_build_brush() { invert.resize(face_count); { - Vector3 *facesw = faces.ptrw(); Vector2 *uvsw = uvs.ptrw(); bool *smoothw = smooth.ptrw(); @@ -1331,9 +1275,7 @@ CSGBrush *CSGCylinder3D::_build_brush() { Vector3 vertex_mul(radius, height * 0.5, radius); { - for (int i = 0; i < sides; i++) { - float inc = float(i) / sides; float inc_n = float((i + 1)) / sides; @@ -1510,13 +1452,11 @@ bool CSGCylinder3D::get_smooth_faces() const { } void CSGCylinder3D::set_material(const Ref<Material> &p_material) { - material = p_material; _make_dirty(); } Ref<Material> CSGCylinder3D::get_material() const { - return material; } @@ -1532,7 +1472,6 @@ CSGCylinder3D::CSGCylinder3D() { /////////////// CSGBrush *CSGTorus3D::_build_brush() { - // set our bounding box float min_radius = inner_radius; @@ -1568,7 +1507,6 @@ CSGBrush *CSGTorus3D::_build_brush() { invert.resize(face_count); { - Vector3 *facesw = faces.ptrw(); Vector2 *uvsw = uvs.ptrw(); bool *smoothw = smooth.ptrw(); @@ -1578,9 +1516,7 @@ CSGBrush *CSGTorus3D::_build_brush() { int face = 0; { - for (int i = 0; i < sides; i++) { - float inci = float(i) / sides; float inci_n = float((i + 1)) / sides; @@ -1591,7 +1527,6 @@ CSGBrush *CSGTorus3D::_build_brush() { Vector3 normali_n = Vector3(Math::cos(angi_n), 0, Math::sin(angi_n)); for (int j = 0; j < ring_sides; j++) { - float incj = float(j) / ring_sides; float incj_n = float((j + 1)) / ring_sides; @@ -1738,13 +1673,11 @@ bool CSGTorus3D::get_smooth_faces() const { } void CSGTorus3D::set_material(const Ref<Material> &p_material) { - material = p_material; _make_dirty(); } Ref<Material> CSGTorus3D::get_material() const { - return material; } @@ -1760,7 +1693,6 @@ CSGTorus3D::CSGTorus3D() { /////////////// CSGBrush *CSGPolygon3D::_build_brush() { - // set our bounding box if (polygon.size() < 3) @@ -1871,7 +1803,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { AABB aabb; //must be computed { - Vector3 *facesw = faces.ptrw(); Vector2 *uvsw = uvs.ptrw(); bool *smoothw = smooth.ptrw(); @@ -1882,10 +1813,8 @@ CSGBrush *CSGPolygon3D::_build_brush() { switch (mode) { case MODE_DEPTH: { - //add triangles, front and back for (int i = 0; i < 2; i++) { - for (int j = 0; j < triangles.size(); j += 3) { for (int k = 0; k < 3; k++) { int src[3] = { 0, i == 0 ? 1 : 2, i == 0 ? 2 : 1 }; @@ -1910,7 +1839,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { //add triangles for depth for (int i = 0; i < final_polygon.size(); i++) { - int i_n = (i + 1) % final_polygon.size(); Vector3 v[4] = { @@ -1960,9 +1888,7 @@ CSGBrush *CSGPolygon3D::_build_brush() { } break; case MODE_SPIN: { - for (int i = 0; i < spin_sides; i++) { - float inci = float(i) / spin_sides; float inci_n = float((i + 1)) / spin_sides; @@ -1974,7 +1900,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { //add triangles for depth for (int j = 0; j < final_polygon.size(); j++) { - int j_n = (j + 1) % final_polygon.size(); Vector3 v[4] = { @@ -2023,7 +1948,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { } if (i == 0 && spin_degrees < 360) { - for (int j = 0; j < triangles.size(); j += 3) { for (int k = 0; k < 3; k++) { int src[3] = { 0, 2, 1 }; @@ -2041,7 +1965,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { } if (i == spin_sides - 1 && spin_degrees < 360) { - for (int j = 0; j < triangles.size(); j += 3) { for (int k = 0; k < 3; k++) { int src[3] = { 0, 1, 2 }; @@ -2061,7 +1984,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { } } break; case MODE_PATH: { - float bl = curve->get_baked_length(); int splits = MAX(2, Math::ceil(bl / path_interval)); float u1 = 0.0; @@ -2087,7 +2009,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { } for (int i = 0; i <= splits; i++) { - float ofs = i * path_interval; if (ofs > bl) { ofs = bl; @@ -2127,7 +2048,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { //put triangles where they belong //add triangles for depth for (int j = 0; j < final_polygon.size(); j++) { - int j_n = (j + 1) % final_polygon.size(); Vector3 v[4] = { @@ -2177,7 +2097,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { } if (i == 0 && !path_joined) { - for (int j = 0; j < triangles.size(); j += 3) { for (int k = 0; k < 3; k++) { int src[3] = { 0, 1, 2 }; @@ -2195,7 +2114,6 @@ CSGBrush *CSGPolygon3D::_build_brush() { } if (i == splits && !path_joined) { - for (int j = 0; j < triangles.size(); j += 3) { for (int k = 0; k < 3; k++) { int src[3] = { 0, 2, 1 }; @@ -2461,13 +2379,11 @@ bool CSGPolygon3D::get_smooth_faces() const { } void CSGPolygon3D::set_material(const Ref<Material> &p_material) { - material = p_material; _make_dirty(); } Ref<Material> CSGPolygon3D::get_material() const { - return material; } diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h index abab1ded20..7e95d685c5 100644 --- a/modules/csg/csg_shape.h +++ b/modules/csg/csg_shape.h @@ -204,7 +204,6 @@ public: }; class CSGSphere3D : public CSGPrimitive3D { - GDCLASS(CSGSphere3D, CSGPrimitive3D); virtual CSGBrush *_build_brush(); @@ -237,7 +236,6 @@ public: }; class CSGBox3D : public CSGPrimitive3D { - GDCLASS(CSGBox3D, CSGPrimitive3D); virtual CSGBrush *_build_brush(); @@ -266,7 +264,6 @@ public: }; class CSGCylinder3D : public CSGPrimitive3D { - GDCLASS(CSGCylinder3D, CSGPrimitive3D); virtual CSGBrush *_build_brush(); @@ -303,7 +300,6 @@ public: }; class CSGTorus3D : public CSGPrimitive3D { - GDCLASS(CSGTorus3D, CSGPrimitive3D); virtual CSGBrush *_build_brush(); @@ -340,7 +336,6 @@ public: }; class CSGPolygon3D : public CSGPrimitive3D { - GDCLASS(CSGPolygon3D, CSGPrimitive3D); public: diff --git a/modules/csg/register_types.cpp b/modules/csg/register_types.cpp index 40eef84b1b..a8bcc2fed1 100644 --- a/modules/csg/register_types.cpp +++ b/modules/csg/register_types.cpp @@ -34,7 +34,6 @@ #include "csg_shape.h" void register_csg_types() { - #ifndef _3D_DISABLED ClassDB::register_virtual_class<CSGShape3D>(); diff --git a/modules/cvtt/image_compress_cvtt.cpp b/modules/cvtt/image_compress_cvtt.cpp index 9dbaa88202..40e0f1a08f 100644 --- a/modules/cvtt/image_compress_cvtt.cpp +++ b/modules/cvtt/image_compress_cvtt.cpp @@ -137,7 +137,6 @@ static void _digest_job_queue(void *p_job_queue) { } void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::UsedChannels p_channels) { - if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) return; //do not compress, already compressed @@ -222,7 +221,6 @@ void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::UsedChann Vector<CVTTCompressionRowTask> tasks; for (int i = 0; i <= mm_count; i++) { - int bw = w % 4 != 0 ? w + (4 - w % 4) : w; int bh = h % 4 != 0 ? h + (4 - h % 4) : h; @@ -280,7 +278,6 @@ void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::UsedChann } void image_decompress_cvtt(Image *p_image) { - Image::Format target_format; bool is_signed = false; bool is_hdr = false; @@ -318,7 +315,6 @@ void image_decompress_cvtt(Image *p_image) { int dst_ofs = 0; for (int i = 0; i <= mm_count; i++) { - int src_ofs = p_image->get_mipmap_offset(i); const uint8_t *in_bytes = &rb[src_ofs]; diff --git a/modules/cvtt/register_types.cpp b/modules/cvtt/register_types.cpp index 38542a33b9..e4a01cc787 100644 --- a/modules/cvtt/register_types.cpp +++ b/modules/cvtt/register_types.cpp @@ -35,7 +35,6 @@ #include "image_compress_cvtt.h" void register_cvtt_types() { - Image::set_compress_bptc_func(image_compress_cvtt); Image::_image_decompress_bptc = image_decompress_cvtt; } diff --git a/modules/dds/register_types.cpp b/modules/dds/register_types.cpp index c6281ff01b..3991964a28 100644 --- a/modules/dds/register_types.cpp +++ b/modules/dds/register_types.cpp @@ -35,13 +35,11 @@ static Ref<ResourceFormatDDS> resource_loader_dds; void register_dds_types() { - resource_loader_dds.instance(); ResourceLoader::add_resource_format_loader(resource_loader_dds); } void unregister_dds_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_dds); resource_loader_dds.unref(); } diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 294d594135..052f2c5e01 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -95,7 +95,6 @@ static const DDSFormatInfo dds_format_info[DDS_MAX] = { }; RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -126,7 +125,6 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, //validate if (magic != DDS_MAGIC || hsize != 124 || !(flags & DDSD_PIXELFORMAT) || !(flags & DDSD_CAPS)) { - ERR_FAIL_V_MSG(RES(), "Invalid or unsupported DDS texture file '" + p_path + "'."); } @@ -163,58 +161,41 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, DDSFormat dds_format; if (format_flags & DDPF_FOURCC && format_fourcc == PF_FOURCC("DXT1")) { - dds_format = DDS_DXT1; } else if (format_flags & DDPF_FOURCC && format_fourcc == PF_FOURCC("DXT3")) { - dds_format = DDS_DXT3; } else if (format_flags & DDPF_FOURCC && format_fourcc == PF_FOURCC("DXT5")) { - dds_format = DDS_DXT5; } else if (format_flags & DDPF_FOURCC && format_fourcc == PF_FOURCC("ATI1")) { - dds_format = DDS_ATI1; } else if (format_flags & DDPF_FOURCC && format_fourcc == PF_FOURCC("ATI2")) { - dds_format = DDS_ATI2; } else if (format_flags & DDPF_FOURCC && format_fourcc == PF_FOURCC("A2XY")) { - dds_format = DDS_A2XY; } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0xff0000 && format_green_mask == 0xff00 && format_blue_mask == 0xff && format_alpha_mask == 0xff000000) { - dds_format = DDS_BGRA8; } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 24 && format_red_mask == 0xff0000 && format_green_mask == 0xff00 && format_blue_mask == 0xff) { - dds_format = DDS_BGR8; } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0xff && format_green_mask == 0xff00 && format_blue_mask == 0xff0000 && format_alpha_mask == 0xff000000) { - dds_format = DDS_RGBA8; } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 24 && format_red_mask == 0xff && format_green_mask == 0xff00 && format_blue_mask == 0xff0000) { - dds_format = DDS_RGB8; } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 16 && format_red_mask == 0x00007c00 && format_green_mask == 0x000003e0 && format_blue_mask == 0x0000001f && format_alpha_mask == 0x00008000) { - dds_format = DDS_BGR5A1; } else if (format_flags & DDPF_RGB && format_flags & DDPF_ALPHAPIXELS && format_rgb_bits == 32 && format_red_mask == 0x3ff00000 && format_green_mask == 0xffc00 && format_blue_mask == 0x3ff && format_alpha_mask == 0xc0000000) { - dds_format = DDS_BGR10A2; } else if (format_flags & DDPF_RGB && !(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 16 && format_red_mask == 0x0000f800 && format_green_mask == 0x000007e0 && format_blue_mask == 0x0000001f) { - dds_format = DDS_BGR565; } else if (!(format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 8 && format_red_mask == 0xff && format_green_mask == 0xff && format_blue_mask == 0xff) { - dds_format = DDS_LUMINANCE; } else if ((format_flags & DDPF_ALPHAPIXELS) && format_rgb_bits == 16 && format_red_mask == 0xff && format_green_mask == 0xff && format_blue_mask == 0xff && format_alpha_mask == 0xff00) { - dds_format = DDS_LUMINANCE_ALPHA; } else if (format_flags & DDPF_INDEXED && format_rgb_bits == 8) { - dds_format = DDS_BGR565; } else { - printf("unrecognized fourcc %x format_flags: %x - rgbbits %i - red_mask %x green mask %x blue mask %x alpha mask %x\n", format_fourcc, format_flags, format_rgb_bits, format_red_mask, format_green_mask, format_blue_mask, format_alpha_mask); ERR_FAIL_V_MSG(RES(), "Unrecognized or unsupported color layout in DDS '" + p_path + "'."); } @@ -236,7 +217,6 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, ERR_FAIL_COND_V(!(flags & DDSD_LINEARSIZE), RES()); for (uint32_t i = 1; i < mipmaps; i++) { - w = MAX(1, w >> 1); h = MAX(1, h >> 1); uint32_t bsize = MAX(info.divisor, w) / info.divisor * MAX(info.divisor, h) / info.divisor * info.block_size; @@ -249,7 +229,6 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, f->get_buffer(wb, size); } else if (info.palette) { - //indexed ERR_FAIL_COND_V(!(flags & DDSD_PITCH), RES()); ERR_FAIL_COND_V(format_rgb_bits != 8, RES()); @@ -262,7 +241,6 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, int colsize = 3; for (int i = 0; i < 256; i++) { - if (palette[i * 4 + 3] < 255) colsize = 4; } @@ -271,7 +249,6 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, int h2 = height; for (uint32_t i = 1; i < mipmaps; i++) { - w2 = (w2 + 1) >> 1; h2 = (h2 + 1) >> 1; size += w2 * h2 * info.block_size; @@ -282,7 +259,6 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, f->get_buffer(wb, size); for (int i = 0; i < 256; i++) { - int dst_ofs = size + i * colsize; int src_ofs = i * 4; wb[dst_ofs + 0] = palette[src_ofs + 2]; @@ -297,7 +273,6 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, uint32_t size = width * height * info.block_size; for (uint32_t i = 1; i < mipmaps; i++) { - w = (w + 1) >> 1; h = (h + 1) >> 1; size += w * h * info.block_size; @@ -313,14 +288,11 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, f->get_buffer(wb, size); switch (dds_format) { - case DDS_BGR5A1: { - // TO RGBA int colcount = size / 4; for (int i = colcount - 1; i >= 0; i--) { - int src_ofs = i * 2; int dst_ofs = i * 4; @@ -335,11 +307,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, } } break; case DDS_BGR565: { - int colcount = size / 3; for (int i = colcount - 1; i >= 0; i--) { - int src_ofs = i * 2; int dst_ofs = i * 3; @@ -353,12 +323,10 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, } break; case DDS_BGR10A2: { - // TO RGBA int colcount = size / 4; for (int i = colcount - 1; i >= 0; i--) { - int ofs = i * 4; uint32_t w32 = uint32_t(wb[ofs + 0]) | (uint32_t(wb[ofs + 1]) << 8) | (uint32_t(wb[ofs + 2]) << 16) | (uint32_t(wb[ofs + 3]) << 24); @@ -375,26 +343,21 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, } } break; case DDS_BGRA8: { - int colcount = size / 4; for (int i = 0; i < colcount; i++) { - SWAP(wb[i * 4 + 0], wb[i * 4 + 2]); } } break; case DDS_BGR8: { - int colcount = size / 3; for (int i = 0; i < colcount; i++) { - SWAP(wb[i * 3 + 0], wb[i * 3 + 2]); } } break; case DDS_RGBA8: { - /* do nothing either int colcount = size/4; @@ -413,7 +376,6 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, */ } break; case DDS_RGB8: { - // do nothing /* int colcount = size/3; @@ -424,12 +386,10 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, }*/ } break; case DDS_LUMINANCE: { - // do nothing i guess? } break; case DDS_LUMINANCE_ALPHA: { - // do nothing i guess? } break; @@ -451,17 +411,14 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, } void ResourceFormatDDS::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("dds"); } bool ResourceFormatDDS::handles_type(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Texture2D"); } String ResourceFormatDDS::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "dds") return "ImageTexture"; return ""; diff --git a/modules/denoise/lightmap_denoiser.cpp b/modules/denoise/lightmap_denoiser.cpp index c821b22d85..29d02e8ee2 100644 --- a/modules/denoise/lightmap_denoiser.cpp +++ b/modules/denoise/lightmap_denoiser.cpp @@ -40,7 +40,6 @@ void LightmapDenoiserOIDN::make_default_denoiser() { } Ref<Image> LightmapDenoiserOIDN::denoise_image(const Ref<Image> &p_image) { - Ref<Image> img = p_image->duplicate(); img->convert(Image::FORMAT_RGBF); diff --git a/modules/denoise/lightmap_denoiser.h b/modules/denoise/lightmap_denoiser.h index ac0cc8b9db..5b6e257df8 100644 --- a/modules/denoise/lightmap_denoiser.h +++ b/modules/denoise/lightmap_denoiser.h @@ -37,7 +37,6 @@ struct OIDNDeviceImpl; class LightmapDenoiserOIDN : public LightmapDenoiser { - GDCLASS(LightmapDenoiserOIDN, LightmapDenoiser); protected: diff --git a/modules/denoise/register_types.cpp b/modules/denoise/register_types.cpp index b6b92701c8..b78734a531 100644 --- a/modules/denoise/register_types.cpp +++ b/modules/denoise/register_types.cpp @@ -33,7 +33,6 @@ #include "lightmap_denoiser.h" void register_denoise_types() { - LightmapDenoiserOIDN::make_default_denoiser(); } diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 444ffae713..0ff747c6d8 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -34,21 +34,17 @@ #include "core/os/os.h" void NetworkedMultiplayerENet::set_transfer_mode(TransferMode p_mode) { - transfer_mode = p_mode; } NetworkedMultiplayerPeer::TransferMode NetworkedMultiplayerENet::get_transfer_mode() const { - return transfer_mode; } void NetworkedMultiplayerENet::set_target_peer(int p_peer) { - target_peer = p_peer; } int NetworkedMultiplayerENet::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); @@ -56,7 +52,6 @@ int NetworkedMultiplayerENet::get_packet_peer() const { } int NetworkedMultiplayerENet::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); @@ -64,7 +59,6 @@ int NetworkedMultiplayerENet::get_packet_channel() const { } int NetworkedMultiplayerENet::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); @@ -72,7 +66,6 @@ int NetworkedMultiplayerENet::get_last_packet_channel() const { } Error NetworkedMultiplayerENet::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 port number must be set 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)."); @@ -121,7 +114,6 @@ Error NetworkedMultiplayerENet::create_server(int p_port, int p_max_clients, int return OK; } Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_port, int p_in_bandwidth, int p_out_bandwidth, int p_client_port) { - 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 server port number must be set between 0 and 65535 (inclusive)."); ERR_FAIL_COND_V_MSG(p_client_port < 0 || p_client_port > 65535, ERR_INVALID_PARAMETER, "The client port number must be set between 0 and 65535 (inclusive)."); @@ -213,7 +205,6 @@ Error NetworkedMultiplayerENet::create_client(const String &p_address, int p_por } void NetworkedMultiplayerENet::poll() { - ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); _pop_current_packet(); @@ -221,7 +212,6 @@ void NetworkedMultiplayerENet::poll() { ENetEvent event; /* Keep servicing until there are no available events left in queue. */ while (true) { - if (!host || !active) // Might have been disconnected while emitting a notification return; @@ -272,7 +262,6 @@ void NetworkedMultiplayerENet::poll() { // Someone connected, notify all the peers available for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == *new_id) continue; // Send existing peers to new peer @@ -287,13 +276,11 @@ void NetworkedMultiplayerENet::poll() { enet_peer_send(E->get(), SYSCH_CONFIG, packet); } } else { - emit_signal("connection_succeeded"); } } break; case ENET_EVENT_TYPE_DISCONNECT: { - // Reset the peer's client information. int *id = (int *)event.peer->data; @@ -307,16 +294,13 @@ void NetworkedMultiplayerENet::poll() { } if (!server) { - // Client just disconnected from server. emit_signal("server_disconnected"); close_connection(); return; } else if (server_relay) { - // Server just received a client disconnect and is in relay mode, notify everyone else. for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == *id) continue; @@ -332,7 +316,6 @@ void NetworkedMultiplayerENet::poll() { memdelete(id); } break; case ENET_EVENT_TYPE_RECEIVE: { - if (event.channelID == SYSCH_CONFIG) { // Some config message ERR_CONTINUE(event.packet->dataLength < 8); @@ -345,13 +328,11 @@ void NetworkedMultiplayerENet::poll() { switch (msg) { case SYSMSG_ADD_PEER: { - peer_map[id] = nullptr; emit_signal("peer_connected", id); } break; case SYSMSG_REMOVE_PEER: { - peer_map.erase(id); emit_signal("peer_disconnected", id); } break; @@ -359,7 +340,6 @@ void NetworkedMultiplayerENet::poll() { enet_packet_destroy(event.packet); } else if (event.channelID < channel_count) { - Packet packet; packet.packet = event.packet; @@ -391,7 +371,6 @@ void NetworkedMultiplayerENet::poll() { incoming_packets.push_back(packet); // And make copies for sending for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) { - if (uint32_t(E->key()) == source) // Do not resend to self continue; @@ -405,7 +384,6 @@ void NetworkedMultiplayerENet::poll() { // And make copies for sending for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) { - if (uint32_t(E->key()) == source || E->key() == -target) // Do not resend to self, also do not send to excluded continue; @@ -428,7 +406,6 @@ void NetworkedMultiplayerENet::poll() { enet_peer_send(peer_map[target], event.channelID, packet.packet); } } else { - incoming_packets.push_back(packet); } @@ -452,7 +429,6 @@ bool NetworkedMultiplayerENet::is_server() const { } void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { - ERR_FAIL_COND_MSG(!active, "The multiplayer instance isn't currently active."); _pop_current_packet(); @@ -484,7 +460,6 @@ void NetworkedMultiplayerENet::close_connection(uint32_t wait_usec) { } void NetworkedMultiplayerENet::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)); @@ -497,7 +472,6 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { // notify everyone else, send disconnect signal & remove from peer_map like in poll() if (server_relay) { for (Map<int, ENetPeer *>::Element *E = peer_map.front(); E; E = E->next()) { - if (E->key() == p_peer) { continue; } @@ -520,12 +494,10 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { } int NetworkedMultiplayerENet::get_available_packet_count() const { - return incoming_packets.size(); } Error NetworkedMultiplayerENet::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(); @@ -540,7 +512,6 @@ Error NetworkedMultiplayerENet::get_packet(const uint8_t **r_buffer, int &r_buff } Error NetworkedMultiplayerENet::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."); @@ -571,7 +542,6 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer Map<int, ENetPeer *>::Element *E = nullptr; if (target_peer != 0) { - E = peer_map.find(ABS(target_peer)); ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, vformat("Invalid target peer: %d", target_peer)); } @@ -582,7 +552,6 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer copymem(&packet->data[8], p_buffer, p_buffer_size); if (server) { - if (target_peer == 0) { enet_host_broadcast(host, channel, packet); } else if (target_peer < 0) { @@ -592,7 +561,6 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer int exclude = -target_peer; for (Map<int, ENetPeer *>::Element *F = peer_map.front(); F; F = F->next()) { - if (F->key() == exclude) // Exclude packet continue; @@ -606,7 +574,6 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer enet_peer_send(E->get(), channel, packet); } } else { - ERR_FAIL_COND_V(!peer_map.has(1), ERR_BUG); enet_peer_send(peer_map[1], channel, packet); // Send to server for broadcast } @@ -617,12 +584,10 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer } int NetworkedMultiplayerENet::get_max_packet_size() const { - return 1 << 24; // Anything is good } void NetworkedMultiplayerENet::_pop_current_packet() { - if (current_packet.packet) { enet_packet_destroy(current_packet.packet); current_packet.packet = nullptr; @@ -632,16 +597,13 @@ void NetworkedMultiplayerENet::_pop_current_packet() { } NetworkedMultiplayerPeer::ConnectionStatus NetworkedMultiplayerENet::get_connection_status() const { - return connection_status; } uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { - uint32_t hash = 0; while (hash == 0 || hash == 1) { - hash = hash_djb2_one_32( (uint32_t)OS::get_singleton()->get_ticks_usec()); hash = hash_djb2_one_32( @@ -660,33 +622,27 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { } int NetworkedMultiplayerENet::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) { - refuse_connections = p_enable; } bool NetworkedMultiplayerENet::is_refusing_new_connections() const { - return refuse_connections; } void NetworkedMultiplayerENet::set_compression_mode(CompressionMode p_mode) { - compression_mode = p_mode; } NetworkedMultiplayerENet::CompressionMode NetworkedMultiplayerENet::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); if (size_t(enet->src_compressor_mem.size()) < inLimit) { @@ -739,20 +695,16 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer * } size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 *inData, size_t inLimit, enet_uint8 *outData, size_t outLimit) { - NetworkedMultiplayerENet *enet = (NetworkedMultiplayerENet *)(context); int ret = -1; switch (enet->compression_mode) { case COMPRESS_FASTLZ: { - ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_FASTLZ); } break; case COMPRESS_ZLIB: { - ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_DEFLATE); } break; case COMPRESS_ZSTD: { - ret = Compression::decompress(outData, outLimit, inData, inLimit, Compression::MODE_ZSTD); } break; default: { @@ -766,11 +718,8 @@ size_t NetworkedMultiplayerENet::enet_decompress(void *context, const enet_uint8 } void NetworkedMultiplayerENet::_setup_compressor() { - switch (compression_mode) { - case COMPRESS_NONE: { - enet_host_compress(host, nullptr); } break; case COMPRESS_RANGE_CODER: { @@ -779,19 +728,16 @@ void NetworkedMultiplayerENet::_setup_compressor() { case COMPRESS_FASTLZ: case COMPRESS_ZLIB: case COMPRESS_ZSTD: { - enet_host_compress(host, &enet_compressor); } break; } } void NetworkedMultiplayerENet::enet_compressor_destroy(void *context) { - // Nothing to do } IP_Address NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const { - ERR_FAIL_COND_V_MSG(!peer_map.has(p_peer_id), IP_Address(), 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, IP_Address(), "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, IP_Address(), vformat("Peer ID %d found in the list of peers, but is null.", p_peer_id)); @@ -807,7 +753,6 @@ IP_Address NetworkedMultiplayerENet::get_peer_address(int p_peer_id) const { } int NetworkedMultiplayerENet::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)); @@ -819,7 +764,6 @@ int NetworkedMultiplayerENet::get_peer_port(int p_peer_id) const { } void NetworkedMultiplayerENet::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; @@ -830,7 +774,6 @@ int NetworkedMultiplayerENet::get_transfer_channel() const { } void NetworkedMultiplayerENet::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; @@ -859,7 +802,6 @@ bool NetworkedMultiplayerENet::is_server_relay_enabled() const { } 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", "client_port"), &NetworkedMultiplayerENet::create_client, DEFVAL(0), DEFVAL(0), DEFVAL(0)); ClassDB::bind_method(D_METHOD("close_connection", "wait_usec"), &NetworkedMultiplayerENet::close_connection, DEFVAL(100)); @@ -903,7 +845,6 @@ void NetworkedMultiplayerENet::_bind_methods() { } NetworkedMultiplayerENet::NetworkedMultiplayerENet() { - active = false; server = false; refuse_connections = false; @@ -929,7 +870,6 @@ NetworkedMultiplayerENet::NetworkedMultiplayerENet() { } NetworkedMultiplayerENet::~NetworkedMultiplayerENet() { - if (active) { close_connection(); } diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h index ff436ce2c0..b2ed951327 100644 --- a/modules/enet/networked_multiplayer_enet.h +++ b/modules/enet/networked_multiplayer_enet.h @@ -38,7 +38,6 @@ #include <enet/enet.h> class NetworkedMultiplayerENet : public NetworkedMultiplayerPeer { - GDCLASS(NetworkedMultiplayerENet, NetworkedMultiplayerPeer); public: @@ -86,7 +85,6 @@ private: Map<int, ENetPeer *> peer_map; struct Packet { - ENetPacket *packet; int from; int channel; diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp index 27f27196d6..e5e9628c26 100644 --- a/modules/enet/register_types.cpp +++ b/modules/enet/register_types.cpp @@ -35,7 +35,6 @@ static bool enet_ok = false; void register_enet_types() { - if (enet_initialize() != 0) { ERR_PRINT("ENet initialization failure"); } else { @@ -46,7 +45,6 @@ void register_enet_types() { } void unregister_enet_types() { - if (enet_ok) enet_deinitialize(); } diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp index 223830f445..6bf4a7ef47 100644 --- a/modules/etc/image_etc.cpp +++ b/modules/etc/image_etc.cpp @@ -219,7 +219,6 @@ static void _compress_etc2(Image *p_img, float p_lossy_quality, Image::UsedChann } void _register_etc_compress_func() { - Image::_image_compress_etc1_func = _compress_etc1; Image::_image_compress_etc2_func = _compress_etc2; } diff --git a/modules/etc/register_types.cpp b/modules/etc/register_types.cpp index 26809e0de9..0972857808 100644 --- a/modules/etc/register_types.cpp +++ b/modules/etc/register_types.cpp @@ -36,7 +36,6 @@ static Ref<ResourceFormatPKM> resource_loader_pkm; void register_etc_types() { - resource_loader_pkm.instance(); ResourceLoader::add_resource_format_loader(resource_loader_pkm); @@ -44,7 +43,6 @@ void register_etc_types() { } void unregister_etc_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_pkm); resource_loader_pkm.unref(); } diff --git a/modules/etc/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp index bfb2098dff..78768c5ba9 100644 --- a/modules/etc/texture_loader_pkm.cpp +++ b/modules/etc/texture_loader_pkm.cpp @@ -43,7 +43,6 @@ struct ETC1Header { }; RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -96,17 +95,14 @@ RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, } void ResourceFormatPKM::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("pkm"); } bool ResourceFormatPKM::handles_type(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Texture2D"); } String ResourceFormatPKM::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "pkm") return "ImageTexture"; return ""; diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index a131e3a78f..7a231ac903 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -63,7 +63,6 @@ GDNativeLibrary::~GDNativeLibrary() { } bool GDNativeLibrary::_set(const StringName &p_name, const Variant &p_property) { - String name = p_name; if (name.begins_with("entry/")) { @@ -148,7 +147,6 @@ void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const { } void GDNativeLibrary::set_config_file(Ref<ConfigFile> p_config_file) { - set_singleton(p_config_file->get_value("general", "singleton", default_singleton)); set_load_once(p_config_file->get_value("general", "load_once", default_load_once)); set_symbol_prefix(p_config_file->get_value("general", "symbol_prefix", default_symbol_prefix)); @@ -156,7 +154,6 @@ void GDNativeLibrary::set_config_file(Ref<ConfigFile> p_config_file) { String entry_lib_path; { - List<String> entry_keys; if (p_config_file->has_section("entry")) @@ -188,7 +185,6 @@ void GDNativeLibrary::set_config_file(Ref<ConfigFile> p_config_file) { Vector<String> dependency_paths; { - List<String> dependency_keys; if (p_config_file->has_section("dependencies")) @@ -383,7 +379,6 @@ bool GDNative::initialize() { } bool GDNative::terminate() { - if (!initialized) { ERR_PRINT("No valid library handle, can't terminate GDNative object"); return false; @@ -452,7 +447,6 @@ Vector<StringName> GDNativeCallRegistry::get_native_call_types() { } Variant GDNative::call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments) { - Map<StringName, native_call_cb>::Element *E = GDNativeCallRegistry::singleton->native_calls.find(p_native_call_type); if (!E) { ERR_PRINT((String("No handler for native call type \"" + p_native_call_type) + "\" found").utf8().get_data()); @@ -478,7 +472,6 @@ Variant GDNative::call_native(StringName p_native_call_type, StringName p_proced } Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional) const { - if (!initialized) { ERR_PRINT("No valid library handle, can't get symbol from GDNative object"); return ERR_CANT_OPEN; @@ -526,7 +519,6 @@ String GDNativeLibraryResourceLoader::get_resource_type(const String &p_path) co } Error GDNativeLibraryResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Ref<GDNativeLibrary> lib = p_resource; if (lib.is_null()) { diff --git a/modules/gdnative/gdnative/color.cpp b/modules/gdnative/gdnative/color.cpp index 68c83e05a6..d79170771a 100644 --- a/modules/gdnative/gdnative/color.cpp +++ b/modules/gdnative/gdnative/color.cpp @@ -38,13 +38,11 @@ extern "C" { #endif void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a) { - Color *dest = (Color *)r_dest; *dest = Color(p_r, p_g, p_b, p_a); } void GDAPI godot_color_new_rgb(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b) { - Color *dest = (Color *)r_dest; *dest = Color(p_r, p_g, p_b); } diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp index 1216d1d9d3..234dbe9534 100644 --- a/modules/gdnative/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative/gdnative.cpp @@ -56,14 +56,12 @@ godot_object GDAPI *godot_global_get_singleton(char *p_name) { // MethodBind API godot_method_bind GDAPI *godot_method_bind_get_method(const char *p_classname, const char *p_methodname) { - MethodBind *mb = ClassDB::get_method(StringName(p_classname), StringName(p_methodname)); // MethodBind *mb = ClassDB::get_method("Node", "get_name"); return (godot_method_bind *)mb; } void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_object *p_instance, const void **p_args, void *p_ret) { - MethodBind *mb = (MethodBind *)p_method_bind; Object *o = (Object *)p_instance; mb->ptrcall(o, p_args, p_ret); diff --git a/modules/gdnative/gdnative/plane.cpp b/modules/gdnative/gdnative/plane.cpp index 17221fe081..923308dc34 100644 --- a/modules/gdnative/gdnative/plane.cpp +++ b/modules/gdnative/gdnative/plane.cpp @@ -38,7 +38,6 @@ extern "C" { #endif void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d) { - Plane *dest = (Plane *)r_dest; *dest = Plane(p_a, p_b, p_c, p_d); } diff --git a/modules/gdnative/gdnative/quat.cpp b/modules/gdnative/gdnative/quat.cpp index be30b89e5f..15c04f7191 100644 --- a/modules/gdnative/gdnative/quat.cpp +++ b/modules/gdnative/gdnative/quat.cpp @@ -38,7 +38,6 @@ extern "C" { #endif void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w) { - Quat *dest = (Quat *)r_dest; *dest = Quat(p_x, p_y, p_z, p_w); } diff --git a/modules/gdnative/gdnative/rect2.cpp b/modules/gdnative/gdnative/rect2.cpp index 906b4f0932..a2f735172f 100644 --- a/modules/gdnative/gdnative/rect2.cpp +++ b/modules/gdnative/gdnative/rect2.cpp @@ -45,7 +45,6 @@ void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const god } void GDAPI godot_rect2_new(godot_rect2 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_width, const godot_real p_height) { - Rect2 *dest = (Rect2 *)r_dest; *dest = Rect2(p_x, p_y, p_width, p_height); } diff --git a/modules/gdnative/gdnative/vector2.cpp b/modules/gdnative/gdnative/vector2.cpp index dc273e7951..b6c3569f42 100644 --- a/modules/gdnative/gdnative/vector2.cpp +++ b/modules/gdnative/gdnative/vector2.cpp @@ -38,7 +38,6 @@ extern "C" { #endif void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y) { - Vector2 *dest = (Vector2 *)r_dest; *dest = Vector2(p_x, p_y); } diff --git a/modules/gdnative/gdnative/vector3.cpp b/modules/gdnative/gdnative/vector3.cpp index bb27ad5a00..3e272ae9df 100644 --- a/modules/gdnative/gdnative/vector3.cpp +++ b/modules/gdnative/gdnative/vector3.cpp @@ -38,7 +38,6 @@ extern "C" { #endif void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z) { - Vector3 *dest = (Vector3 *)r_dest; *dest = Vector3(p_x, p_y, p_z); } diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp index 10ddd79d3a..278bc7217d 100644 --- a/modules/gdnative/gdnative_library_editor_plugin.cpp +++ b/modules/gdnative/gdnative_library_editor_plugin.cpp @@ -40,7 +40,6 @@ void GDNativeLibraryEditor::edit(Ref<GDNativeLibrary> p_library) { for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) { - String target = E->key() + "." + it->get(); TargetConfig ecfg; ecfg.library = config->get_value("entry", target, ""); @@ -56,14 +55,12 @@ void GDNativeLibraryEditor::_bind_methods() { } void GDNativeLibraryEditor::_update_tree() { - tree->clear(); TreeItem *root = tree->create_item(); PopupMenu *filter_list = filter->get_popup(); String text = ""; for (int i = 0; i < filter_list->get_item_count(); i++) { - if (!filter_list->is_item_checked(i)) { continue; } @@ -84,7 +81,6 @@ void GDNativeLibraryEditor::_update_tree() { platform->set_expand_right(0, true); for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) { - String target = E->key() + "." + it->get(); TreeItem *bit = tree->create_item(platform); @@ -125,14 +121,12 @@ void GDNativeLibraryEditor::_update_tree() { } void GDNativeLibraryEditor::_on_item_button(Object *item, int column, int id) { - String target = Object::cast_to<TreeItem>(item)->get_metadata(0); String platform = target.substr(0, target.find(".")); String entry = target.substr(platform.length() + 1, target.length()); String section = (id == BUTTON_SELECT_DEPENDENCES || id == BUTTON_CLEAR_DEPENDENCES) ? "dependencies" : "entry"; if (id == BUTTON_SELECT_LIBRARY || id == BUTTON_SELECT_DEPENDENCES) { - EditorFileDialog::FileMode mode = EditorFileDialog::FILE_MODE_OPEN_FILE; if (id == BUTTON_SELECT_DEPENDENCES) mode = EditorFileDialog::FILE_MODE_OPEN_FILES; @@ -156,24 +150,20 @@ void GDNativeLibraryEditor::_on_item_button(Object *item, int column, int id) { } void GDNativeLibraryEditor::_on_library_selected(const String &file) { - _set_target_value(file_dialog->get_meta("section"), file_dialog->get_meta("target"), file); } void GDNativeLibraryEditor::_on_dependencies_selected(const PackedStringArray &files) { - _set_target_value(file_dialog->get_meta("section"), file_dialog->get_meta("target"), files); } void GDNativeLibraryEditor::_on_filter_selected(int index) { - PopupMenu *filter_list = filter->get_popup(); filter_list->set_item_checked(index, !filter_list->is_item_checked(index)); _update_tree(); } void GDNativeLibraryEditor::_on_item_collapsed(Object *p_item) { - TreeItem *item = Object::cast_to<TreeItem>(p_item); String name = item->get_text(0); @@ -185,7 +175,6 @@ void GDNativeLibraryEditor::_on_item_collapsed(Object *p_item) { } void GDNativeLibraryEditor::_on_item_activated() { - TreeItem *item = tree->get_selected(); if (item && tree->get_selected_column() == 0 && item->get_metadata(0).get_type() == Variant::NIL) { new_architecture_dialog->set_meta("platform", item->get_metadata(1)); @@ -194,7 +183,6 @@ void GDNativeLibraryEditor::_on_item_activated() { } void GDNativeLibraryEditor::_on_create_new_entry() { - String platform = new_architecture_dialog->get_meta("platform"); String entry = new_architecture_input->get_text().strip_edges(); if (!entry.empty()) { @@ -213,10 +201,8 @@ void GDNativeLibraryEditor::_set_target_value(const String §ion, const Strin } void GDNativeLibraryEditor::_erase_entry(const String &platform, const String &entry) { - if (platforms.has(platform)) { if (List<String>::Element *E = platforms[platform].entries.find(entry)) { - String target = platform + "." + entry; platforms[platform].entries.erase(E); @@ -243,16 +229,13 @@ void GDNativeLibraryEditor::_move_entry(const String &platform, const String &en } void GDNativeLibraryEditor::_translate_to_config_file() { - if (!library.is_null()) { - Ref<ConfigFile> config = library->get_config_file(); config->erase_section("entry"); config->erase_section("dependencies"); for (Map<String, NativePlatformConfig>::Element *E = platforms.front(); E; E = E->next()) { for (List<String>::Element *it = E->value().entries.front(); it; it = it->next()) { - String target = E->key() + "." + it->get(); if (entry_configs[target].library.empty() && entry_configs[target].dependencies.empty()) continue; @@ -267,7 +250,6 @@ void GDNativeLibraryEditor::_translate_to_config_file() { } GDNativeLibraryEditor::GDNativeLibraryEditor() { - { // Define platforms NativePlatformConfig platform_windows; platform_windows.name = "Windows"; @@ -388,19 +370,16 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() { } void GDNativeLibraryEditorPlugin::edit(Object *p_node) { - Ref<GDNativeLibrary> new_library = Object::cast_to<GDNativeLibrary>(p_node); if (new_library.is_valid()) library_editor->edit(new_library); } bool GDNativeLibraryEditorPlugin::handles(Object *p_node) const { - return p_node->is_class("GDNativeLibrary"); } void GDNativeLibraryEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { button->show(); EditorNode::get_singleton()->make_bottom_panel_item_visible(library_editor); @@ -413,7 +392,6 @@ void GDNativeLibraryEditorPlugin::make_visible(bool p_visible) { } GDNativeLibraryEditorPlugin::GDNativeLibraryEditorPlugin(EditorNode *p_node) { - library_editor = memnew(GDNativeLibraryEditor); library_editor->set_custom_minimum_size(Size2(0, 250 * EDSCALE)); button = p_node->add_bottom_panel_item(TTR("GDNativeLibrary"), library_editor); diff --git a/modules/gdnative/gdnative_library_editor_plugin.h b/modules/gdnative/gdnative_library_editor_plugin.h index b1274d08b3..5fdb860ca3 100644 --- a/modules/gdnative/gdnative_library_editor_plugin.h +++ b/modules/gdnative/gdnative_library_editor_plugin.h @@ -36,7 +36,6 @@ #include "gdnative.h" class GDNativeLibraryEditor : public Control { - GDCLASS(GDNativeLibraryEditor, Control); struct NativePlatformConfig { @@ -94,7 +93,6 @@ public: }; class GDNativeLibraryEditorPlugin : public EditorPlugin { - GDCLASS(GDNativeLibraryEditorPlugin, EditorPlugin); GDNativeLibraryEditor *library_editor; diff --git a/modules/gdnative/gdnative_library_singleton_editor.cpp b/modules/gdnative/gdnative_library_singleton_editor.cpp index 378339ecea..27f18c91a8 100644 --- a/modules/gdnative/gdnative_library_singleton_editor.cpp +++ b/modules/gdnative/gdnative_library_singleton_editor.cpp @@ -35,7 +35,6 @@ #include "editor/editor_node.h" Set<String> GDNativeLibrarySingletonEditor::_find_singletons_recursive(EditorFileSystemDirectory *p_dir) { - Set<String> file_paths; // check children @@ -67,7 +66,6 @@ Set<String> GDNativeLibrarySingletonEditor::_find_singletons_recursive(EditorFil } void GDNativeLibrarySingletonEditor::_discover_singletons() { - EditorFileSystemDirectory *dir = EditorFileSystem::get_singleton()->get_filesystem(); Set<String> file_paths = _find_singletons_recursive(dir); @@ -97,7 +95,6 @@ void GDNativeLibrarySingletonEditor::_discover_singletons() { } if (changed) { - ProjectSettings::get_singleton()->set("gdnative/singletons", files); _update_libraries(); // So singleton options (i.e. disabled) updates too ProjectSettings::get_singleton()->save(); @@ -105,7 +102,6 @@ void GDNativeLibrarySingletonEditor::_discover_singletons() { } void GDNativeLibrarySingletonEditor::_update_libraries() { - updating = true; libraries->clear(); libraries->create_item(); // root item @@ -182,7 +178,6 @@ void GDNativeLibrarySingletonEditor::_item_edited() { } void GDNativeLibrarySingletonEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { if (is_visible_in_tree()) { _update_libraries(); @@ -191,7 +186,6 @@ void GDNativeLibrarySingletonEditor::_notification(int p_what) { } void GDNativeLibrarySingletonEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_update_libraries"), &GDNativeLibrarySingletonEditor::_update_libraries); } diff --git a/modules/gdnative/include/net/godot_net.h b/modules/gdnative/include/net/godot_net.h index d245f3b965..42804112f2 100644 --- a/modules/gdnative/include/net/godot_net.h +++ b/modules/gdnative/include/net/godot_net.h @@ -45,7 +45,6 @@ extern "C" { #define GODOT_NET_API_MINOR 1 typedef struct { - godot_gdnative_api_version version; /* version of our API */ godot_object *data; /* User reference */ diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index 3c0cfd0484..62f2ec5024 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -41,7 +41,6 @@ // helper stuff static Error save_file(const String &p_path, const List<String> &p_content) { - FileAccessRef file = FileAccess::open(p_path, FileAccess::WRITE); ERR_FAIL_COND_V(!file, ERR_FILE_CANT_WRITE); @@ -146,7 +145,6 @@ static String get_type_name(const PropertyInfo &info) { struct MethodInfoComparator { StringName::AlphCompare compare; bool operator()(const MethodInfo &p_a, const MethodInfo &p_b) const { - return compare(p_a.name, p_b.name); } }; @@ -154,7 +152,6 @@ struct MethodInfoComparator { struct PropertyInfoComparator { StringName::AlphCompare compare; bool operator()(const PropertyInfo &p_a, const PropertyInfo &p_b) const { - return compare(p_a.name, p_b.name); } }; @@ -162,7 +159,6 @@ struct PropertyInfoComparator { struct ConstantAPIComparator { NoCaseComparator compare; bool operator()(const ConstantAPI &p_a, const ConstantAPI &p_b) const { - return compare(p_a.constant_name, p_b.constant_name); } }; @@ -171,7 +167,6 @@ struct ConstantAPIComparator { * Reads the entire Godot API to a list */ List<ClassAPI> generate_c_api_classes() { - List<ClassAPI> api; List<StringName> classes; @@ -410,7 +405,6 @@ List<ClassAPI> generate_c_api_classes() { * Generates the JSON source from the API in p_api */ static List<String> generate_c_api_json(const List<ClassAPI> &p_api) { - // I'm sorry for the \t mess List<String> source; @@ -520,7 +514,6 @@ static List<String> generate_c_api_json(const List<ClassAPI> &p_api) { * p_path */ Error generate_c_api(const String &p_path) { - #ifndef TOOLS_ENABLED return ERR_BUG; #else diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp index 0502458b4f..ee944ee7cb 100644 --- a/modules/gdnative/nativescript/godot_nativescript.cpp +++ b/modules/gdnative/nativescript/godot_nativescript.cpp @@ -52,7 +52,6 @@ extern "C" void _native_script_hook() { // Script API void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) { - String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s]; @@ -85,7 +84,6 @@ void GDAPI godot_nativescript_register_class(void *p_gdnative_handle, const char } void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const char *p_name, const char *p_base, godot_instance_create_func p_create_func, godot_instance_destroy_func p_destroy_func) { - String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc> *classes = &NSL->library_classes[*s]; @@ -119,7 +117,6 @@ void GDAPI godot_nativescript_register_tool_class(void *p_gdnative_handle, const } void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const char *p_name, const char *p_function_name, godot_method_attributes p_attr, godot_instance_method p_method) { - String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); @@ -139,7 +136,6 @@ void GDAPI godot_nativescript_register_method(void *p_gdnative_handle, const cha } void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const char *p_name, const char *p_path, godot_property_attributes *p_attr, godot_property_set_func p_set_func, godot_property_get_func p_get_func) { - String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); @@ -164,7 +160,6 @@ void GDAPI godot_nativescript_register_property(void *p_gdnative_handle, const c } void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const char *p_name, const godot_signal *p_signal) { - String *s = (String *)p_gdnative_handle; Map<StringName, NativeScriptDesc>::Element *E = NSL->library_classes[*s].find(p_name); @@ -315,7 +310,6 @@ void GDAPI godot_nativescript_set_type_tag(void *p_gdnative_handle, const char * } const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object) { - const Object *o = (Object *)p_object; if (!o->get_script_instance()) { diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index ed3ec44bf7..70a651be1e 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -169,7 +169,6 @@ String NativeScript::get_script_class_icon_path() const { } bool NativeScript::can_instance() const { - NativeScriptDesc *script_data = get_script_desc(); #ifdef TOOLS_ENABLED @@ -207,7 +206,6 @@ StringName NativeScript::get_instance_base_type() const { } ScriptInstance *NativeScript::instance_create(Object *p_this) { - NativeScriptDesc *script_data = get_script_desc(); if (!script_data) { @@ -336,7 +334,6 @@ void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { Set<MethodInfo> signals_; while (script_data) { - for (Map<StringName, NativeScriptDesc::Signal>::Element *S = script_data->signals_.front(); S; S = S->next()) { signals_.insert(S->get().signal); } @@ -376,7 +373,6 @@ void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const { Set<MethodInfo> methods; while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { methods.insert(E->get().info); } @@ -408,13 +404,11 @@ void NativeScript::get_script_property_list(List<PropertyInfo> *p_list) const { } Vector<ScriptNetData> NativeScript::get_rpc_methods() const { - Vector<ScriptNetData> v; NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_mode != GODOT_METHOD_RPC_MODE_DISABLED) { ScriptNetData nd; @@ -434,7 +428,6 @@ uint16_t NativeScript::get_rpc_method_id(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); if (E) { return E->get().rpc_method_id; @@ -452,7 +445,6 @@ StringName NativeScript::get_rpc_method(uint16_t p_id) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_method_id == p_id) { return E->key(); @@ -466,13 +458,11 @@ StringName NativeScript::get_rpc_method(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const { - ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED); NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.front(); E; E = E->next()) { if (E->get().rpc_method_id == p_id) { switch (E->get().rpc_mode) { @@ -503,11 +493,9 @@ MultiplayerAPI::RPCMode NativeScript::get_rpc_mode_by_id(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rpc_mode(const StringName &p_method) const { - NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find(p_method); if (E) { switch (E->get().rpc_mode) { @@ -542,7 +530,6 @@ Vector<ScriptNetData> NativeScript::get_rset_properties() const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_mode != GODOT_METHOD_RPC_MODE_DISABLED) { ScriptNetData nd; @@ -561,7 +548,6 @@ uint16_t NativeScript::get_rset_property_id(const StringName &p_variable) const NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable); if (E) { return E.get().rset_property_id; @@ -579,7 +565,6 @@ StringName NativeScript::get_rset_property(uint16_t p_id) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_property_id == p_id) { return E.key(); @@ -593,13 +578,11 @@ StringName NativeScript::get_rset_property(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const { - ERR_FAIL_COND_V(p_id == UINT16_MAX, MultiplayerAPI::RPC_MODE_DISABLED); NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.front(); E; E = E.next()) { if (E.get().rset_property_id == p_id) { switch (E.get().rset_mode) { @@ -630,11 +613,9 @@ MultiplayerAPI::RPCMode NativeScript::get_rset_mode_by_id(uint16_t p_id) const { } MultiplayerAPI::RPCMode NativeScript::get_rset_mode(const StringName &p_variable) const { - NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element E = script_data->properties.find(p_variable); if (E) { switch (E.get().rset_mode) { @@ -677,7 +658,6 @@ String NativeScript::get_method_documentation(const StringName &p_method) const ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get method documentation on invalid NativeScript."); while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *method = script_data->methods.find(p_method); if (method) { @@ -696,7 +676,6 @@ String NativeScript::get_signal_documentation(const StringName &p_signal_name) c ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get signal documentation on invalid NativeScript."); while (script_data) { - Map<StringName, NativeScriptDesc::Signal>::Element *signal = script_data->signals_.find(p_signal_name); if (signal) { @@ -715,7 +694,6 @@ String NativeScript::get_property_documentation(const StringName &p_path) const ERR_FAIL_COND_V_MSG(!script_data, "", "Attempt to get property documentation on invalid NativeScript."); while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element property = script_data->properties.find(p_path); if (property) { @@ -729,7 +707,6 @@ String NativeScript::get_property_documentation(const StringName &p_path) const } Variant NativeScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (lib_path.empty() || class_name.empty() || library.is_null()) { r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; return Variant(); @@ -884,10 +861,8 @@ void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { - Map<StringName, NativeScriptDesc::Method>::Element *E = script_data->methods.find("_get_property_list"); if (E) { - godot_variant result; result = E->get().method.method((godot_object *)owner, E->get().method.method_data, @@ -936,11 +911,9 @@ void NativeScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c } Variant::Type NativeScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { - OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = script_data->properties.find(p_name); if (P) { *r_is_valid = true; @@ -961,7 +934,6 @@ bool NativeScriptInstance::has_method(const StringName &p_method) const { } Variant NativeScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); while (script_data) { @@ -1127,7 +1099,6 @@ void NativeScriptInstance::call_multilevel_reversed(const StringName &p_method, } NativeScriptInstance::~NativeScriptInstance() { - NativeScriptDesc *script_data = GET_SCRIPT_DESC(); if (!script_data) @@ -1145,16 +1116,13 @@ NativeScriptInstance::~NativeScriptInstance() { NativeScriptLanguage *NativeScriptLanguage::singleton; void NativeScriptLanguage::_unload_stuff(bool p_reload) { - Map<String, Ref<GDNative>> erase_and_unload; for (Map<String, Map<StringName, NativeScriptDesc>>::Element *L = library_classes.front(); L; L = L->next()) { - String lib_path = L->key(); Map<StringName, NativeScriptDesc> classes = L->get(); if (p_reload) { - Map<String, Ref<GDNative>>::Element *E = library_gdnatives.find(lib_path); Ref<GDNative> gdn; @@ -1184,7 +1152,6 @@ void NativeScriptLanguage::_unload_stuff(bool p_reload) { } for (Map<StringName, NativeScriptDesc>::Element *C = classes.front(); C; C = C->next()) { - // free property stuff first for (OrderedHashMap<StringName, NativeScriptDesc::Property>::Element P = C->get().properties.front(); P; P = P.next()) { if (P.get().getter.free_func) @@ -1253,13 +1220,10 @@ NativeScriptLanguage::NativeScriptLanguage() { } NativeScriptLanguage::~NativeScriptLanguage() { - for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> lib = L->get(); // only shut down valid libs, duh! if (lib.is_valid()) { - // If it's a singleton-library then the gdnative module // manages the destruction at engine shutdown, not NativeScript. if (!lib->get_library()->is_singleton()) { @@ -1285,7 +1249,6 @@ void _add_reload_node() { } void NativeScriptLanguage::init() { - #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) List<String> args = OS::get_singleton()->get_cmdline_args(); @@ -1490,7 +1453,6 @@ void NativeScriptLanguage::profiling_add_data(StringName p_signature, uint64_t p } int NativeScriptLanguage::register_binding_functions(godot_instance_binding_functions p_binding_functions) { - // find index int idx = -1; @@ -1553,7 +1515,6 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec } if (!(*binding_data)[p_idx]) { - const void *global_type_tag = get_global_type_tag(p_idx, p_object->get_class_name()); // no binding data yet, soooooo alloc new one \o/ @@ -1564,7 +1525,6 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec } void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { - Vector<void *> *binding_data = new Vector<void *>; binding_data->resize(binding_functions.size()); @@ -1579,7 +1539,6 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { } void NativeScriptLanguage::free_instance_binding_data(void *p_data) { - if (!p_data) return; @@ -1600,7 +1559,6 @@ void NativeScriptLanguage::free_instance_binding_data(void *p_data) { } void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_object) { - void *data = p_object->get_script_instance_binding(lang_idx); if (!data) @@ -1622,7 +1580,6 @@ void NativeScriptLanguage::refcount_incremented_instance_binding(Object *p_objec } bool NativeScriptLanguage::refcount_decremented_instance_binding(Object *p_object) { - void *data = p_object->get_script_instance_binding(lang_idx); if (!data) @@ -1741,13 +1698,11 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { void NativeScriptLanguage::call_libraries_cb(const StringName &name) { // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here for (Map<String, Ref<GDNative>>::Element *L = library_gdnatives.front(); L; L = L->next()) { - if (L->get().is_null()) { continue; } if (L->get()->is_initialized()) { - void *proc_ptr; Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + name, proc_ptr); @@ -1835,14 +1790,12 @@ void NativeReloadNode::_notification(int p_what) { switch (p_what) { case NOTIFICATION_WM_FOCUS_OUT: { - if (unloaded) break; MutexLock lock(NSL->mutex); NSL->_unload_stuff(true); for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> gdn = L->get(); if (gdn.is_null()) { @@ -1870,14 +1823,12 @@ void NativeReloadNode::_notification(int p_what) { } break; case NOTIFICATION_WM_FOCUS_IN: { - if (!unloaded) break; MutexLock lock(NSL->mutex); Set<StringName> libs_to_remove; for (Map<String, Ref<GDNative>>::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { - Ref<GDNative> gdn = L->get(); if (gdn.is_null()) { diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index d24b247e59..1aca142889 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -47,7 +47,6 @@ #include <nativescript/godot_nativescript.h> struct NativeScriptDesc { - struct Method { godot_instance_method method; MethodInfo info; @@ -194,7 +193,6 @@ public: }; class NativeScriptInstance : public ScriptInstance { - friend class NativeScript; Object *owner; @@ -245,7 +243,6 @@ public: class NativeReloadNode; class NativeScriptLanguage : public ScriptLanguage { - friend class NativeScript; friend class NativeScriptInstance; friend class NativeReloadNode; diff --git a/modules/gdnative/nativescript/register_types.cpp b/modules/gdnative/nativescript/register_types.cpp index b5e8174e43..ac8c7ab2fd 100644 --- a/modules/gdnative/nativescript/register_types.cpp +++ b/modules/gdnative/nativescript/register_types.cpp @@ -58,7 +58,6 @@ void register_nativescript_types() { } void unregister_nativescript_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_gdns); resource_loader_gdns.unref(); diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.cpp b/modules/gdnative/net/multiplayer_peer_gdnative.cpp index a95697ea65..997eec6425 100644 --- a/modules/gdnative/net/multiplayer_peer_gdnative.cpp +++ b/modules/gdnative/net/multiplayer_peer_gdnative.cpp @@ -120,7 +120,6 @@ void MultiplayerPeerGDNative::_bind_methods() { extern "C" { void GDAPI godot_net_bind_multiplayer_peer(godot_object *p_obj, const godot_net_multiplayer_peer *p_impl) { - ((MultiplayerPeerGDNative *)p_obj)->set_native_multiplayer_peer(p_impl); } } diff --git a/modules/gdnative/net/packet_peer_gdnative.cpp b/modules/gdnative/net/packet_peer_gdnative.cpp index 28135df3b6..6bb21cb48d 100644 --- a/modules/gdnative/net/packet_peer_gdnative.cpp +++ b/modules/gdnative/net/packet_peer_gdnative.cpp @@ -67,7 +67,6 @@ int PacketPeerGDNative::get_available_packet_count() const { extern "C" { void GDAPI godot_net_bind_packet_peer(godot_object *p_obj, const godot_net_packet_peer *p_impl) { - ((PacketPeerGDNative *)p_obj)->set_native_packet_peer(p_impl); } } diff --git a/modules/gdnative/net/stream_peer_gdnative.h b/modules/gdnative/net/stream_peer_gdnative.h index f3711e0f0f..0b2f995aa7 100644 --- a/modules/gdnative/net/stream_peer_gdnative.h +++ b/modules/gdnative/net/stream_peer_gdnative.h @@ -36,7 +36,6 @@ #include "modules/gdnative/include/net/godot_net.h" class StreamPeerGDNative : public StreamPeer { - GDCLASS(StreamPeerGDNative, StreamPeer); protected: diff --git a/modules/gdnative/pluginscript/pluginscript_loader.cpp b/modules/gdnative/pluginscript/pluginscript_loader.cpp index 64582cc517..7ce124c16a 100644 --- a/modules/gdnative/pluginscript/pluginscript_loader.cpp +++ b/modules/gdnative/pluginscript/pluginscript_loader.cpp @@ -101,13 +101,11 @@ Error ResourceFormatSaverPluginScript::save(const String &p_path, const RES &p_r } void ResourceFormatSaverPluginScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (Object::cast_to<PluginScript>(*p_resource)) { p_extensions->push_back(_language->get_extension()); } } bool ResourceFormatSaverPluginScript::recognize(const RES &p_resource) const { - return Object::cast_to<PluginScript>(*p_resource) != nullptr; } diff --git a/modules/gdnative/pluginscript/pluginscript_loader.h b/modules/gdnative/pluginscript/pluginscript_loader.h index e47754490a..35fc79c2ca 100644 --- a/modules/gdnative/pluginscript/pluginscript_loader.h +++ b/modules/gdnative/pluginscript/pluginscript_loader.h @@ -39,7 +39,6 @@ class PluginScriptLanguage; class ResourceFormatLoaderPluginScript : public ResourceFormatLoader { - PluginScriptLanguage *_language; public: @@ -51,7 +50,6 @@ public: }; class ResourceFormatSaverPluginScript : public ResourceFormatSaver { - PluginScriptLanguage *_language; public: diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index 9b00d654d1..d659ade876 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -56,7 +56,6 @@ void PluginScript::_bind_methods() { } PluginScriptInstance *PluginScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; // Create instance @@ -84,7 +83,6 @@ PluginScriptInstance *PluginScript::_create_instance(const Variant **p_args, int } Variant PluginScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; if (!_valid) { @@ -167,7 +165,6 @@ void PluginScript::update_exports() { #ifdef TOOLS_ENABLED ASSERT_SCRIPT_VALID(); if (placeholders.size()) { - //update placeholders if any Map<StringName, Variant> propdefvalues; List<PropertyInfo> propinfos; @@ -281,7 +278,6 @@ Error PluginScript::reload(bool p_keep_state) { // ClassDB name (i.e. `Node2D`) or a resource path (i.e. `res://foo/bar.gd`) StringName *base_name = (StringName *)&manifest.base; if (*base_name) { - if (ClassDB::class_exists(*base_name)) { _native_parent = *base_name; } else { @@ -434,7 +430,6 @@ ScriptLanguage *PluginScript::get_language() const { } Error PluginScript::load_source_code(const String &p_path) { - Vector<uint8_t> sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); diff --git a/modules/gdnative/pluginscript/pluginscript_script.h b/modules/gdnative/pluginscript/pluginscript_script.h index 287f42bf7b..659289ef9b 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.h +++ b/modules/gdnative/pluginscript/pluginscript_script.h @@ -38,7 +38,6 @@ #include <pluginscript/godot_pluginscript.h> class PluginScript : public Script { - GDCLASS(PluginScript, Script); friend class PluginScriptInstance; diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 67a286ee2e..bffbb86526 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -53,7 +53,6 @@ #include "gdnative_library_singleton_editor.h" class GDNativeExportPlugin : public EditorExportPlugin { - protected: virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features); }; @@ -77,7 +76,6 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty Ref<ConfigFile> config = lib->get_config_file(); { - List<String> entry_keys; config->get_section_keys("entry", &entry_keys); @@ -189,7 +187,6 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty } static void editor_init_callback() { - GDNativeLibrarySingletonEditor *library_editor = memnew(GDNativeLibrarySingletonEditor); library_editor->set_name(TTR("GDNative")); ProjectSettingsEditor::get_singleton()->get_tabs()->add_child(library_editor); @@ -205,7 +202,6 @@ static void editor_init_callback() { #endif static godot_variant cb_standard_varcall(void *p_procedure_handle, godot_array *p_args) { - godot_gdnative_procedure_fn proc; proc = (godot_gdnative_procedure_fn)p_procedure_handle; @@ -220,7 +216,6 @@ Ref<GDNativeLibraryResourceLoader> resource_loader_gdnlib; Ref<GDNativeLibraryResourceSaver> resource_saver_gdnlib; void register_gdnative_types() { - #ifdef TOOLS_ENABLED EditorNode::add_init_callback(editor_init_callback); @@ -287,9 +282,7 @@ void register_gdnative_types() { } void unregister_gdnative_types() { - for (int i = 0; i < singleton_gdnatives.size(); i++) { - if (singleton_gdnatives[i].is_null()) { continue; } diff --git a/modules/gdnative/videodecoder/register_types.cpp b/modules/gdnative/videodecoder/register_types.cpp index c53e8f2c78..4181d8813f 100644 --- a/modules/gdnative/videodecoder/register_types.cpp +++ b/modules/gdnative/videodecoder/register_types.cpp @@ -36,7 +36,6 @@ static Ref<ResourceFormatLoaderVideoStreamGDNative> resource_loader_vsgdnative; void register_videodecoder_types() { - resource_loader_vsgdnative.instance(); ResourceLoader::add_resource_format_loader(resource_loader_vsgdnative, true); @@ -44,7 +43,6 @@ void register_videodecoder_types() { } void unregister_videodecoder_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_vsgdnative); resource_loader_vsgdnative.unref(); } diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp index a2ff376e31..476f44b185 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp +++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp @@ -105,7 +105,6 @@ int64_t GDAPI godot_videodecoder_file_seek(void *ptr, int64_t pos, int whence) { } void GDAPI godot_videodecoder_register_decoder(const godot_videodecoder_interface_gdnative *p_interface) { - decoder_server.register_decoder_interface(p_interface); } } @@ -240,7 +239,6 @@ bool VideoStreamPlaybackGDNative::is_paused() const { } void VideoStreamPlaybackGDNative::play() { - stop(); playing = true; @@ -282,7 +280,6 @@ float VideoStreamPlaybackGDNative::get_length() const { } float VideoStreamPlaybackGDNative::get_playback_position() const { - ERR_FAIL_COND_V(interface == nullptr, 0); return interface->get_playback_position(data_struct); } @@ -302,7 +299,6 @@ void VideoStreamPlaybackGDNative::set_audio_track(int p_idx) { } void VideoStreamPlaybackGDNative::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) { - mix_udata = p_userdata; mix_callback = p_callback; } @@ -334,17 +330,14 @@ Ref<VideoStreamPlayback> VideoStreamGDNative::instance_playback() { } void VideoStreamGDNative::set_file(const String &p_file) { - file = p_file; } String VideoStreamGDNative::get_file() { - return file; } void VideoStreamGDNative::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamGDNative::set_file); ClassDB::bind_method(D_METHOD("get_file"), &VideoStreamGDNative::get_file); @@ -352,7 +345,6 @@ void VideoStreamGDNative::_bind_methods() { } void VideoStreamGDNative::set_audio_track(int p_track) { - audio_track = p_track; } diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.h b/modules/gdnative/videodecoder/video_stream_gdnative.h index f1bae22801..2da63e96d6 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.h +++ b/modules/gdnative/videodecoder/video_stream_gdnative.h @@ -105,7 +105,6 @@ public: }; class VideoStreamPlaybackGDNative : public VideoStreamPlayback { - GDCLASS(VideoStreamPlaybackGDNative, VideoStreamPlayback); Ref<ImageTexture> texture; @@ -175,7 +174,6 @@ public: }; class VideoStreamGDNative : public VideoStream { - GDCLASS(VideoStreamGDNative, VideoStream); String file; diff --git a/modules/gdnative/xr/xr_interface_gdnative.cpp b/modules/gdnative/xr/xr_interface_gdnative.cpp index d65089a123..d03fc33935 100644 --- a/modules/gdnative/xr/xr_interface_gdnative.cpp +++ b/modules/gdnative/xr/xr_interface_gdnative.cpp @@ -80,7 +80,6 @@ void XRInterfaceGDNative::set_interface(const godot_xr_interface_gdnative *p_int } StringName XRInterfaceGDNative::get_name() const { - ERR_FAIL_COND_V(interface == nullptr, StringName()); godot_string result = interface->get_name(data); @@ -103,21 +102,18 @@ int XRInterfaceGDNative::get_capabilities() const { } bool XRInterfaceGDNative::get_anchor_detection_is_enabled() const { - ERR_FAIL_COND_V(interface == nullptr, false); return interface->get_anchor_detection_is_enabled(data); } void XRInterfaceGDNative::set_anchor_detection_is_enabled(bool p_enable) { - ERR_FAIL_COND(interface == nullptr); interface->set_anchor_detection_is_enabled(data, p_enable); } int XRInterfaceGDNative::get_camera_feed_id() { - ERR_FAIL_COND_V(interface == nullptr, 0); return (unsigned int)interface->get_camera_feed_id(data); @@ -134,7 +130,6 @@ bool XRInterfaceGDNative::is_stereo() { } bool XRInterfaceGDNative::is_initialized() const { - ERR_FAIL_COND_V(interface == nullptr, false); return interface->is_initialized(data); @@ -170,7 +165,6 @@ void XRInterfaceGDNative::uninitialize() { } Size2 XRInterfaceGDNative::get_render_targetsize() { - ERR_FAIL_COND_V(interface == nullptr, Size2()); godot_vector2 result = interface->get_render_targetsize(data); @@ -202,14 +196,12 @@ CameraMatrix XRInterfaceGDNative::get_projection_for_eye(XRInterface::Eyes p_eye } unsigned int XRInterfaceGDNative::get_external_texture_for_eye(XRInterface::Eyes p_eye) { - ERR_FAIL_COND_V(interface == nullptr, 0); return (unsigned int)interface->get_external_texture_for_eye(data, (godot_int)p_eye); } void XRInterfaceGDNative::commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) { - ERR_FAIL_COND(interface == nullptr); interface->commit_for_eye(data, (godot_int)p_eye, (godot_rid *)&p_render_target, (godot_rect2 *)&p_screen_rect); diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp index 3792098af4..5aea9f8b9f 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/gdnavigation/gd_navigation_server.cpp @@ -249,7 +249,6 @@ COMMAND_2(region_set_map, RID, p_region, RID, p_map) { ERR_FAIL_COND(region == nullptr); if (region->get_map() != nullptr) { - if (region->get_map()->get_self() == p_map) return; // Pointless diff --git a/modules/gdnavigation/nav_map.cpp b/modules/gdnavigation/nav_map.cpp index d6dd95d6e7..e55a3deb8f 100644 --- a/modules/gdnavigation/nav_map.cpp +++ b/modules/gdnavigation/nav_map.cpp @@ -71,7 +71,6 @@ gd::PointKey NavMap::get_point_key(const Vector3 &p_pos) const { } Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p_optimize) const { - const gd::Polygon *begin_poly = nullptr; const gd::Polygon *end_poly = nullptr; Vector3 begin_point; @@ -85,7 +84,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p // For each point cast a face and check the distance between the origin/destination for (size_t point_id = 2; point_id < p.points.size(); point_id++) { - Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); Vector3 spoint = f.get_closest_point_to(p_origin); float dpoint = spoint.distance_to(p_origin); @@ -111,7 +109,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p } if (begin_poly == end_poly) { - Vector<Vector3> path; path.resize(2); path.write[0] = begin_point; @@ -142,7 +139,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p bool is_reachable = true; while (found_route == false) { - { // Takes the current least_cost_poly neighbors and compute the traveled_distance of each for (size_t i = 0; i < navigation_polys[least_cost_id].poly->edges.size(); i++) { @@ -172,7 +168,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p if (it != navigation_polys.end()) { // Oh this was visited already, can we win the cost? if (it->traveled_distance > new_distance) { - it->prev_navigation_poly_id = least_cost_id; it->back_navigation_edge = edge.other_edge; it->traveled_distance = new_distance; @@ -274,10 +269,8 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p } if (found_route) { - Vector<Vector3> path; if (p_optimize) { - // String pulling gd::NavigationPoly *apex_poly = &navigation_polys[least_cost_id]; @@ -291,7 +284,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p path.push_back(end_point); while (p) { - Vector3 left; Vector3 right; @@ -320,7 +312,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p left_poly = p; portal_left = left; } else { - clip_path(navigation_polys, path, apex_poly, portal_right, right_poly); apex_point = portal_right; @@ -340,7 +331,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p right_poly = p; portal_right = right; } else { - clip_path(navigation_polys, path, apex_poly, portal_left, left_poly); apex_point = portal_left; @@ -371,7 +361,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p // Add mid points int np_id = least_cost_id; while (np_id != -1) { - #ifdef USE_ENTRY_POINT Vector3 point = navigation_polys[np_id].entry; #else @@ -393,7 +382,6 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p } Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const { - bool use_collision = p_use_collision; Vector3 closest_point; real_t closest_point_d = 1e20; @@ -404,7 +392,6 @@ Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector // For each point cast a face and check the distance to the segment for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) { - const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); Vector3 inters; if (f.intersects_segment(p_from, p_to, &inters)) { @@ -414,7 +401,6 @@ Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector use_collision = true; closest_point_d = d; } else if (closest_point_d > d) { - closest_point = inters; closest_point_d = d; } @@ -422,9 +408,7 @@ Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector } if (use_collision == false) { - for (size_t point_id = 0; point_id < p.points.size(); point_id += 1) { - Vector3 a, b; Geometry::get_closest_points_between_segments( @@ -437,7 +421,6 @@ Vector3 NavMap::get_closest_point_to_segment(const Vector3 &p_from, const Vector const real_t d = a.distance_to(b); if (d < closest_point_d) { - closest_point_d = d; closest_point = b; } @@ -460,7 +443,6 @@ Vector3 NavMap::get_closest_point(const Vector3 &p_point) const { // For each point cast a face and check the distance to the point for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) { - const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); const Vector3 inters = f.get_closest_point_to(p_point); const real_t d = inters.distance_to(p_point); @@ -487,7 +469,6 @@ Vector3 NavMap::get_closest_point_normal(const Vector3 &p_point) const { // For each point cast a face and check the distance to the point for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) { - const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); const Vector3 inters = f.get_closest_point_to(p_point); const real_t d = inters.distance_to(p_point); @@ -515,7 +496,6 @@ RID NavMap::get_closest_point_owner(const Vector3 &p_point) const { // For each point cast a face and check the distance to the point for (size_t point_id = 2; point_id < p.points.size(); point_id += 1) { - const Face3 f(p.points[point_id - 2].pos, p.points[point_id - 1].pos, p.points[point_id].pos); const Vector3 inters = f.get_closest_point_to(p_point); const real_t d = inters.distance_to(p_point); @@ -579,7 +559,6 @@ void NavMap::remove_agent_as_controlled(RvoAgent *agent) { } void NavMap::sync() { - if (regenerate_polygons) { for (size_t r(0); r < regions.size(); r++) { regions[r]->scratch_polygons(); @@ -777,7 +756,6 @@ void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys cut_plane.d = cut_plane.normal.dot(from); while (from_poly != p_to_poly) { - int back_nav_edge = from_poly->back_navigation_edge; Vector3 a = from_poly->poly->points[back_nav_edge].pos; Vector3 b = from_poly->poly->points[(back_nav_edge + 1) % from_poly->poly->points.size()].pos; @@ -786,7 +764,6 @@ void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys from_poly = &p_navigation_polys[from_poly->prev_navigation_poly_id]; if (a.distance_to(b) > CMP_EPSILON) { - Vector3 inters; if (cut_plane.intersects_segment(a, b, &inters)) { if (inters.distance_to(p_to_point) > CMP_EPSILON && inters.distance_to(path[path.size() - 1]) > CMP_EPSILON) { diff --git a/modules/gdnavigation/nav_map.h b/modules/gdnavigation/nav_map.h index d39e301511..892755f3f9 100644 --- a/modules/gdnavigation/nav_map.h +++ b/modules/gdnavigation/nav_map.h @@ -46,7 +46,6 @@ class RvoAgent; class NavRegion; class NavMap : public NavRid { - /// Map Up Vector3 up = Vector3(0, 1, 0); diff --git a/modules/gdnavigation/nav_region.cpp b/modules/gdnavigation/nav_region.cpp index 2bd42ba980..3dff19cd65 100644 --- a/modules/gdnavigation/nav_region.cpp +++ b/modules/gdnavigation/nav_region.cpp @@ -84,7 +84,6 @@ void NavRegion::update_polygons() { // Build for (size_t i(0); i < polygons.size(); i++) { - gd::Polygon &p = polygons[i]; p.owner = this; @@ -98,7 +97,6 @@ void NavRegion::update_polygons() { float sum(0); for (int j(0); j < mesh_poly.size(); j++) { - int idx = indices[j]; if (idx < 0 || idx >= len) { valid = false; diff --git a/modules/gdnavigation/nav_utils.h b/modules/gdnavigation/nav_utils.h index 388e53a66a..40e54df553 100644 --- a/modules/gdnavigation/nav_utils.h +++ b/modules/gdnavigation/nav_utils.h @@ -45,7 +45,6 @@ namespace gd { struct Polygon; union PointKey { - struct { int64_t x : 21; int64_t y : 22; @@ -57,7 +56,6 @@ union PointKey { }; struct EdgeKey { - PointKey a; PointKey b; @@ -109,7 +107,6 @@ struct Polygon { }; struct Connection { - Polygon *A = nullptr; int A_edge = -1; Polygon *B = nullptr; diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp index abaf73ba6a..379131864e 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp +++ b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp @@ -38,7 +38,6 @@ #include "scene/gui/box_container.h" void NavigationMeshEditor::_node_removed(Node *p_node) { - if (p_node == node) { node = nullptr; @@ -47,9 +46,7 @@ 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")); } @@ -72,7 +69,6 @@ void NavigationMeshEditor::_bake_pressed() { } void NavigationMeshEditor::_clear_pressed() { - if (node) NavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh()); @@ -85,7 +81,6 @@ void NavigationMeshEditor::_clear_pressed() { } void NavigationMeshEditor::edit(NavigationRegion3D *p_nav_region) { - if (p_nav_region == nullptr || node == p_nav_region) { return; } @@ -97,7 +92,6 @@ void NavigationMeshEditor::_bind_methods() { } NavigationMeshEditor::NavigationMeshEditor() { - bake_hbox = memnew(HBoxContainer); button_bake = memnew(ToolButton); @@ -124,22 +118,18 @@ NavigationMeshEditor::~NavigationMeshEditor() { } void NavigationMeshEditorPlugin::edit(Object *p_object) { - navigation_mesh_editor->edit(Object::cast_to<NavigationRegion3D>(p_object)); } bool NavigationMeshEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("NavigationRegion3D"); } void NavigationMeshEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { navigation_mesh_editor->show(); navigation_mesh_editor->bake_hbox->show(); } else { - navigation_mesh_editor->hide(); navigation_mesh_editor->bake_hbox->hide(); navigation_mesh_editor->edit(nullptr); @@ -147,7 +137,6 @@ void NavigationMeshEditorPlugin::make_visible(bool p_visible) { } NavigationMeshEditorPlugin::NavigationMeshEditorPlugin(EditorNode *p_node) { - editor = p_node; navigation_mesh_editor = memnew(NavigationMeshEditor); editor->get_viewport()->add_child(navigation_mesh_editor); diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.h b/modules/gdnavigation/navigation_mesh_editor_plugin.h index 434981c9e0..da3a981f8c 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.h +++ b/modules/gdnavigation/navigation_mesh_editor_plugin.h @@ -67,7 +67,6 @@ public: }; class NavigationMeshEditorPlugin : public EditorPlugin { - GDCLASS(NavigationMeshEditorPlugin, EditorPlugin); NavigationMeshEditor *navigation_mesh_editor; diff --git a/modules/gdnavigation/navigation_mesh_generator.cpp b/modules/gdnavigation/navigation_mesh_generator.cpp index acb4f0461f..78818fd990 100644 --- a/modules/gdnavigation/navigation_mesh_generator.cpp +++ b/modules/gdnavigation/navigation_mesh_generator.cpp @@ -94,7 +94,6 @@ void NavigationMeshGenerator::_add_mesh(const Ref<Mesh> &p_mesh, const Transform const Vector3 *vr = mesh_vertices.ptr(); if (p_mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_INDEX) { - Vector<int> mesh_indices = a[Mesh::ARRAY_INDEX]; const int *ir = mesh_indices.ptr(); @@ -139,9 +138,7 @@ void NavigationMeshGenerator::_add_faces(const PackedVector3Array &p_faces, cons } void NavigationMeshGenerator::_parse_geometry(Transform p_accumulated_transform, Node *p_node, Vector<float> &p_verticies, Vector<int> &p_indices, int p_generate_from, uint32_t p_collision_mask, bool p_recurse_children) { - if (Object::cast_to<MeshInstance3D>(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { - MeshInstance3D *mesh_instance = Object::cast_to<MeshInstance3D>(p_node); Ref<Mesh> mesh = mesh_instance->get_mesh(); if (mesh.is_valid()) { @@ -151,7 +148,6 @@ void NavigationMeshGenerator::_parse_geometry(Transform p_accumulated_transform, #ifdef MODULE_CSG_ENABLED if (Object::cast_to<CSGShape3D>(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { - CSGShape3D *csg_shape = Object::cast_to<CSGShape3D>(p_node); Array meshes = csg_shape->get_meshes(); if (!meshes.empty()) { @@ -167,7 +163,6 @@ void NavigationMeshGenerator::_parse_geometry(Transform p_accumulated_transform, StaticBody3D *static_body = Object::cast_to<StaticBody3D>(p_node); if (static_body->get_collision_layer() & p_collision_mask) { - for (int i = 0; i < p_node->get_child_count(); ++i) { Node *child = p_node->get_child(i); if (Object::cast_to<CollisionShape3D>(child)) { @@ -278,7 +273,6 @@ void NavigationMeshGenerator::_parse_geometry(Transform p_accumulated_transform, } void NavigationMeshGenerator::_convert_detail_mesh_to_native_navigation_mesh(const rcPolyMeshDetail *p_detail_mesh, Ref<NavigationMesh> p_nav_mesh) { - Vector<Vector3> nav_vertices; for (int i = 0; i < p_detail_mesh->nverts; i++) { @@ -481,7 +475,6 @@ NavigationMeshGenerator::~NavigationMeshGenerator() { } void NavigationMeshGenerator::bake(Ref<NavigationMesh> p_nav_mesh, Node *p_node) { - ERR_FAIL_COND(!p_nav_mesh.is_valid()); #ifdef TOOLS_ENABLED @@ -514,7 +507,6 @@ void NavigationMeshGenerator::bake(Ref<NavigationMesh> p_nav_mesh, Node *p_node) } if (vertices.size() > 0 && indices.size() > 0) { - rcHeightfield *hf = nullptr; rcCompactHeightfield *chf = nullptr; rcContourSet *cset = nullptr; diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index 0aca4dbc5e..c3091a56a6 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -34,17 +34,14 @@ #include "scene/gui/text_edit.h" inline bool _is_symbol(CharType c) { - return is_symbol(c); } static bool _is_text_char(CharType c) { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } static bool _is_char(CharType c) { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; } @@ -180,7 +177,6 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ } if (in_region == -1 && !in_keyword && is_char && !prev_is_char) { - int to = j; while (to < str.length() && _is_text_char(str[to])) to++; @@ -208,7 +204,6 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ } if (!in_function_name && in_word && !in_keyword) { - int k = j; while (k < str.length() && !_is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') { k++; @@ -238,7 +233,6 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ } if (is_symbol) { - if (in_function_name) { in_function_args = true; } diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 8559fac57c..d42fdb1e04 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -44,12 +44,10 @@ /////////////////////////// GDScriptNativeClass::GDScriptNativeClass(const StringName &p_name) { - name = p_name; } bool GDScriptNativeClass::_get(const StringName &p_name, Variant &r_ret) const { - bool ok; int v = ClassDB::get_integer_constant(name, p_name, &ok); @@ -62,12 +60,10 @@ bool GDScriptNativeClass::_get(const StringName &p_name, Variant &r_ret) const { } void GDScriptNativeClass::_bind_methods() { - ClassDB::bind_method(D_METHOD("new"), &GDScriptNativeClass::_new); } Variant GDScriptNativeClass::_new() { - Object *o = instance(); ERR_FAIL_COND_V_MSG(!o, Variant(), "Class type: '" + String(name) + "' is not instantiable."); @@ -80,12 +76,10 @@ Variant GDScriptNativeClass::_new() { } Object *GDScriptNativeClass::instance() { - return ClassDB::instance(name); } GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Callable::CallError &r_error) { - /* STEP 1, CREATE */ GDScriptInstance *instance = memnew(GDScriptInstance); @@ -125,7 +119,6 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco } Variant GDScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - /* STEP 1, CREATE */ if (!valid) { @@ -171,7 +164,6 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Callable::CallErr } bool GDScript::can_instance() const { - #ifdef TOOLS_ENABLED return valid && (tool || ScriptServer::is_scripting_enabled()); #else @@ -180,7 +172,6 @@ bool GDScript::can_instance() const { } Ref<Script> GDScript::get_base_script() const { - if (_base) { return Ref<GDScript>(_base); } else { @@ -189,7 +180,6 @@ Ref<Script> GDScript::get_base_script() const { } StringName GDScript::get_instance_base_type() const { - if (native.is_valid()) return native->get_name(); if (base.is_valid() && base->is_valid()) @@ -198,7 +188,6 @@ StringName GDScript::get_instance_base_type() const { } struct _GDScriptMemberSort { - int index; StringName name; _FORCE_INLINE_ bool operator<(const _GDScriptMemberSort &p_member) const { return index < p_member.index; } @@ -207,13 +196,11 @@ struct _GDScriptMemberSort { #ifdef TOOLS_ENABLED void GDScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { - placeholders.erase(p_placeholder); } #endif void GDScript::get_script_method_list(List<MethodInfo> *p_list) const { - const GDScript *current = this; while (current) { for (const Map<StringName, GDScriptFunction *>::Element *E = current->member_functions.front(); E; E = E->next()) { @@ -233,15 +220,12 @@ void GDScript::get_script_method_list(List<MethodInfo> *p_list) const { } void GDScript::get_script_property_list(List<PropertyInfo> *p_list) const { - const GDScript *sptr = this; List<PropertyInfo> props; while (sptr) { - Vector<_GDScriptMemberSort> msort; for (Map<StringName, PropertyInfo>::Element *E = sptr->member_info.front(); E; E = E->next()) { - _GDScriptMemberSort ms; ERR_CONTINUE(!sptr->member_indices.has(E->key())); ms.index = sptr->member_indices[E->key()].index; @@ -252,7 +236,6 @@ void GDScript::get_script_property_list(List<PropertyInfo> *p_list) const { msort.sort(); msort.invert(); for (int i = 0; i < msort.size(); i++) { - props.push_front(sptr->member_info[msort[i].name]); } @@ -265,12 +248,10 @@ void GDScript::get_script_property_list(List<PropertyInfo> *p_list) const { } bool GDScript::has_method(const StringName &p_method) const { - return member_functions.has(p_method); } MethodInfo GDScript::get_method_info(const StringName &p_method) const { - const Map<StringName, GDScriptFunction *>::Element *E = member_functions.find(p_method); if (!E) return MethodInfo(); @@ -287,7 +268,6 @@ MethodInfo GDScript::get_method_info(const StringName &p_method) const { } bool GDScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { - #ifdef TOOLS_ENABLED const Map<StringName, Variant>::Element *E = member_default_values_cache.find(p_property); @@ -304,14 +284,12 @@ bool GDScript::get_property_default_value(const StringName &p_property, Variant } ScriptInstance *GDScript::instance_create(Object *p_this) { - GDScript *top = this; while (top->_base) top = top->_base; if (top->native.is_valid()) { if (!ClassDB::is_parent_class(p_this->get_class_name(), top->native->get_name())) { - if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), 1, "Script inherits from native type '" + String(top->native->get_name()) + "', so it can't be instanced in object of type: '" + p_this->get_class() + "'"); } @@ -335,22 +313,18 @@ PlaceHolderScriptInstance *GDScript::placeholder_instance_create(Object *p_this) } bool GDScript::instance_has(const Object *p_this) const { - MutexLock lock(GDScriptLanguage::singleton->lock); return instances.has((Object *)p_this); } bool GDScript::has_source_code() const { - return source != ""; } String GDScript::get_source_code() const { - return source; } void GDScript::set_source_code(const String &p_code) { - if (source == p_code) return; source = p_code; @@ -361,7 +335,6 @@ void GDScript::set_source_code(const String &p_code) { #ifdef TOOLS_ENABLED void GDScript::_update_exports_values(Map<StringName, Variant> &values, List<PropertyInfo> &propnames) { - if (base_cache.is_valid()) { base_cache->_update_exports_values(values, propnames); } @@ -377,7 +350,6 @@ void GDScript::_update_exports_values(Map<StringName, Variant> &values, List<Pro #endif bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { - #ifdef TOOLS_ENABLED static Vector<GDScript *> base_caches; @@ -403,7 +375,6 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { Error err = parser.parse(source, basedir, true, path); if (err == OK) { - const GDScriptParser::Node *root = parser.get_parse_tree(); ERR_FAIL_COND_V(root->type != GDScriptParser::Node::TYPE_CLASS, false); @@ -419,10 +390,8 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { if (String(c->extends_file) != "" && String(c->extends_file) != get_path()) { path = c->extends_file; if (path.is_rel_path()) { - String base = get_path(); if (base == "" || base.is_rel_path()) { - ERR_PRINT(("Could not resolve relative path for parent class: " + path).utf8().get_data()); } else { path = base.get_base_dir().plus_file(path); @@ -437,11 +406,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { if (path != "") { if (path != get_path()) { - Ref<GDScript> bf = ResourceLoader::load(path); if (bf.is_valid()) { - base_cache = bf; bf->inheriters_cache.insert(get_instance_id()); } @@ -518,7 +485,6 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { } void GDScript::update_exports() { - #ifdef TOOLS_ENABLED bool cyclic_error = false; @@ -540,16 +506,13 @@ void GDScript::update_exports() { } void GDScript::_set_subclass_path(Ref<GDScript> &p_sc, const String &p_path) { - p_sc->path = p_path; for (Map<StringName, Ref<GDScript>>::Element *E = p_sc->subclasses.front(); E; E = E->next()) { - _set_subclass_path(E->get(), p_path); } } Error GDScript::reload(bool p_keep_state) { - bool has_instances; { MutexLock lock(GDScriptLanguage::singleton->lock); @@ -589,7 +552,6 @@ Error GDScript::reload(bool p_keep_state) { err = compiler.compile(&parser, this, p_keep_state); if (err) { - if (can_run) { if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->debug_break_parse(get_path(), compiler.get_error_line(), "Parser Error: " + compiler.get_error()); @@ -613,7 +575,6 @@ Error GDScript::reload(bool p_keep_state) { valid = true; for (Map<StringName, Ref<GDScript>>::Element *E = subclasses.front(); E; E = E->next()) { - _set_subclass_path(E->get(), path); } @@ -623,12 +584,10 @@ Error GDScript::reload(bool p_keep_state) { } ScriptLanguage *GDScript::get_language() const { - return GDScriptLanguage::get_singleton(); } void GDScript::get_constants(Map<StringName, Variant> *p_constants) { - if (p_constants) { for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) { (*p_constants)[E->key()] = E->value(); @@ -703,13 +662,10 @@ MultiplayerAPI::RPCMode GDScript::get_rset_mode(const StringName &p_variable) co } Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - GDScript *top = this; while (top) { - Map<StringName, GDScriptFunction *>::Element *E = top->member_functions.find(p_method); if (E) { - ERR_FAIL_COND_V_MSG(!E->get()->is_static(), Variant(), "Can't call non-static function '" + String(p_method) + "' in script."); return E->get()->call(nullptr, p_args, p_argcount, r_error); @@ -723,16 +679,12 @@ Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p } bool GDScript::_get(const StringName &p_name, Variant &r_ret) const { - { - const GDScript *top = this; while (top) { - { const Map<StringName, Variant>::Element *E = top->constants.find(p_name); if (E) { - r_ret = E->get(); return true; } @@ -741,7 +693,6 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const { { const Map<StringName, Ref<GDScript>>::Element *E = subclasses.find(p_name); if (E) { - r_ret = E->get(); return true; } @@ -750,7 +701,6 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const { } if (p_name == GDScriptLanguage::get_singleton()->strings._script_source) { - r_ret = get_source_code(); return true; } @@ -759,9 +709,7 @@ bool GDScript::_get(const StringName &p_name, Variant &r_ret) const { return false; } bool GDScript::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == GDScriptLanguage::get_singleton()->strings._script_source) { - set_source_code(p_value); reload(); } else @@ -771,29 +719,24 @@ bool GDScript::_set(const StringName &p_name, const Variant &p_value) { } void GDScript::_get_property_list(List<PropertyInfo> *p_properties) const { - p_properties->push_back(PropertyInfo(Variant::STRING, "script/source", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); } void GDScript::_bind_methods() { - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &GDScript::_new, MethodInfo("new")); ClassDB::bind_method(D_METHOD("get_as_byte_code"), &GDScript::get_as_byte_code); } Vector<uint8_t> GDScript::get_as_byte_code() const { - GDScriptTokenizerBuffer tokenizer; return tokenizer.parse_code_string(source); }; Error GDScript::load_byte_code(const String &p_path) { - Vector<uint8_t> bytecode; if (p_path.ends_with("gde")) { - FileAccess *fa = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_V(!fa, ERR_CANT_OPEN); @@ -822,7 +765,6 @@ Error GDScript::load_byte_code(const String &p_path) { memdelete(fae); } else { - bytecode = FileAccess::get_file_as_array(p_path); } @@ -856,7 +798,6 @@ Error GDScript::load_byte_code(const String &p_path) { valid = true; for (Map<StringName, Ref<GDScript>>::Element *E = subclasses.front(); E; E = E->next()) { - _set_subclass_path(E->get(), path); } @@ -866,12 +807,10 @@ Error GDScript::load_byte_code(const String &p_path) { } Error GDScript::load_source_code(const String &p_path) { - Vector<uint8_t> sourcef; Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); if (err) { - ERR_FAIL_COND_V(err, err); } @@ -886,7 +825,6 @@ Error GDScript::load_source_code(const String &p_path) { String s; if (s.parse_utf8((const char *)w)) { - ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Script '" + p_path + "' contains invalid unicode (UTF-8), so it was not loaded. Please ensure that scripts are saved in valid UTF-8 unicode."); } @@ -899,14 +837,11 @@ Error GDScript::load_source_code(const String &p_path) { } const Map<StringName, GDScriptFunction *> &GDScript::debug_get_member_functions() const { - return member_functions; } StringName GDScript::debug_get_member_by_index(int p_idx) const { - for (const Map<StringName, MemberInfo>::Element *E = member_indices.front(); E; E = E->next()) { - if (E->get().index == p_idx) return E->key(); } @@ -915,7 +850,6 @@ StringName GDScript::debug_get_member_by_index(int p_idx) const { } Ref<GDScript> GDScript::get_base() const { - return base; } @@ -951,9 +885,7 @@ bool GDScript::has_script_signal(const StringName &p_signal) const { return false; } void GDScript::get_script_signal_list(List<MethodInfo> *r_signals) const { - for (const Map<StringName, Vector<StringName>>::Element *E = _signals.front(); E; E = E->next()) { - MethodInfo mi; mi.name = E->key(); for (int i = 0; i < E->get().size(); i++) { @@ -977,7 +909,6 @@ void GDScript::get_script_signal_list(List<MethodInfo> *r_signals) const { GDScript::GDScript() : script_list(this) { - valid = false; subclass_count = 0; initializer = nullptr; @@ -1079,7 +1010,6 @@ void GDScript::_init_rpc_methods_properties() { } GDScript::~GDScript() { - { MutexLock lock(GDScriptLanguage::get_singleton()->lock); @@ -1109,7 +1039,6 @@ GDScript::~GDScript() { ////////////////////////////// bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { - //member { const Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.find(p_name); @@ -1144,10 +1073,8 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { GDScript *sptr = script.ptr(); while (sptr) { - Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set); if (E) { - Variant name = p_name; const Variant *args[2] = { &name, &p_value }; @@ -1163,10 +1090,8 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { } bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { - const GDScript *sptr = script.ptr(); while (sptr) { - { const Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.find(p_name); if (E) { @@ -1183,7 +1108,6 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { } { - const GDScript *sl = sptr; while (sl) { const Map<StringName, Variant>::Element *E = sl->constants.find(p_name); @@ -1198,7 +1122,6 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { { const Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get); if (E) { - Variant name = p_name; const Variant *args[1] = { &name }; @@ -1217,10 +1140,8 @@ bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { } Variant::Type GDScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { - const GDScript *sptr = script.ptr(); while (sptr) { - if (sptr->member_info.has(p_name)) { if (r_is_valid) *r_is_valid = true; @@ -1241,19 +1162,15 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const List<PropertyInfo> props; while (sptr) { - const Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list); if (E) { - Callable::CallError err; Variant ret = const_cast<GDScriptFunction *>(E->get())->call(const_cast<GDScriptInstance *>(this), nullptr, 0, err); if (err.error == Callable::CallError::CALL_OK) { - ERR_FAIL_COND_MSG(ret.get_type() != Variant::ARRAY, "Wrong type for _get_property_list, must be an array of dictionaries."); Array arr = ret; for (int i = 0; i < arr.size(); i++) { - Dictionary d = arr[i]; ERR_CONTINUE(!d.has("name")); ERR_CONTINUE(!d.has("type")); @@ -1278,7 +1195,6 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const Vector<_GDScriptMemberSort> msort; for (Map<StringName, PropertyInfo>::Element *F = sptr->member_info.front(); F; F = F->next()) { - _GDScriptMemberSort ms; ERR_CONTINUE(!sptr->member_indices.has(F->key())); ms.index = sptr->member_indices[F->key()].index; @@ -1289,7 +1205,6 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const msort.sort(); msort.invert(); for (int i = 0; i < msort.size(); i++) { - props.push_front(sptr->member_info[msort[i].name]); } @@ -1297,18 +1212,14 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const } for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - p_properties->push_back(E->get()); } } void GDScriptInstance::get_method_list(List<MethodInfo> *p_list) const { - const GDScript *sptr = script.ptr(); while (sptr) { - for (Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.front(); E; E = E->next()) { - MethodInfo mi; mi.name = E->key(); mi.flags |= METHOD_FLAG_FROM_SCRIPT; @@ -1321,7 +1232,6 @@ void GDScriptInstance::get_method_list(List<MethodInfo> *p_list) const { } bool GDScriptInstance::has_method(const StringName &p_method) const { - const GDScript *sptr = script.ptr(); while (sptr) { const Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(p_method); @@ -1333,7 +1243,6 @@ bool GDScriptInstance::has_method(const StringName &p_method) const { return false; } Variant GDScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - GDScript *sptr = script.ptr(); while (sptr) { Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(p_method); @@ -1347,7 +1256,6 @@ Variant GDScriptInstance::call(const StringName &p_method, const Variant **p_arg } void GDScriptInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { - GDScript *sptr = script.ptr(); Callable::CallError ce; @@ -1361,7 +1269,6 @@ void GDScriptInstance::call_multilevel(const StringName &p_method, const Variant } void GDScriptInstance::_ml_call_reversed(GDScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount) { - if (sptr->_base) _ml_call_reversed(sptr->_base, p_method, p_args, p_argcount); @@ -1374,14 +1281,12 @@ void GDScriptInstance::_ml_call_reversed(GDScript *sptr, const StringName &p_met } void GDScriptInstance::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { - if (script.ptr()) { _ml_call_reversed(script.ptr(), p_method, p_args, p_argcount); } } void GDScriptInstance::notification(int p_notification) { - //notification is not virtual, it gets called at ALL levels just like in C. Variant value = p_notification; const Variant *args[1] = { &value }; @@ -1421,12 +1326,10 @@ String GDScriptInstance::to_string(bool *r_valid) { } Ref<Script> GDScriptInstance::get_script() const { - return script; } ScriptLanguage *GDScriptInstance::get_language() { - return GDScriptLanguage::get_singleton(); } @@ -1471,7 +1374,6 @@ MultiplayerAPI::RPCMode GDScriptInstance::get_rset_mode(const StringName &p_vari } void GDScriptInstance::reload_members() { - #ifdef DEBUG_ENABLED members.resize(script->member_indices.size()); //resize @@ -1481,7 +1383,6 @@ void GDScriptInstance::reload_members() { //pass the values to the new indices for (Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.front(); E; E = E->next()) { - if (member_indices_cache.has(E->key())) { Variant value = members[member_indices_cache[E->key()]]; new_members.write[E->get().index] = value; @@ -1494,7 +1395,6 @@ void GDScriptInstance::reload_members() { //pass the values to the new indices member_indices_cache.clear(); for (Map<StringName, GDScript::MemberInfo>::Element *E = script->member_indices.front(); E; E = E->next()) { - member_indices_cache[E->key()] = E->get().index; } @@ -1507,7 +1407,6 @@ GDScriptInstance::GDScriptInstance() { } GDScriptInstance::~GDScriptInstance() { - MutexLock lock(GDScriptLanguage::get_singleton()->lock); while (SelfList<GDScriptFunctionState> *E = pending_func_states.first()) { @@ -1525,14 +1424,12 @@ GDScriptInstance::~GDScriptInstance() { GDScriptLanguage *GDScriptLanguage::singleton = nullptr; String GDScriptLanguage::get_name() const { - return "GDScript"; } /* LANGUAGE FUNCTIONS */ void GDScriptLanguage::_add_global(const StringName &p_name, const Variant &p_value) { - if (globals.has(p_name)) { //overwrite existing global_array.write[globals[p_name]] = p_value; @@ -1544,7 +1441,6 @@ void GDScriptLanguage::_add_global(const StringName &p_name, const Variant &p_va } void GDScriptLanguage::add_global_constant(const StringName &p_variable, const Variant &p_value) { - _add_global(p_variable, p_value); } @@ -1558,11 +1454,9 @@ void GDScriptLanguage::remove_named_global_constant(const StringName &p_name) { } void GDScriptLanguage::init() { - //populate global constants int gcc = GlobalConstants::get_global_constant_count(); for (int i = 0; i < gcc; i++) { - _add_global(StaticCString::create(GlobalConstants::get_global_constant_name(i)), GlobalConstants::get_global_constant_value(i)); } @@ -1576,7 +1470,6 @@ void GDScriptLanguage::init() { List<StringName> class_list; ClassDB::get_class_list(&class_list); for (List<StringName>::Element *E = class_list.front(); E; E = E->next()) { - StringName n = E->get(); String s = String(n); if (s.begins_with("_")) @@ -1593,21 +1486,17 @@ void GDScriptLanguage::init() { List<Engine::Singleton> singletons; Engine::get_singleton()->get_singletons(&singletons); for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { - _add_global(E->get().name, E->get().ptr); } } String GDScriptLanguage::get_type() const { - return "GDScript"; } String GDScriptLanguage::get_extension() const { - return "gd"; } Error GDScriptLanguage::execute_file(const String &p_path) { - // ?? return OK; } @@ -1615,7 +1504,6 @@ void GDScriptLanguage::finish() { } void GDScriptLanguage::profiling_start() { - #ifdef DEBUG_ENABLED MutexLock lock(this->lock); @@ -1638,7 +1526,6 @@ void GDScriptLanguage::profiling_start() { } void GDScriptLanguage::profiling_stop() { - #ifdef DEBUG_ENABLED MutexLock lock(this->lock); @@ -1647,7 +1534,6 @@ void GDScriptLanguage::profiling_stop() { } int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { - int current = 0; #ifdef DEBUG_ENABLED @@ -1670,7 +1556,6 @@ int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, } int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { - int current = 0; #ifdef DEBUG_ENABLED @@ -1695,10 +1580,8 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_ } struct GDScriptDepSort { - //must support sorting so inheritance works properly (parent must be reloaded first) bool operator()(const Ref<GDScript> &A, const Ref<GDScript> &B) const { - if (A == B) return false; //shouldn't happen but.. const GDScript *I = B->get_base().ptr(); @@ -1716,7 +1599,6 @@ struct GDScriptDepSort { }; void GDScriptLanguage::reload_all_scripts() { - #ifdef DEBUG_ENABLED print_verbose("GDScript: Reloading all scripts"); List<Ref<GDScript>> scripts; @@ -1738,7 +1620,6 @@ void GDScriptLanguage::reload_all_scripts() { scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order for (List<Ref<GDScript>>::Element *E = scripts.front(); E; E = E->next()) { - print_verbose("GDScript: Reloading: " + E->get()->get_path()); E->get()->load_source_code(E->get()->get_path()); E->get()->reload(true); @@ -1747,7 +1628,6 @@ void GDScriptLanguage::reload_all_scripts() { } void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { - #ifdef DEBUG_ENABLED List<Ref<GDScript>> scripts; @@ -1757,7 +1637,6 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so SelfList<GDScript> *elem = script_list.first(); while (elem) { if (elem->self()->get_path().is_resource_file()) { - scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident } elem = elem->next(); @@ -1773,7 +1652,6 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so scripts.sort_custom<GDScriptDepSort>(); //update in inheritance dependency order for (List<Ref<GDScript>>::Element *E = scripts.front(); E; E = E->next()) { - bool reload = E->get() == p_script || to_reload.has(E->get()->get_base()); if (!reload) @@ -1782,7 +1660,6 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so to_reload.insert(E->get(), Map<ObjectID, List<Pair<StringName, Variant>>>()); if (!p_soft_reload) { - //save state and remove script from instances Map<ObjectID, List<Pair<StringName, Variant>>> &map = to_reload[E->get()]; @@ -1791,7 +1668,6 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so //save instance info List<Pair<StringName, Variant>> state; if (obj->get_script_instance()) { - obj->get_script_instance()->get_property_state(state); map[obj->get_instance_id()] = state; obj->set_script(Variant()); @@ -1806,7 +1682,6 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so //save instance info if (obj->get_script_instance()) { - map.insert(obj->get_instance_id(), List<Pair<StringName, Variant>>()); List<Pair<StringName, Variant>> &state = map[obj->get_instance_id()]; obj->get_script_instance()->get_property_state(state); @@ -1826,13 +1701,11 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so } for (Map<Ref<GDScript>, Map<ObjectID, List<Pair<StringName, Variant>>>>::Element *E = to_reload.front(); E; E = E->next()) { - Ref<GDScript> scr = E->key(); scr->reload(p_soft_reload); //restore state if saved for (Map<ObjectID, List<Pair<StringName, Variant>>>::Element *F = E->get().front(); F; F = F->next()) { - List<Pair<StringName, Variant>> &saved_state = F->get(); Object *obj = ObjectDB::get_instance(F->key()); @@ -1876,7 +1749,6 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so } void GDScriptLanguage::frame() { - calls = 0; #ifdef DEBUG_ENABLED @@ -1900,7 +1772,6 @@ void GDScriptLanguage::frame() { /* EDITOR FUNCTIONS */ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { - static const char *_reserved_words[] = { // operators "and", @@ -1964,7 +1835,6 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { const char **w = _reserved_words; while (*w) { - p_words->push_back(*w); w++; } @@ -1975,12 +1845,10 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { } bool GDScriptLanguage::handles_global_class_type(const String &p_type) const { - return p_type == "GDScript"; } String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_base_type, String *r_icon_path) const { - Vector<uint8_t> sourcef; Error err; FileAccessRef f = FileAccess::open(p_path, FileAccess::READ, &err); @@ -1994,7 +1862,6 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b parser.parse(source, p_path.get_base_dir(), true, p_path, false, nullptr, true); if (parser.get_parse_tree() && parser.get_parse_tree()->type == GDScriptParser::Node::TYPE_CLASS) { - const GDScriptParser::ClassNode *c = static_cast<const GDScriptParser::ClassNode *>(parser.get_parse_tree()); if (r_icon_path) { if (c->icon_path.empty() || c->icon_path.is_abs_path()) @@ -2003,7 +1870,6 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b *r_icon_path = p_path.get_base_dir().plus_file(c->icon_path).simplify_path(); } if (r_base_type) { - const GDScriptParser::ClassNode *subclass = c; String path = p_path; GDScriptParser subparser; @@ -2077,7 +1943,6 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b #ifdef DEBUG_ENABLED String GDScriptWarning::get_message() const { - #define CHECK_SYMBOLS(m_amount) ERR_FAIL_COND_V(symbols.size() < m_amount, String()); switch (code) { @@ -2246,7 +2111,6 @@ GDScriptWarning::Code GDScriptWarning::get_code_from_name(const String &p_name) #endif // DEBUG_ENABLED GDScriptLanguage::GDScriptLanguage() { - calls = 0; ERR_FAIL_COND(singleton); singleton = this; @@ -2291,7 +2155,6 @@ GDScriptLanguage::GDScriptLanguage() { } GDScriptLanguage::~GDScriptLanguage() { - if (_call_stack) { memdelete_arr(_call_stack); } @@ -2317,7 +2180,6 @@ Ref<GDScript> GDScriptLanguage::get_orphan_subclass(const String &p_qualified_na /*************** RESOURCE ***************/ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_FILE_CANT_OPEN; @@ -2326,7 +2188,6 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori Ref<GDScript> scriptres(script); if (p_path.ends_with(".gde") || p_path.ends_with(".gdc")) { - script->set_script_path(p_original_path); // script needs this. script->set_path(p_original_path); Error err = script->load_byte_code(p_path); @@ -2348,19 +2209,16 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori } void ResourceFormatLoaderGDScript::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("gd"); p_extensions->push_back("gdc"); p_extensions->push_back("gde"); } bool ResourceFormatLoaderGDScript::handles_type(const String &p_type) const { - return (p_type == "Script" || p_type == "GDScript"); } String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "gd" || el == "gdc" || el == "gde") return "GDScript"; @@ -2368,7 +2226,6 @@ String ResourceFormatLoaderGDScript::get_resource_type(const String &p_path) con } void ResourceFormatLoaderGDScript::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) { - FileAccessRef file = FileAccess::open(p_path, FileAccess::READ); ERR_FAIL_COND_MSG(!file, "Cannot open file '" + p_path + "'."); @@ -2388,7 +2245,6 @@ void ResourceFormatLoaderGDScript::get_dependencies(const String &p_path, List<S } Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Ref<GDScript> sqscr = p_resource; ERR_FAIL_COND_V(sqscr.is_null(), ERR_INVALID_PARAMETER); @@ -2415,12 +2271,10 @@ Error ResourceFormatSaverGDScript::save(const String &p_path, const RES &p_resou } void ResourceFormatSaverGDScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (Object::cast_to<GDScript>(*p_resource)) { p_extensions->push_back("gd"); } } bool ResourceFormatSaverGDScript::recognize(const RES &p_resource) const { - return Object::cast_to<GDScript>(*p_resource) != nullptr; } diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 3cba621578..ecaa2257ca 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -39,7 +39,6 @@ #include "gdscript_function.h" class GDScriptNativeClass : public Reference { - GDCLASS(GDScriptNativeClass, Reference); StringName name; @@ -56,7 +55,6 @@ public: }; class GDScript : public Script { - GDCLASS(GDScript, Script); bool tool; bool valid; @@ -350,7 +348,6 @@ struct GDScriptWarning { #endif // DEBUG_ENABLED class GDScriptLanguage : public ScriptLanguage { - friend class GDScriptFunctionState; static GDScriptLanguage *singleton; @@ -361,7 +358,6 @@ class GDScriptLanguage : public ScriptLanguage { Map<StringName, Variant> named_globals; struct CallLevel { - Variant *stack; GDScriptFunction *function; GDScriptInstance *instance; @@ -400,7 +396,6 @@ public: bool debug_break_parse(const String &p_file, int p_line, const String &p_error); _FORCE_INLINE_ void enter_function(GDScriptInstance *p_instance, GDScriptFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) { - if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now @@ -423,7 +418,6 @@ public: } _FORCE_INLINE_ void exit_function() { - if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now @@ -431,7 +425,6 @@ public: EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1); if (_debug_call_stack_pos == 0) { - _debug_error = "Stack Underflow (Engine Bug)"; EngineDebugger::get_script_debugger()->debug(this); return; @@ -457,7 +450,6 @@ public: } struct { - StringName _init; StringName _notification; StringName _set; diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 473b6fab05..c227d4098c 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -33,7 +33,6 @@ #include "gdscript.h" bool GDScriptCompiler::_is_class_member_property(CodeGen &codegen, const StringName &p_name) { - if (codegen.function_node && codegen.function_node->_static) return false; @@ -44,11 +43,9 @@ bool GDScriptCompiler::_is_class_member_property(CodeGen &codegen, const StringN } bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringName &p_name) { - GDScript *scr = owner; GDScriptNativeClass *nc = nullptr; while (scr) { - if (scr->native.is_valid()) nc = scr->native.ptr(); scr = scr->_base; @@ -60,7 +57,6 @@ bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringNa } void GDScriptCompiler::_set_error(const String &p_error, const GDScriptParser::Node *p_node) { - if (error != "") return; @@ -75,7 +71,6 @@ void GDScriptCompiler::_set_error(const String &p_error, const GDScriptParser::N } bool GDScriptCompiler::_create_unary_operator(CodeGen &codegen, const GDScriptParser::OperatorNode *on, Variant::Operator op, int p_stack_level) { - ERR_FAIL_COND_V(on->arguments.size() != 1, false); int src_address_a = _parse_expression(codegen, on->arguments[0], p_stack_level); @@ -91,7 +86,6 @@ bool GDScriptCompiler::_create_unary_operator(CodeGen &codegen, const GDScriptPa } bool GDScriptCompiler::_create_binary_operator(CodeGen &codegen, const GDScriptParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer, int p_index_addr) { - ERR_FAIL_COND_V(on->arguments.size() != 2, false); int src_address_a = _parse_expression(codegen, on->arguments[0], p_stack_level, false, p_initializer, p_index_addr); @@ -172,11 +166,9 @@ GDScriptDataType GDScriptCompiler::_gdtype_from_datatype(const GDScriptParser::D } int GDScriptCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDScriptParser::OperatorNode *p_expression, int p_stack_level, int p_index_addr) { - Variant::Operator var_op = Variant::OP_MAX; switch (p_expression->op) { - case GDScriptParser::OperatorNode::OP_ASSIGN_ADD: var_op = Variant::OP_ADD; break; @@ -209,11 +201,9 @@ int GDScriptCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDS break; case GDScriptParser::OperatorNode::OP_INIT_ASSIGN: case GDScriptParser::OperatorNode::OP_ASSIGN: { - //none } break; default: { - ERR_FAIL_V(-1); } } @@ -221,7 +211,6 @@ int GDScriptCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDS bool initializer = p_expression->op == GDScriptParser::OperatorNode::OP_INIT_ASSIGN; if (var_op == Variant::OP_MAX) { - return _parse_expression(codegen, p_expression->arguments[1], p_stack_level, false, initializer); } @@ -235,7 +224,6 @@ int GDScriptCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDS } int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::Node *p_expression, int p_stack_level, bool p_root, bool p_initializer, int p_index_addr) { - switch (p_expression->type) { //should parse variable declaration and adjust stack accordingly... case GDScriptParser::Node::TYPE_IDENTIFIER: { @@ -251,7 +239,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: // TRY STACK! if (!p_initializer && codegen.stack_identifiers.has(identifier)) { - int pos = codegen.stack_identifiers[identifier]; return pos | (GDScriptFunction::ADDR_TYPE_STACK_VARIABLE << GDScriptFunction::ADDR_BITS); } @@ -269,11 +256,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: //TRY MEMBERS! if (!codegen.function_node || !codegen.function_node->_static) { - // TRY MEMBER VARIABLES! //static function if (codegen.script->member_indices.has(identifier)) { - int idx = codegen.script->member_indices[identifier].index; return idx | (GDScriptFunction::ADDR_TYPE_MEMBER << GDScriptFunction::ADDR_BITS); //argument (stack root) } @@ -283,13 +268,10 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: GDScript *owner = codegen.script; while (owner) { - GDScript *scr = owner; GDScriptNativeClass *nc = nullptr; while (scr) { - if (scr->constants.has(identifier)) { - //int idx=scr->constants[identifier]; int idx = codegen.get_name_map_pos(identifier); return idx | (GDScriptFunction::ADDR_TYPE_CLASS_CONSTANT << GDScriptFunction::ADDR_BITS); //argument (stack root) @@ -302,7 +284,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: // CLASS C++ Integer Constant if (nc) { - bool success = false; int constant = ClassDB::get_integer_constant(nc->get_name(), identifier, &success); if (success) { @@ -310,7 +291,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int idx; if (!codegen.constant_map.has(key)) { - idx = codegen.constant_map.size(); codegen.constant_map[key] = idx; @@ -326,7 +306,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) { - int idx = GDScriptLanguage::get_singleton()->get_global_map()[identifier]; return idx | (GDScriptFunction::ADDR_TYPE_GLOBAL << GDScriptFunction::ADDR_BITS); //argument (stack root) } @@ -334,7 +313,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: /* TRY GLOBAL CLASSES */ if (ScriptServer::is_global_class(identifier)) { - const GDScriptParser::ClassNode *class_node = codegen.class_node; while (class_node->owner) { class_node = class_node->owner; @@ -355,7 +333,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int idx; if (!codegen.constant_map.has(key)) { - idx = codegen.constant_map.size(); codegen.constant_map[key] = idx; @@ -368,7 +345,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: #ifdef TOOLS_ENABLED if (GDScriptLanguage::get_singleton()->get_named_globals_map().has(identifier)) { - int idx = codegen.named_globals.find(identifier); if (idx == -1) { idx = codegen.named_globals.size(); @@ -392,7 +368,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int idx; if (!codegen.constant_map.has(cn->value)) { - idx = codegen.constant_map.size(); codegen.constant_map[cn->value] = idx; @@ -412,14 +387,12 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: return (GDScriptFunction::ADDR_TYPE_SELF << GDScriptFunction::ADDR_BITS); } break; case GDScriptParser::Node::TYPE_ARRAY: { - const GDScriptParser::ArrayNode *an = static_cast<const GDScriptParser::ArrayNode *>(p_expression); Vector<int> values; int slevel = p_stack_level; for (int i = 0; i < an->elements.size(); i++) { - int ret = _parse_expression(codegen, an->elements[i], slevel); if (ret < 0) return ret; @@ -443,14 +416,12 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; case GDScriptParser::Node::TYPE_DICTIONARY: { - const GDScriptParser::DictionaryNode *dn = static_cast<const GDScriptParser::DictionaryNode *>(p_expression); Vector<int> values; int slevel = p_stack_level; for (int i = 0; i < dn->elements.size(); i++) { - int ret = _parse_expression(codegen, dn->elements[i].key, slevel); if (ret < 0) return ret; @@ -505,7 +476,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: case GDScriptDataType::NATIVE: { int class_idx; if (GDScriptLanguage::get_singleton()->get_global_map().has(cast_type.native_type)) { - class_idx = GDScriptLanguage::get_singleton()->get_global_map()[cast_type.native_type]; class_idx |= (GDScriptFunction::ADDR_TYPE_GLOBAL << GDScriptFunction::ADDR_BITS); //argument (stack root) } else { @@ -517,7 +487,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; case GDScriptDataType::SCRIPT: case GDScriptDataType::GDSCRIPT: { - Variant script = cast_type.script_type; int idx = codegen.get_constant_pos(script); idx |= GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT << GDScriptFunction::ADDR_BITS; //make it a local constant (faster access) @@ -543,10 +512,8 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: const GDScriptParser::OperatorNode *on = static_cast<const GDScriptParser::OperatorNode *>(p_expression); switch (on->op) { - //call/constructor operator case GDScriptParser::OperatorNode::OP_PARENT_CALL: { - ERR_FAIL_COND_V(on->arguments.size() < 1, -1); const GDScriptParser::IdentifierNode *in = (const GDScriptParser::IdentifierNode *)on->arguments[0]; @@ -554,7 +521,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: Vector<int> arguments; int slevel = p_stack_level; for (int i = 1; i < on->arguments.size(); i++) { - int ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; @@ -576,7 +542,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; case GDScriptParser::OperatorNode::OP_CALL: { - if (on->arguments[0]->type == GDScriptParser::Node::TYPE_TYPE) { //construct a basic type ERR_FAIL_COND_V(on->arguments.size() < 1, -1); @@ -587,7 +552,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: Vector<int> arguments; int slevel = p_stack_level; for (int i = 1; i < on->arguments.size(); i++) { - int ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; @@ -614,7 +578,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: Vector<int> arguments; int slevel = p_stack_level; for (int i = 1; i < on->arguments.size(); i++) { - int ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; @@ -648,14 +611,12 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int slevel = p_stack_level; for (int i = 0; i < on->arguments.size(); i++) { - int ret; if (i == 0 && on->arguments[i]->type == GDScriptParser::Node::TYPE_SELF && codegen.function_node && codegen.function_node->_static) { //static call to self ret = (GDScriptFunction::ADDR_TYPE_CLASS << GDScriptFunction::ADDR_BITS); } else if (i == 1) { - if (on->arguments[i]->type != GDScriptParser::Node::TYPE_IDENTIFIER) { _set_error("Attempt to call a non-identifier.", on); return -1; @@ -664,7 +625,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: ret = codegen.get_name_map_pos(id->name); } else { - ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; @@ -684,13 +644,11 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } } break; case GDScriptParser::OperatorNode::OP_YIELD: { - ERR_FAIL_COND_V(on->arguments.size() && on->arguments.size() != 2, -1); Vector<int> arguments; int slevel = p_stack_level; for (int i = 0; i < on->arguments.size(); i++) { - int ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; @@ -713,7 +671,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: //indexing operator case GDScriptParser::OperatorNode::OP_INDEX: case GDScriptParser::OperatorNode::OP_INDEX_NAMED: { - ERR_FAIL_COND_V(on->arguments.size() != 2, -1); int slevel = p_stack_level; @@ -728,7 +685,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: index = p_index_addr; } else if (named) { if (on->arguments[0]->type == GDScriptParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) { - GDScriptParser::IdentifierNode *identifier = static_cast<GDScriptParser::IdentifierNode *>(on->arguments[1]); const Map<StringName, GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(identifier->name); @@ -749,7 +705,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: index = codegen.get_name_map_pos(static_cast<GDScriptParser::IdentifierNode *>(on->arguments[1])->name); } else { - if (on->arguments[1]->type == GDScriptParser::Node::TYPE_CONSTANT && static_cast<const GDScriptParser::ConstantNode *>(on->arguments[1])->value.get_type() == Variant::STRING) { //also, somehow, named (speed up anyway) StringName name = static_cast<const GDScriptParser::ConstantNode *>(on->arguments[1])->value; @@ -775,7 +730,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; case GDScriptParser::OperatorNode::OP_AND: { - // AND operator with early out on failure int res = _parse_expression(codegen, on->arguments[0], p_stack_level); @@ -808,7 +762,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; case GDScriptParser::OperatorNode::OP_OR: { - // OR operator with early out on success int res = _parse_expression(codegen, on->arguments[0], p_stack_level); @@ -842,7 +795,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; // ternary operators case GDScriptParser::OperatorNode::OP_TERNARY_IF: { - // x IF a ELSE y operator with early out on failure int res = _parse_expression(codegen, on->arguments[0], p_stack_level); @@ -981,18 +933,15 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: case GDScriptParser::OperatorNode::OP_ASSIGN_BIT_XOR: case GDScriptParser::OperatorNode::OP_INIT_ASSIGN: case GDScriptParser::OperatorNode::OP_ASSIGN: { - ERR_FAIL_COND_V(on->arguments.size() != 2, -1); if (on->arguments[0]->type == GDScriptParser::Node::TYPE_OPERATOR && (static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX || static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED)) { - // SET (chained) MODE! #ifdef DEBUG_ENABLED if (static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED) { const GDScriptParser::OperatorNode *inon = static_cast<GDScriptParser::OperatorNode *>(on->arguments[0]); if (inon->arguments[0]->type == GDScriptParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) { - const Map<StringName, GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(static_cast<GDScriptParser::IdentifierNode *>(inon->arguments[1])->name); if (MI && MI->get().setter == codegen.function_node->name) { String n = static_cast<GDScriptParser::IdentifierNode *>(inon->arguments[1])->name; @@ -1017,13 +966,10 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: //create get/set chain GDScriptParser::OperatorNode *n = op; while (true) { - chain.push_back(n); if (n->arguments[0]->type != GDScriptParser::Node::TYPE_OPERATOR) { - //check for a built-in property if (n->arguments[0]->type == GDScriptParser::Node::TYPE_IDENTIFIER) { - GDScriptParser::IdentifierNode *identifier = static_cast<GDScriptParser::IdentifierNode *>(n->arguments[0]); if (_is_class_member_property(codegen, identifier->name)) { assign_property = identifier->name; @@ -1053,7 +999,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: Vector<int> setchain; if (assign_property != StringName()) { - // recover and assign at the end, this allows stuff like // position.x+=2.0 // in Node2D @@ -1063,7 +1008,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } for (List<GDScriptParser::OperatorNode *>::Element *E = chain.back(); E; E = E->prev()) { - if (E == chain.front()) //ignore first break; @@ -1071,12 +1015,10 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int key_idx; if (named) { - key_idx = codegen.get_name_map_pos(static_cast<const GDScriptParser::IdentifierNode *>(E->get()->arguments[1])->name); //printf("named key %x\n",key_idx); } else { - if (prev_pos & (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS)) { slevel++; codegen.alloc_stack(slevel); @@ -1117,11 +1059,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: bool named = false; if (op->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED) { - set_index = codegen.get_name_map_pos(static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[1])->name); named = true; } else { - set_index = _parse_expression(codegen, op->arguments[1], slevel + 1); named = false; } @@ -1144,7 +1084,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.push_back(set_value); for (int i = 0; i < setchain.size(); i++) { - codegen.opcodes.push_back(setchain[i]); } @@ -1167,7 +1106,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: return GDScriptFunction::ADDR_TYPE_NIL << GDScriptFunction::ADDR_BITS; } else { - //REGULAR ASSIGNMENT MODE!! int slevel = p_stack_level; @@ -1199,7 +1137,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: case GDScriptDataType::NATIVE: { int class_idx; if (GDScriptLanguage::get_singleton()->get_global_map().has(assign_type.native_type)) { - class_idx = GDScriptLanguage::get_singleton()->get_global_map()[assign_type.native_type]; class_idx |= (GDScriptFunction::ADDR_TYPE_GLOBAL << GDScriptFunction::ADDR_BITS); //argument (stack root) } else { @@ -1213,7 +1150,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; case GDScriptDataType::SCRIPT: case GDScriptDataType::GDSCRIPT: { - Variant script = assign_type.script_type; int idx = codegen.get_constant_pos(script); idx |= GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT << GDScriptFunction::ADDR_BITS; //make it a local constant (faster access) @@ -1242,7 +1178,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } } break; case GDScriptParser::OperatorNode::OP_IS: { - ERR_FAIL_COND_V(on->arguments.size() != 2, false); int slevel = p_stack_level; @@ -1283,7 +1218,6 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.push_back((int)tn->vtype); // argument 2 (unary only takes one parameter) } break; default: { - ERR_FAIL_V_MSG(0, "Bug in bytecode compiler, unexpected operator #" + itos(on->op) + " in parse tree while parsing expression."); //unreachable code } break; @@ -1296,20 +1230,17 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; //TYPE_TYPE, default: { - ERR_FAIL_V_MSG(-1, "Bug in bytecode compiler, unexpected node in parse tree while parsing expression."); //unreachable code } break; } } Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::BlockNode *p_block, int p_stack_level, int p_break_addr, int p_continue_addr) { - codegen.push_stack_identifiers(); int new_identifiers = 0; codegen.current_line = p_block->line; for (int i = 0; i < p_block->statements.size(); i++) { - const GDScriptParser::Node *s = p_block->statements[i]; switch (s->type) { @@ -1327,7 +1258,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo const GDScriptParser::ControlFlowNode *cf = static_cast<const GDScriptParser::ControlFlowNode *>(s); switch (cf->cf_type) { - case GDScriptParser::ControlFlowNode::CF_MATCH: { GDScriptParser::MatchNode *match = cf->match; @@ -1401,7 +1331,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo } break; case GDScriptParser::ControlFlowNode::CF_IF: { - int ret2 = _parse_expression(codegen, cf->arguments[0], p_stack_level, false); if (ret2 < 0) return ERR_PARSE_ERROR; @@ -1416,7 +1345,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo return err; if (cf->body_else) { - codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); int end_addr = codegen.opcodes.size(); codegen.opcodes.push_back(0); @@ -1434,7 +1362,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo } break; case GDScriptParser::ControlFlowNode::CF_FOR: { - int slevel = p_stack_level; int iter_stack_pos = slevel; int iterator_pos = (slevel++) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); @@ -1486,7 +1413,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo } break; case GDScriptParser::ControlFlowNode::CF_WHILE: { - codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(codegen.opcodes.size() + 3); int break_addr = codegen.opcodes.size(); @@ -1510,9 +1436,7 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo } break; case GDScriptParser::ControlFlowNode::CF_BREAK: { - if (p_break_addr < 0) { - _set_error("'break'' not within loop", cf); return ERR_COMPILATION_FAILED; } @@ -1521,9 +1445,7 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo } break; case GDScriptParser::ControlFlowNode::CF_CONTINUE: { - if (p_continue_addr < 0) { - _set_error("'continue' not within loop", cf); return ERR_COMPILATION_FAILED; } @@ -1533,17 +1455,14 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo } break; case GDScriptParser::ControlFlowNode::CF_RETURN: { - int ret2; if (cf->arguments.size()) { - ret2 = _parse_expression(codegen, cf->arguments[0], p_stack_level, false); if (ret2 < 0) return ERR_PARSE_ERROR; } else { - ret2 = GDScriptFunction::ADDR_TYPE_NIL << GDScriptFunction::ADDR_BITS; } @@ -1582,7 +1501,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo #endif } break; case GDScriptParser::Node::TYPE_LOCAL_VAR: { - const GDScriptParser::LocalVarNode *lv = static_cast<const GDScriptParser::LocalVarNode *>(s); // since we are using properties now for most class access, allow shadowing of class members to make user's life easier. @@ -1610,7 +1528,6 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo } Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser::ClassNode *p_class, const GDScriptParser::FunctionNode *p_func, bool p_for_ready) { - Vector<int> bytecode; CodeGen codegen; @@ -1651,7 +1568,6 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser if (is_initializer || (p_func && String(p_func->name) == "_init")) { //parse initializer for class members if (!p_func && p_class->extends_used && p_script->native.is_null()) { - //call implicit parent constructor codegen.opcodes.push_back(GDScriptFunction::OPCODE_CALL_SELF_BASE); codegen.opcodes.push_back(codegen.get_name_map_pos("_init")); @@ -1679,13 +1595,10 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser StringName func_name; if (p_func) { - if (p_func->default_values.size()) { - codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_TO_DEF_ARGUMENT); defarg_addr.push_back(codegen.opcodes.size()); for (int i = 0; i < p_func->default_values.size(); i++) { - _parse_expression(codegen, p_func->default_values[i], stack_level, true); defarg_addr.push_back(codegen.opcodes.size()); } @@ -1747,17 +1660,14 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser gdfunc->constants.write[idx] = *K; } } else { - gdfunc->_constants_ptr = nullptr; gdfunc->_constant_count = 0; } //global names if (codegen.name_map.size()) { - gdfunc->global_names.resize(codegen.name_map.size()); gdfunc->_global_names_ptr = &gdfunc->global_names[0]; for (Map<StringName, int>::Element *E = codegen.name_map.front(); E; E = E->next()) { - gdfunc->global_names.write[E->get()] = E->key(); } gdfunc->_global_names_count = gdfunc->global_names.size(); @@ -1780,19 +1690,16 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser #endif if (codegen.opcodes.size()) { - gdfunc->code = codegen.opcodes; gdfunc->_code_ptr = &gdfunc->code[0]; gdfunc->_code_size = codegen.opcodes.size(); } else { - gdfunc->_code_ptr = nullptr; gdfunc->_code_size = 0; } if (defarg_addr.size()) { - gdfunc->default_arguments = defarg_addr; gdfunc->_default_arg_count = defarg_addr.size() - 1; gdfunc->_default_arg_ptr = &gdfunc->default_arguments[0]; @@ -1860,7 +1767,6 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser } Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptParser::ClassNode *p_class, bool p_keep_state) { - parsing_classes.insert(p_script); if (p_class->owner && p_class->owner->owner) { @@ -1931,7 +1837,6 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar } for (int i = 0; i < p_class->variables.size(); i++) { - StringName name = p_class->variables[i].identifier; GDScript::MemberInfo minfo; @@ -1946,7 +1851,6 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar PropertyInfo export_info = p_class->variables[i]._export; if (export_info.type != Variant::NIL) { - if (!minfo.data_type.has_type) { prop_info.type = export_info.type; prop_info.class_name = export_info.class_name; @@ -1973,7 +1877,6 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar } for (Map<StringName, GDScriptParser::ClassNode::Constant>::Element *E = p_class->constant_expressions.front(); E; E = E->next()) { - StringName name = E->key(); ERR_CONTINUE(E->get().expression->type != GDScriptParser::Node::TYPE_CONSTANT); @@ -1988,13 +1891,11 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar } for (int i = 0; i < p_class->_signals.size(); i++) { - StringName name = p_class->_signals[i].name; GDScript *c = p_script; while (c) { - if (c->_signals.has(name)) { _set_error("Signal '" + name + "' redefined (in current or parent class)", p_class); return ERR_ALREADY_EXISTS; @@ -2052,7 +1953,6 @@ Error GDScriptCompiler::_parse_class_blocks(GDScript *p_script, const GDScriptPa bool has_ready = false; for (int i = 0; i < p_class->functions.size(); i++) { - if (!has_initializer && p_class->functions[i]->name == "_init") has_initializer = true; if (!has_ready && p_class->functions[i]->name == "_ready") @@ -2065,7 +1965,6 @@ Error GDScriptCompiler::_parse_class_blocks(GDScript *p_script, const GDScriptPa //parse static methods for (int i = 0; i < p_class->static_functions.size(); i++) { - Error err = _parse_function(p_script, p_class, p_class->static_functions[i]); if (err) return err; @@ -2091,7 +1990,6 @@ Error GDScriptCompiler::_parse_class_blocks(GDScript *p_script, const GDScriptPa if (p_keep_state) { for (Set<Object *>::Element *E = p_script->instances.front(); E;) { - Set<Object *>::Element *N = E->next(); ScriptInstance *si = E->get()->get_script_instance(); @@ -2126,7 +2024,6 @@ Error GDScriptCompiler::_parse_class_blocks(GDScript *p_script, const GDScriptPa } #endif } else { - GDScriptInstance *gi = static_cast<GDScriptInstance *>(si); gi->reload_members(); } @@ -2151,7 +2048,6 @@ Error GDScriptCompiler::_parse_class_blocks(GDScript *p_script, const GDScriptPa } void GDScriptCompiler::_make_scripts(GDScript *p_script, const GDScriptParser::ClassNode *p_class, bool p_keep_state) { - Map<StringName, Ref<GDScript>> old_subclasses; if (p_keep_state) { @@ -2186,7 +2082,6 @@ void GDScriptCompiler::_make_scripts(GDScript *p_script, const GDScriptParser::C } Error GDScriptCompiler::compile(const GDScriptParser *p_parser, GDScript *p_script, bool p_keep_state) { - err_line = -1; err_column = -1; error = ""; @@ -2218,15 +2113,12 @@ Error GDScriptCompiler::compile(const GDScriptParser *p_parser, GDScript *p_scri } String GDScriptCompiler::get_error() const { - return error; } int GDScriptCompiler::get_error_line() const { - return err_line; } int GDScriptCompiler::get_error_column() const { - return err_column; } diff --git a/modules/gdscript/gdscript_compiler.h b/modules/gdscript/gdscript_compiler.h index 08e1ec74af..3a362c75bc 100644 --- a/modules/gdscript/gdscript_compiler.h +++ b/modules/gdscript/gdscript_compiler.h @@ -36,13 +36,11 @@ #include "gdscript_parser.h" class GDScriptCompiler { - const GDScriptParser *parser; Set<GDScript *> parsed_classes; Set<GDScript *> parsing_classes; GDScript *main_script; struct CodeGen { - GDScript *script; const GDScriptParser::ClassNode *class_node; const GDScriptParser::FunctionNode *function_node; @@ -71,7 +69,6 @@ class GDScriptCompiler { void push_stack_identifiers() { stack_id_stack.push_back(stack_identifiers); if (debug_stack) { - block_identifier_stack.push_back(block_identifiers); block_identifiers.clear(); } @@ -83,7 +80,6 @@ class GDScriptCompiler { if (debug_stack) { for (Map<StringName, int>::Element *E = block_identifiers.front(); E; E = E->next()) { - GDScriptFunction::StackDebug sd; sd.added = false; sd.identifier = E->key(); diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 56381e8af7..fc6f9b5419 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -41,19 +41,16 @@ #endif void GDScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) const { - p_delimiters->push_back("#"); } void GDScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { - p_delimiters->push_back("\" \""); p_delimiters->push_back("' '"); p_delimiters->push_back("\"\"\" \"\"\""); } String GDScriptLanguage::_get_processed_template(const String &p_template, const String &p_base_class_name) const { - String processed_template = p_template; #ifdef TOOLS_ENABLED @@ -109,18 +106,15 @@ Ref<Script> GDScriptLanguage::get_template(const String &p_class_name, const Str } bool GDScriptLanguage::is_using_templates() { - return true; } void GDScriptLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) { - String _template = _get_processed_template(p_script->get_source_code(), p_base_class_name); p_script->set_source_code(_template); } bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { - GDScriptParser parser; Error err = parser.parse(p_script, p_path.get_base_dir(), true, p_path, false, r_safe_lines); @@ -143,35 +137,29 @@ bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int & r_test_error = parser.get_error(); return false; } else { - const GDScriptParser::Node *root = parser.get_parse_tree(); ERR_FAIL_COND_V(root->type != GDScriptParser::Node::TYPE_CLASS, false); const GDScriptParser::ClassNode *cl = static_cast<const GDScriptParser::ClassNode *>(root); Map<int, String> funcs; for (int i = 0; i < cl->functions.size(); i++) { - funcs[cl->functions[i]->line] = cl->functions[i]->name; } for (int i = 0; i < cl->static_functions.size(); i++) { - funcs[cl->static_functions[i]->line] = cl->static_functions[i]->name; } for (int i = 0; i < cl->subclasses.size(); i++) { for (int j = 0; j < cl->subclasses[i]->functions.size(); j++) { - funcs[cl->subclasses[i]->functions[j]->line] = String(cl->subclasses[i]->name) + "." + cl->subclasses[i]->functions[j]->name; } for (int j = 0; j < cl->subclasses[i]->static_functions.size(); j++) { - funcs[cl->subclasses[i]->static_functions[j]->line] = String(cl->subclasses[i]->name) + "." + cl->subclasses[i]->static_functions[j]->name; } } for (Map<int, String>::Element *E = funcs.front(); E; E = E->next()) { - r_functions->push_back(E->get() + ":" + itos(E->key())); } } @@ -180,27 +168,22 @@ bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int & } bool GDScriptLanguage::has_named_classes() const { - return false; } bool GDScriptLanguage::supports_builtin_mode() const { - return true; } int GDScriptLanguage::find_function(const String &p_function, const String &p_code) const { - GDScriptTokenizerText tokenizer; tokenizer.set_code(p_code); int indent = 0; while (tokenizer.get_token() != GDScriptTokenizer::TK_EOF && tokenizer.get_token() != GDScriptTokenizer::TK_ERROR) { - if (tokenizer.get_token() == GDScriptTokenizer::TK_NEWLINE) { indent = tokenizer.get_token_line_indent(); } if (indent == 0 && tokenizer.get_token() == GDScriptTokenizer::TK_PR_FUNCTION && tokenizer.get_token(1) == GDScriptTokenizer::TK_IDENTIFIER) { - String identifier = tokenizer.get_token_identifier(1); if (identifier == p_function) { return tokenizer.get_token_line(); @@ -212,7 +195,6 @@ int GDScriptLanguage::find_function(const String &p_function, const String &p_co } Script *GDScriptLanguage::create_script() const { - return memnew(GDScript); } @@ -222,7 +204,6 @@ bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const //break because of parse error if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { - _debug_parse_err_line = p_line; _debug_parse_err_file = p_file; _debug_error = p_error; @@ -234,9 +215,7 @@ bool GDScriptLanguage::debug_break_parse(const String &p_file, int p_line, const } bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { - _debug_parse_err_line = -1; _debug_parse_err_file = ""; _debug_error = p_error; @@ -249,19 +228,16 @@ bool GDScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) } String GDScriptLanguage::debug_get_error() const { - return _debug_error; } int GDScriptLanguage::debug_get_stack_level_count() const { - if (_debug_parse_err_line >= 0) return 1; return _debug_call_stack_pos; } int GDScriptLanguage::debug_get_stack_level_line(int p_level) const { - if (_debug_parse_err_line >= 0) return _debug_parse_err_line; @@ -272,7 +248,6 @@ int GDScriptLanguage::debug_get_stack_level_line(int p_level) const { return *(_call_stack[l].line); } String GDScriptLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_line >= 0) return ""; @@ -281,7 +256,6 @@ String GDScriptLanguage::debug_get_stack_level_function(int p_level) const { return _call_stack[l].function->get_name(); } String GDScriptLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_line >= 0) return _debug_parse_err_file; @@ -290,7 +264,6 @@ String GDScriptLanguage::debug_get_stack_level_source(int p_level) const { return _call_stack[l].function->get_source(); } void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_line >= 0) return; @@ -303,13 +276,11 @@ void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p f->debug_get_stack_member_state(*_call_stack[l].line, &locals); for (List<Pair<StringName, int>>::Element *E = locals.front(); E; E = E->next()) { - p_locals->push_back(E->get().first); p_values->push_back(_call_stack[l].stack[E->get().second]); } } void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_line >= 0) return; @@ -327,14 +298,12 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> * const Map<StringName, GDScript::MemberInfo> &mi = script->debug_get_member_indices(); for (const Map<StringName, GDScript::MemberInfo>::Element *E = mi.front(); E; E = E->next()) { - p_members->push_back(E->key()); p_values->push_back(instance->debug_get_member_by_index(E->get().index)); } } ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) { - if (_debug_parse_err_line >= 0) return nullptr; @@ -347,7 +316,6 @@ ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) { } void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - const Map<StringName, int> &name_idx = GDScriptLanguage::get_singleton()->get_global_map(); const Variant *globals = GDScriptLanguage::get_singleton()->get_global_array(); @@ -355,7 +323,6 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> get_public_constants(&cinfo); for (const Map<StringName, int>::Element *E = name_idx.front(); E; E = E->next()) { - if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key())) continue; @@ -391,19 +358,15 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> } String GDScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { - return ""; } void GDScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("gd"); } void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { - for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) { - p_functions->push_back(GDScriptFunctions::get_info(GDScriptFunctions::Function(i))); } @@ -437,7 +400,6 @@ void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const } void GDScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_constants) const { - Pair<String, Variant> pi; pi.first = "PI"; pi.second = Math_PI; @@ -460,7 +422,6 @@ void GDScriptLanguage::get_public_constants(List<Pair<String, Variant>> *p_const } String GDScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const { - #ifdef TOOLS_ENABLED bool th = EditorSettings::get_singleton()->get_setting("text_editor/completion/add_type_hints"); #else @@ -491,7 +452,6 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) struct GDScriptCompletionContext { - const GDScriptParser::ClassNode *_class = nullptr; const GDScriptParser::FunctionNode *function = nullptr; const GDScriptParser::BlockNode *block = nullptr; @@ -513,7 +473,6 @@ struct GDScriptCompletionIdentifier { }; static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Map<String, ScriptCodeCompletionOption> &r_list) { - const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; for (int i = 0; i < p_dir->get_file_count(); i++) { @@ -528,7 +487,6 @@ static void _get_directory_contents(EditorFileSystemDirectory *p_dir, Map<String } static String _get_visual_datatype(const PropertyInfo &p_info, bool p_isarg = true) { - if (p_info.usage & PROPERTY_USAGE_CLASS_IS_ENUM) { String enum_name = p_info.class_name; if (enum_name.find(".") == -1) { @@ -828,7 +786,6 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G Object *baseptr = base.value; if (all_is_const && String(id) == "get_node" && ClassDB::is_parent_class(native_type.native_type, "Node") && args.size()) { - String arg1 = args[0]; if (arg1.begins_with("/root/")) { String which = arg1.get_slice("/", 2); @@ -842,7 +799,6 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - String s = E->get().name; if (!s.begins_with("autoload/")) { continue; @@ -1184,7 +1140,6 @@ static bool _guess_expression_type(GDScriptCompletionContext &p_context, const G } static bool _guess_identifier_type(GDScriptCompletionContext &p_context, const StringName &p_identifier, GDScriptCompletionIdentifier &r_type) { - // Look in blocks first const GDScriptParser::BlockNode *blk = p_context.block; int last_assign_line = -1; @@ -1746,7 +1701,6 @@ static bool _guess_method_return_type_from_base(GDScriptCompletionContext &p_con } static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx) { - String arghint = _get_visual_datatype(p_info.return_val, false) + " " + p_info.name + "("; int def_args = p_info.arguments.size() - p_info.default_arguments.size(); @@ -1791,7 +1745,6 @@ static String _make_arguments_hint(const MethodInfo &p_info, int p_arg_idx) { } static String _make_arguments_hint(const GDScriptParser::FunctionNode *p_function, int p_arg_idx) { - String arghint = p_function->return_type.to_string() + " " + p_function->name.operator String() + "("; int def_args = p_function->arguments.size() - p_function->default_values.size(); @@ -1833,7 +1786,6 @@ static String _make_arguments_hint(const GDScriptParser::FunctionNode *p_functio } static void _find_enumeration_candidates(const String p_enum_hint, Map<String, ScriptCodeCompletionOption> &r_result) { - if (p_enum_hint.find(".") == -1) { // Global constant StringName current_enum = p_enum_hint; @@ -2144,11 +2096,9 @@ static void _find_identifiers_in_base(const GDScriptCompletionContext &p_context } static void _find_identifiers(const GDScriptCompletionContext &p_context, bool p_only_functions, Map<String, ScriptCodeCompletionOption> &r_result) { - const GDScriptParser::BlockNode *block = p_context.block; if (p_context.function) { - const GDScriptParser::FunctionNode *f = p_context.function; for (int i = 0; i < f->arguments.size(); i++) { @@ -2417,7 +2367,6 @@ static void _find_call_arguments(const GDScriptCompletionContext &p_context, con } static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDScriptParser::Node *p_node, int p_argidx, Map<String, ScriptCodeCompletionOption> &r_result, bool &r_forced, String &r_arghint) { - const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; if (!p_node || p_node->type != GDScriptParser::Node::TYPE_OPERATOR) { @@ -2473,7 +2422,6 @@ static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDS } return; } else if (op->arguments[0]->type == GDScriptParser::Node::TYPE_SELF) { - if (op->arguments.size() < 2 || op->arguments[1]->type != GDScriptParser::Node::TYPE_IDENTIFIER) { return; } @@ -2547,7 +2495,6 @@ static void _find_call_arguments(GDScriptCompletionContext &p_context, const GDS } Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) { - const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; GDScriptParser parser; @@ -2595,7 +2542,6 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path p_owner->get_argument_options("get_node", 0, &opts); for (List<String>::Element *E = opts.front(); E; E = E->next()) { - String opt = E->get().strip_edges(); if (opt.is_quoted()) { r_forced = true; @@ -2703,7 +2649,6 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_path List<MethodInfo> virtual_methods; ClassDB::get_virtual_methods(class_name, &virtual_methods); for (List<MethodInfo>::Element *E = virtual_methods.front(); E; E = E->next()) { - MethodInfo &mi = E->get(); String method_hint = mi.name; if (method_hint.find(":") != -1) { @@ -3027,19 +2972,16 @@ String GDScriptLanguage::_get_indentation() const { } void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_to_line) const { - String indent = _get_indentation(); Vector<String> lines = p_code.split("\n"); List<int> indent_stack; for (int i = 0; i < lines.size(); i++) { - String l = lines[i]; int tc = 0; for (int j = 0; j < l.length(); j++) { if (l[j] == ' ' || l[j] == '\t') { - tc++; } else { break; @@ -3067,7 +3009,6 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t } if (i >= p_from_line) { - l = ""; for (int j = 0; j < indent_stack.size(); j++) { l += indent; @@ -3271,7 +3212,6 @@ static Error _lookup_symbol_from_base(const GDScriptParser::DataType &p_base, co } Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) { - //before parsing, try the usual stuff if (ClassDB::class_exists(p_symbol)) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; @@ -3352,7 +3292,6 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol [[fallthrough]]; } case GDScriptParser::COMPLETION_IDENTIFIER: { - if (!is_function) { is_function = parser.get_completion_identifier_is_function(); } @@ -3404,13 +3343,11 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol ProjectSettings::get_singleton()->get_property_list(&props); for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - String s = E->get().name; if (!s.begins_with("autoload/")) continue; String name = s.get_slice("/", 1); if (name == String(p_symbol)) { - String path = ProjectSettings::get_singleton()->get(s); if (path.begins_with("*")) { String script = path.substr(1, path.length()); @@ -3422,7 +3359,6 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } if (FileAccess::exists(script)) { - r_result.type = ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION; r_result.location = 0; r_result.script = ResourceLoader::load(script); @@ -3505,7 +3441,6 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } break; case GDScriptParser::COMPLETION_TYPE_HINT: { - GDScriptParser::DataType base_type = context._class->base_type; base_type.has_type = true; base_type.kind = GDScriptParser::DataType::CLASS; diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index 4e31ffe2a4..5ad8c2d367 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -35,12 +35,10 @@ #include "gdscript_functions.h" Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant &static_ref, Variant *p_stack, String &r_error) const { - int address = p_address & ADDR_MASK; //sequential table (jump table generated by compiler) switch ((p_address & ADDR_TYPE_MASK) >> ADDR_BITS) { - case ADDR_TYPE_SELF: { #ifdef DEBUG_ENABLED if (unlikely(!p_instance)) { @@ -51,7 +49,6 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta return &self; } break; case ADDR_TYPE_CLASS: { - return &static_ref; } break; case ADDR_TYPE_MEMBER: { @@ -65,7 +62,6 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta return &p_instance->members.write[address]; } break; case ADDR_TYPE_CLASS_CONSTANT: { - //todo change to index! GDScript *s = p_script; #ifdef DEBUG_ENABLED @@ -76,7 +72,6 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta while (s) { GDScript *o = s; while (o) { - Map<StringName, Variant>::Element *E = o->constants.find(*sn); if (E) { return &E->get(); @@ -133,7 +128,6 @@ Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_insta #ifdef DEBUG_ENABLED static String _get_var_type(const Variant *p_var) { - String basestr; if (p_var->get_type() == Variant::OBJECT) { @@ -161,7 +155,6 @@ static String _get_var_type(const Variant *p_var) { #endif // DEBUG_ENABLED String GDScriptFunction::_get_call_error(const Callable::CallError &p_err, const String &p_where, const Variant **argptrs) const { - String err_text; if (p_err.error == Callable::CallError::CALL_ERROR_INVALID_ARGUMENT) { @@ -259,11 +252,9 @@ String GDScriptFunction::_get_call_error(const Callable::CallError &p_err, const #endif Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_args, int p_argcount, Callable::CallError &r_err, CallState *p_state) { - OPCODES_TABLE; if (!_code_ptr) { - return Variant(); } @@ -300,22 +291,17 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a self = p_state->self; } else { - if (p_argcount != _argument_count) { - if (p_argcount > _argument_count) { - r_err.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; r_err.argument = _argument_count; return Variant(); } else if (p_argcount < _argument_count - _default_arg_count) { - r_err.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_err.argument = _argument_count - _default_arg_count; return Variant(); } else { - defarg = _argument_count - p_argcount; } } @@ -323,11 +309,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a alloca_size = sizeof(Variant *) * _call_size + sizeof(Variant) * _stack_size; if (alloca_size) { - uint8_t *aptr = (uint8_t *)alloca(alloca_size); if (_stack_size) { - stack = (Variant *)aptr; for (int i = 0; i < p_argcount; i++) { if (!argument_types[i].has_type) { @@ -356,10 +340,8 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } if (_call_size) { - call_args = (Variant **)&aptr[sizeof(Variant) * _stack_size]; } else { - call_args = nullptr; } @@ -370,7 +352,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a if (p_instance) { if (p_instance->base_ref && static_cast<Reference *>(p_instance->owner)->is_referenced()) { - self = REF(static_cast<Reference *>(p_instance->owner)); } else { self = p_instance->owner; @@ -437,9 +418,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #endif OPCODE_SWITCH(_code_ptr[ip]) { - OPCODE(OPCODE_OPERATOR) { - CHECK_SPACE(5); bool valid; @@ -459,7 +438,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #endif #ifdef DEBUG_ENABLED if (!valid) { - if (ret.get_type() == Variant::STRING) { //return a string when invalid with the error err_text = ret; @@ -476,7 +454,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_EXTENDS_TEST) { - CHECK_SPACE(4); GET_VARIANT_PTR(a, 1); @@ -485,7 +462,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (b->get_type() != Variant::OBJECT || b->operator Object *() == nullptr) { - err_text = "Right operand of 'is' is not a class."; OPCODE_BREAK; } @@ -493,7 +469,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a bool extends_ok = false; if (a->get_type() == Variant::OBJECT && a->operator Object *() != nullptr) { - #ifdef DEBUG_ENABLED bool was_freed; Object *obj_A = a->get_validated_object_with_check(was_freed); @@ -522,11 +497,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a //in other situation, this shoul return false. if (obj_A->get_script_instance() && obj_A->get_script_instance()->get_language() == GDScriptLanguage::get_singleton()) { - GDScript *cmp = static_cast<GDScript *>(obj_A->get_script_instance()->get_script().ptr()); //bool found=false; while (cmp) { - if (cmp == scr_B) { //inherits from script, all ok extends_ok = true; @@ -538,12 +511,10 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } } else { - GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(obj_B); #ifdef DEBUG_ENABLED if (!nc) { - err_text = "Right operand of 'is' is not a class (type: '" + obj_B->get_class() + "')."; OPCODE_BREAK; } @@ -558,7 +529,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_IS_BUILTIN) { - CHECK_SPACE(4); GET_VARIANT_PTR(value, 1); @@ -573,7 +543,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_SET) { - CHECK_SPACE(3); GET_VARIANT_PTR(dst, 1); @@ -600,7 +569,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_GET) { - CHECK_SPACE(3); GET_VARIANT_PTR(src, 1); @@ -633,7 +601,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_SET_NAMED) { - CHECK_SPACE(3); GET_VARIANT_PTR(dst, 1); @@ -659,7 +626,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_GET_NAMED) { - CHECK_SPACE(4); GET_VARIANT_PTR(src, 1); @@ -694,7 +660,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_SET_MEMBER) { - CHECK_SPACE(3); int indexname = _code_ptr[ip + 1]; GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count); @@ -719,7 +684,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_GET_MEMBER) { - CHECK_SPACE(3); int indexname = _code_ptr[ip + 1]; GD_ERR_BREAK(indexname < 0 || indexname >= _global_names_count); @@ -740,7 +704,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_ASSIGN) { - CHECK_SPACE(3); GET_VARIANT_PTR(dst, 1); GET_VARIANT_PTR(src, 2); @@ -752,7 +715,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_ASSIGN_TRUE) { - CHECK_SPACE(2); GET_VARIANT_PTR(dst, 1); @@ -763,7 +725,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_ASSIGN_FALSE) { - CHECK_SPACE(2); GET_VARIANT_PTR(dst, 1); @@ -774,7 +735,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_ASSIGN_TYPED_BUILTIN) { - CHECK_SPACE(4); GET_VARIANT_PTR(dst, 2); GET_VARIANT_PTR(src, 3); @@ -804,7 +764,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_ASSIGN_TYPED_NATIVE) { - CHECK_SPACE(4); GET_VARIANT_PTR(dst, 2); GET_VARIANT_PTR(src, 3); @@ -833,7 +792,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_ASSIGN_TYPED_SCRIPT) { - CHECK_SPACE(4); GET_VARIANT_PTR(dst, 2); GET_VARIANT_PTR(src, 3); @@ -850,7 +808,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } if (src->get_type() != Variant::NIL && src->operator Object *() != nullptr) { - ScriptInstance *scr_inst = src->operator Object *()->get_script_instance(); if (!scr_inst) { err_text = "Trying to assign value of type '" + src->operator Object *()->get_class_name() + @@ -884,7 +841,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_CAST_TO_BUILTIN) { - CHECK_SPACE(4); Variant::Type to_type = (Variant::Type)_code_ptr[ip + 1]; GET_VARIANT_PTR(src, 2); @@ -907,7 +863,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_CAST_TO_NATIVE) { - CHECK_SPACE(4); GET_VARIANT_PTR(to_type, 1); GET_VARIANT_PTR(src, 2); @@ -935,7 +890,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_CAST_TO_SCRIPT) { - CHECK_SPACE(4); GET_VARIANT_PTR(to_type, 1); GET_VARIANT_PTR(src, 2); @@ -955,11 +909,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a bool valid = false; if (src->get_type() != Variant::NIL && src->operator Object *() != nullptr) { - ScriptInstance *scr_inst = src->operator Object *()->get_script_instance(); if (scr_inst) { - Script *src_type = src->operator Object *()->get_script_instance()->get_script().ptr(); while (src_type) { @@ -983,7 +935,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_CONSTRUCT) { - CHECK_SPACE(2); Variant::Type t = Variant::Type(_code_ptr[ip + 1]); int argc = _code_ptr[ip + 2]; @@ -1000,7 +951,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (err.error != Callable::CallError::CALL_OK) { - err_text = _get_call_error(err, "'" + Variant::get_type_name(t) + "' constructor", (const Variant **)argptrs); OPCODE_BREAK; } @@ -1012,7 +962,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_CONSTRUCT_ARRAY) { - CHECK_SPACE(1); int argc = _code_ptr[ip + 1]; Array array; //arrays are always shared @@ -1033,7 +982,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_CONSTRUCT_DICTIONARY) { - CHECK_SPACE(1); int argc = _code_ptr[ip + 1]; Dictionary dict; //arrays are always shared @@ -1041,7 +989,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a CHECK_SPACE(argc * 2 + 2); for (int i = 0; i < argc; i++) { - GET_VARIANT_PTR(k, 2 + i * 2 + 0); GET_VARIANT_PTR(v, 2 + i * 2 + 1); dict[*k] = *v; @@ -1057,7 +1004,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE(OPCODE_CALL_RETURN) OPCODE(OPCODE_CALL) { - CHECK_SPACE(4); bool call_ret = _code_ptr[ip] == OPCODE_CALL_RETURN; @@ -1088,11 +1034,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #endif Callable::CallError err; if (call_ret) { - GET_VARIANT_PTR(ret, argc); base->call_ptr(*methodname, (const Variant **)argptrs, argc, ret, err); } else { - base->call_ptr(*methodname, (const Variant **)argptrs, argc, nullptr, err); } #ifdef DEBUG_ENABLED @@ -1101,7 +1045,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } if (err.error != Callable::CallError::CALL_OK) { - String methodstr = *methodname; String basestr = _get_var_type(base); @@ -1113,14 +1056,11 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } } } else if (methodstr == "free") { - if (err.error == Callable::CallError::CALL_ERROR_INVALID_METHOD) { - if (base->is_ref()) { err_text = "Attempted to free a reference."; OPCODE_BREAK; } else if (base->get_type() == Variant::OBJECT) { - err_text = "Attempted to free a locked object (calling or emitting)."; OPCODE_BREAK; } @@ -1137,7 +1077,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_CALL_BUILT_IN) { - CHECK_SPACE(4); GDScriptFunctions::Function func = GDScriptFunctions::Function(_code_ptr[ip + 1]); @@ -1161,7 +1100,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED if (err.error != Callable::CallError::CALL_OK) { - String methodstr = GDScriptFunctions::get_func_name(func); if (dst->get_type() == Variant::STRING) { //call provided error string @@ -1177,18 +1115,15 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_CALL_SELF) { - OPCODE_BREAK; } OPCODE(OPCODE_CALL_SELF_BASE) { - CHECK_SPACE(2); int self_fun = _code_ptr[ip + 1]; #ifdef DEBUG_ENABLED if (self_fun < 0 || self_fun >= _global_names_count) { - err_text = "compiler bug, function name not found"; OPCODE_BREAK; } @@ -1221,12 +1156,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a Callable::CallError err; if (E) { - *dst = E->get()->call(p_instance, (const Variant **)argptrs, argc, err); } else if (gds->native.ptr()) { - if (*methodname != GDScriptLanguage::get_singleton()->strings._init) { - MethodBind *mb = ClassDB::get_method(gds->native->get_name(), *methodname); if (!mb) { err.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -1237,7 +1169,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a err.error = Callable::CallError::CALL_OK; } } else { - if (*methodname != GDScriptLanguage::get_singleton()->strings._init) { err.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; } else { @@ -1246,7 +1177,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } if (err.error != Callable::CallError::CALL_OK) { - String methodstr = *methodname; err_text = _get_call_error(err, "function '" + methodstr + "'", (const Variant **)argptrs); @@ -1259,7 +1189,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE(OPCODE_YIELD) OPCODE(OPCODE_YIELD_SIGNAL) { - int ipofs = 1; if (_code_ptr[ip] == OPCODE_YIELD_SIGNAL) { CHECK_SPACE(4); @@ -1332,7 +1261,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE_BREAK; } if (signal.length() == 0) { - err_text = "Second argument of yield() is an empty string (for signal name)."; OPCODE_BREAK; } @@ -1358,7 +1286,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } OPCODE(OPCODE_YIELD_RESUME) { - CHECK_SPACE(2); #ifdef DEBUG_ENABLED if (!p_state) { @@ -1373,7 +1300,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_JUMP) { - CHECK_SPACE(2); int to = _code_ptr[ip + 1]; @@ -1383,7 +1309,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_JUMP_IF) { - CHECK_SPACE(3); GET_VARIANT_PTR(test, 1); @@ -1401,7 +1326,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_JUMP_IF_NOT) { - CHECK_SPACE(3); GET_VARIANT_PTR(test, 1); @@ -1419,14 +1343,12 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_JUMP_TO_DEF_ARGUMENT) { - CHECK_SPACE(2); ip = _default_arg_ptr[defarg]; } DISPATCH_OPCODE; OPCODE(OPCODE_RETURN) { - CHECK_SPACE(2); GET_VARIANT_PTR(r, 1); retvalue = *r; @@ -1437,7 +1359,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } OPCODE(OPCODE_ITERATE_BEGIN) { - CHECK_SPACE(8); //space for this a regular iterate GET_VARIANT_PTR(counter, 1); @@ -1470,7 +1391,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a DISPATCH_OPCODE; OPCODE(OPCODE_ITERATE) { - CHECK_SPACE(4); GET_VARIANT_PTR(counter, 1); @@ -1546,7 +1466,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a bool do_break = false; if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) { - if (EngineDebugger::get_script_debugger()->get_depth() <= 0) EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1); if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) @@ -1645,32 +1564,26 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } const int *GDScriptFunction::get_code() const { - return _code_ptr; } int GDScriptFunction::get_code_size() const { - return _code_size; } Variant GDScriptFunction::get_constant(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, constants.size(), "<errconst>"); return constants[p_idx]; } StringName GDScriptFunction::get_global_name(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, global_names.size(), "<errgname>"); return global_names[p_idx]; } int GDScriptFunction::get_default_argument_count() const { - return _default_arg_count; } int GDScriptFunction::get_default_argument_addr(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, default_arguments.size(), -1); return default_arguments[p_idx]; } @@ -1685,45 +1598,37 @@ GDScriptDataType GDScriptFunction::get_argument_type(int p_idx) const { } StringName GDScriptFunction::get_name() const { - return name; } int GDScriptFunction::get_max_stack_size() const { - return _stack_size; } struct _GDFKC { - int order; List<int> pos; }; struct _GDFKCS { - int order; StringName id; int pos; bool operator<(const _GDFKCS &p_r) const { - return order < p_r.order; } }; void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<StringName, int>> *r_stackvars) const { - int oc = 0; Map<StringName, _GDFKC> sdmap; for (const List<StackDebug>::Element *E = stack_debug.front(); E; E = E->next()) { - const StackDebug &sd = E->get(); if (sd.line > p_line) break; if (sd.added) { - if (!sdmap.has(sd.identifier)) { _GDFKC d; d.order = oc++; @@ -1734,7 +1639,6 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String sdmap[sd.identifier].pos.push_back(sd.pos); } } else { - ERR_CONTINUE(!sdmap.has(sd.identifier)); sdmap[sd.identifier].pos.pop_back(); @@ -1745,7 +1649,6 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String List<_GDFKCS> stackpositions; for (Map<StringName, _GDFKC>::Element *E = sdmap.front(); E; E = E->next()) { - _GDFKCS spp; spp.id = E->key(); spp.order = E->get().order; @@ -1756,7 +1659,6 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String stackpositions.sort(); for (List<_GDFKCS>::Element *E = stackpositions.front(); E; E = E->next()) { - Pair<StringName, int> p; p.first = E->get().id; p.second = E->get().pos; @@ -1766,7 +1668,6 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String GDScriptFunction::GDScriptFunction() : function_list(this) { - _stack_size = 0; _call_size = 0; rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; @@ -1805,7 +1706,6 @@ GDScriptFunction::~GDScriptFunction() { ///////////////////// Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - Variant arg; r_error.error = Callable::CallError::CALL_OK; @@ -1838,7 +1738,6 @@ Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_ar } bool GDScriptFunctionState::is_valid(bool p_extended_check) const { - if (function == nullptr) return false; @@ -1859,7 +1758,6 @@ bool GDScriptFunctionState::is_valid(bool p_extended_check) const { } Variant GDScriptFunctionState::resume(const Variant &p_arg) { - ERR_FAIL_COND_V(!function, Variant()); { MutexLock lock(GDScriptLanguage::singleton->lock); @@ -1921,7 +1819,6 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) { } void GDScriptFunctionState::_clear_stack() { - if (state.stack_size) { Variant *stack = (Variant *)state.stack.ptr(); for (int i = 0; i < state.stack_size; i++) @@ -1931,7 +1828,6 @@ void GDScriptFunctionState::_clear_stack() { } void GDScriptFunctionState::_bind_methods() { - ClassDB::bind_method(D_METHOD("resume", "arg"), &GDScriptFunctionState::resume, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("is_valid", "extended_check"), &GDScriptFunctionState::is_valid, DEFVAL(false)); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &GDScriptFunctionState::_signal_callback, MethodInfo("_signal_callback")); @@ -1942,12 +1838,10 @@ void GDScriptFunctionState::_bind_methods() { GDScriptFunctionState::GDScriptFunctionState() : scripts_list(this), instances_list(this) { - function = nullptr; } GDScriptFunctionState::~GDScriptFunctionState() { - _clear_stack(); { diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 7043c9b69b..490da102c0 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -215,7 +215,6 @@ public: }; struct StackDebug { - int line; int pos; bool added; @@ -293,7 +292,6 @@ private: public: struct CallState { - GDScript *script; GDScriptInstance *instance; #ifdef DEBUG_ENABLED @@ -351,7 +349,6 @@ public: }; class GDScriptFunctionState : public Reference { - GDCLASS(GDScriptFunctionState, Reference); friend class GDScriptFunction; GDScriptFunction *function; diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index 85a5d86ca0..5df2c79df5 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -41,7 +41,6 @@ #include "gdscript.h" const char *GDScriptFunctions::get_func_name(Function p_func) { - ERR_FAIL_INDEX_V(p_func, FUNC_MAX, ""); static const char *_names[FUNC_MAX] = { @@ -140,7 +139,6 @@ const char *GDScriptFunctions::get_func_name(Function p_func) { } void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, Variant &r_ret, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; #ifdef DEBUG_ENABLED @@ -176,7 +174,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ //using a switch, so the compiler generates a jumptable switch (p_func) { - case MATH_SIN: { VALIDATE_ARG_COUNT(1); VALIDATE_ARG_NUM(0); @@ -269,15 +266,12 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case MATH_ABS: { VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() == Variant::INT) { - int64_t i = *p_args[0]; r_ret = ABS(i); } else if (p_args[0]->get_type() == Variant::FLOAT) { - double r = *p_args[0]; r_ret = Math::abs(r); } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::FLOAT; @@ -287,15 +281,12 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case MATH_SIGN: { VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() == Variant::INT) { - int64_t i = *p_args[0]; r_ret = i < 0 ? -1 : (i > 0 ? +1 : 0); } else if (p_args[0]->get_type() == Variant::FLOAT) { - real_t r = *p_args[0]; r_ret = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::FLOAT; @@ -505,7 +496,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case LOGIC_MAX: { VALIDATE_ARG_COUNT(2); if (p_args[0]->get_type() == Variant::INT && p_args[1]->get_type() == Variant::INT) { - int64_t a = *p_args[0]; int64_t b = *p_args[1]; r_ret = MAX(a, b); @@ -523,7 +513,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case LOGIC_MIN: { VALIDATE_ARG_COUNT(2); if (p_args[0]->get_type() == Variant::INT && p_args[1]->get_type() == Variant::INT) { - int64_t a = *p_args[0]; int64_t b = *p_args[1]; r_ret = MIN(a, b); @@ -540,7 +529,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case LOGIC_CLAMP: { VALIDATE_ARG_COUNT(3); if (p_args[0]->get_type() == Variant::INT && p_args[1]->get_type() == Variant::INT && p_args[2]->get_type() == Variant::INT) { - int64_t a = *p_args[0]; int64_t b = *p_args[1]; int64_t c = *p_args[2]; @@ -595,7 +583,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case FUNC_FUNCREF: { VALIDATE_ARG_COUNT(2); if (p_args[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -603,7 +590,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ return; } if (p_args[1]->get_type() != Variant::STRING && p_args[1]->get_type() != Variant::NODE_PATH) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; r_error.expected = Variant::STRING; @@ -624,7 +610,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_NUM(1); int type = *p_args[1]; if (type < 0 || type >= Variant::VARIANT_MAX) { - r_ret = RTR("Invalid type argument to convert(), use TYPE_* constants."); r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -632,18 +617,15 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ return; } else { - r_ret = Variant::construct(Variant::Type(type), p_args, 1, r_error); } } break; case TYPE_OF: { - VALIDATE_ARG_COUNT(1); r_ret = p_args[0]->get_type(); } break; case TYPE_EXISTS: { - VALIDATE_ARG_COUNT(1); r_ret = ClassDB::class_exists(*p_args[0]); @@ -655,11 +637,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_ret = String(result); } break; case TEXT_ORD: { - VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() != Variant::STRING) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::STRING; @@ -670,7 +650,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ String str = p_args[0]->operator String(); if (str.length() != 1) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::STRING; @@ -691,7 +670,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } String str; for (int i = 0; i < p_arg_count; i++) { - String os = p_args[i]->operator String(); if (i == 0) @@ -704,10 +682,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case TEXT_PRINT: { - String str; for (int i = 0; i < p_arg_count; i++) { - str += p_args[i]->operator String(); } @@ -716,10 +692,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case TEXT_PRINT_TABBED: { - String str; for (int i = 0; i < p_arg_count; i++) { - if (i) str += "\t"; str += p_args[i]->operator String(); @@ -730,10 +704,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case TEXT_PRINT_SPACED: { - String str; for (int i = 0; i < p_arg_count; i++) { - if (i) str += " "; str += p_args[i]->operator String(); @@ -745,10 +717,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case TEXT_PRINTERR: { - String str; for (int i = 0; i < p_arg_count; i++) { - str += p_args[i]->operator String(); } @@ -759,7 +729,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case TEXT_PRINTRAW: { String str; for (int i = 0; i < p_arg_count; i++) { - str += p_args[i]->operator String(); } @@ -770,7 +739,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case TEXT_PRINT_DEBUG: { String str; for (int i = 0; i < p_arg_count; i++) { - str += p_args[i]->operator String(); } @@ -922,18 +890,14 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case GEN_RANGE: { - switch (p_arg_count) { - case 0: { - r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 1; r_ret = Variant(); } break; case 1: { - VALIDATE_ARG_NUM(0); int count = *p_args[0]; Array arr; @@ -955,7 +919,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_ret = arr; } break; case 2: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); @@ -978,7 +941,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_ret = arr; } break; case 3: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -987,7 +949,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ int to = *p_args[1]; int incr = *p_args[2]; if (incr == 0) { - r_ret = RTR("Step argument is zero!"); r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; return; @@ -1006,10 +967,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ //calculate how many int count = 0; if (incr > 0) { - count = ((to - from - 1) / incr) + 1; } else { - count = ((from - to - 1) / -incr) + 1; } @@ -1027,7 +986,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ arr[idx++] = i; } } else { - int idx = 0; for (int i = from; i > to; i += incr) { arr[idx++] = i; @@ -1037,7 +995,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_ret = arr; } break; default: { - r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS; r_error.argument = 3; r_ret = Variant(); @@ -1059,7 +1016,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case INST2DICT: { - VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() == Variant::NIL) { @@ -1069,24 +1025,20 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_error.argument = 0; r_ret = Variant(); } else { - Object *obj = *p_args[0]; if (!obj) { r_ret = Variant(); } else if (!obj->get_script_instance() || obj->get_script_instance()->get_language() != GDScriptLanguage::get_singleton()) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::DICTIONARY; r_ret = RTR("Not a script with an instance"); return; } else { - GDScriptInstance *ins = static_cast<GDScriptInstance *>(obj->get_script_instance()); Ref<GDScript> base = ins->get_script(); if (base.is_null()) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::DICTIONARY; @@ -1098,7 +1050,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ Vector<StringName> sname; while (p->_owner) { - sname.push_back(p->name); p = p->_owner; } @@ -1132,11 +1083,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case DICT2INST: { - VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() != Variant::DICTIONARY) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::DICTIONARY; @@ -1148,7 +1097,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ Dictionary d = *p_args[0]; if (!d.has("@path")) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -1159,7 +1107,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ Ref<Script> scr = ResourceLoader::load(d["@path"]); if (!scr.is_valid()) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -1170,7 +1117,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ Ref<GDScript> gdscr = scr; if (!gdscr.is_valid()) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -1185,10 +1131,8 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } for (int i = 0; i < sub.get_name_count(); i++) { - gdscr = gdscr->subclasses[sub.get_name(i)]; if (!gdscr.is_valid()) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -1215,7 +1159,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case VALIDATE_JSON: { - VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() != Variant::STRING) { @@ -1239,7 +1182,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case PARSE_JSON: { - VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() != Variant::STRING) { @@ -1267,13 +1209,11 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_ret = JSON::print(*p_args[0]); } break; case HASH: { - VALIDATE_ARG_COUNT(1); r_ret = p_args[0]->hash(); } break; case COLOR8: { - if (p_arg_count < 3) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 3; @@ -1304,7 +1244,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case COLORN: { - if (p_arg_count < 1) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 1; @@ -1339,7 +1278,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ ScriptLanguage *script = GDScriptLanguage::get_singleton(); for (int i = 0; i < script->debug_get_stack_level_count(); i++) { - print_line("Frame " + itos(i) + " - " + script->debug_get_stack_level_source(i) + ":" + itos(script->debug_get_stack_level_line(i)) + " in function '" + script->debug_get_stack_level_function(i) + "'"); }; } break; @@ -1350,7 +1288,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ ScriptLanguage *script = GDScriptLanguage::get_singleton(); Array ret; for (int i = 0; i < script->debug_get_stack_level_count(); i++) { - Dictionary frame; frame["source"] = script->debug_get_stack_level_source(i); frame["function"] = script->debug_get_stack_level_function(i); @@ -1361,7 +1298,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case INSTANCE_FROM_ID: { - VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() != Variant::INT && p_args[0]->get_type() != Variant::FLOAT) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; @@ -1376,66 +1312,53 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case LEN: { - VALIDATE_ARG_COUNT(1); switch (p_args[0]->get_type()) { case Variant::STRING: { - String d = *p_args[0]; r_ret = d.length(); } break; case Variant::DICTIONARY: { - Dictionary d = *p_args[0]; r_ret = d.size(); } break; case Variant::ARRAY: { - Array d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_BYTE_ARRAY: { - Vector<uint8_t> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_INT32_ARRAY: { - Vector<int32_t> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_INT64_ARRAY: { - Vector<int64_t> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_FLOAT32_ARRAY: { - Vector<float> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_FLOAT64_ARRAY: { - Vector<double> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_STRING_ARRAY: { - Vector<String> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_VECTOR2_ARRAY: { - Vector<Vector2> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_VECTOR3_ARRAY: { - Vector<Vector3> d = *p_args[0]; r_ret = d.size(); } break; case Variant::PACKED_COLOR_ARRAY: { - Vector<Color> d = *p_args[0]; r_ret = d.size(); } break; @@ -1450,7 +1373,6 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case IS_INSTANCE_VALID: { - VALIDATE_ARG_COUNT(1); if (p_args[0]->get_type() != Variant::OBJECT) { r_ret = false; @@ -1461,19 +1383,16 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } break; case FUNC_MAX: { - ERR_FAIL(); } break; } } bool GDScriptFunctions::is_deterministic(Function p_func) { - //man i couldn't have chosen a worse function name, //way too controversial.. switch (p_func) { - case MATH_SIN: case MATH_COS: case MATH_TAN: @@ -1537,12 +1456,10 @@ bool GDScriptFunctions::is_deterministic(Function p_func) { } MethodInfo GDScriptFunctions::get_info(Function p_func) { - #ifdef DEBUG_ENABLED //using a switch, so the compiler generates a jumptable switch (p_func) { - case MATH_SIN: { MethodInfo mi("sin", PropertyInfo(Variant::FLOAT, "s")); mi.return_val.type = Variant::FLOAT; @@ -1817,7 +1734,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { return mi; } break; case OBJ_WEAKREF: { - MethodInfo mi("weakref", PropertyInfo(Variant::OBJECT, "obj")); mi.return_val.type = Variant::OBJECT; mi.return_val.class_name = "WeakRef"; @@ -1826,7 +1742,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case FUNC_FUNCREF: { - MethodInfo mi("funcref", PropertyInfo(Variant::OBJECT, "instance"), PropertyInfo(Variant::STRING, "funcname")); mi.return_val.type = Variant::OBJECT; mi.return_val.class_name = "FuncRef"; @@ -1834,42 +1749,36 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case TYPE_CONVERT: { - MethodInfo mi("convert", PropertyInfo(Variant::NIL, "what", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT), PropertyInfo(Variant::INT, "type")); mi.return_val.type = Variant::NIL; mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; return mi; } break; case TYPE_OF: { - MethodInfo mi("typeof", PropertyInfo(Variant::NIL, "what", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT)); mi.return_val.type = Variant::INT; return mi; } break; case TYPE_EXISTS: { - MethodInfo mi("type_exists", PropertyInfo(Variant::STRING, "type")); mi.return_val.type = Variant::BOOL; return mi; } break; case TEXT_CHAR: { - MethodInfo mi("char", PropertyInfo(Variant::INT, "code")); mi.return_val.type = Variant::STRING; return mi; } break; case TEXT_ORD: { - MethodInfo mi("ord", PropertyInfo(Variant::STRING, "char")); mi.return_val.type = Variant::INT; return mi; } break; case TEXT_STR: { - MethodInfo mi("str"); mi.return_val.type = Variant::STRING; mi.flags |= METHOD_FLAG_VARARG; @@ -1877,7 +1786,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case TEXT_PRINT: { - MethodInfo mi("print"); mi.return_val.type = Variant::NIL; mi.flags |= METHOD_FLAG_VARARG; @@ -1885,7 +1793,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case TEXT_PRINT_TABBED: { - MethodInfo mi("printt"); mi.return_val.type = Variant::NIL; mi.flags |= METHOD_FLAG_VARARG; @@ -1893,7 +1800,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case TEXT_PRINT_SPACED: { - MethodInfo mi("prints"); mi.return_val.type = Variant::NIL; mi.flags |= METHOD_FLAG_VARARG; @@ -1901,7 +1807,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case TEXT_PRINTERR: { - MethodInfo mi("printerr"); mi.return_val.type = Variant::NIL; mi.flags |= METHOD_FLAG_VARARG; @@ -1909,7 +1814,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case TEXT_PRINTRAW: { - MethodInfo mi("printraw"); mi.return_val.type = Variant::NIL; mi.flags |= METHOD_FLAG_VARARG; @@ -1917,7 +1821,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case TEXT_PRINT_DEBUG: { - MethodInfo mi("print_debug"); mi.return_val.type = Variant::NIL; mi.flags |= METHOD_FLAG_VARARG; @@ -1925,41 +1828,35 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { } break; case PUSH_ERROR: { - MethodInfo mi(Variant::NIL, "push_error", PropertyInfo(Variant::STRING, "message")); mi.return_val.type = Variant::NIL; return mi; } break; case PUSH_WARNING: { - MethodInfo mi(Variant::NIL, "push_warning", PropertyInfo(Variant::STRING, "message")); mi.return_val.type = Variant::NIL; return mi; } break; case VAR_TO_STR: { - MethodInfo mi("var2str", PropertyInfo(Variant::NIL, "var", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT)); mi.return_val.type = Variant::STRING; return mi; } break; case STR_TO_VAR: { - MethodInfo mi(Variant::NIL, "str2var", PropertyInfo(Variant::STRING, "string")); mi.return_val.type = Variant::NIL; mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; return mi; } break; case VAR_TO_BYTES: { - MethodInfo mi("var2bytes", PropertyInfo(Variant::NIL, "var", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT), PropertyInfo(Variant::BOOL, "full_objects")); mi.default_arguments.push_back(false); mi.return_val.type = Variant::PACKED_BYTE_ARRAY; return mi; } break; case BYTES_TO_VAR: { - MethodInfo mi(Variant::NIL, "bytes2var", PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytes"), PropertyInfo(Variant::BOOL, "allow_objects")); mi.default_arguments.push_back(false); mi.return_val.type = Variant::NIL; @@ -1967,65 +1864,55 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { return mi; } break; case GEN_RANGE: { - MethodInfo mi("range"); mi.return_val.type = Variant::ARRAY; mi.flags |= METHOD_FLAG_VARARG; return mi; } break; case RESOURCE_LOAD: { - MethodInfo mi("load", PropertyInfo(Variant::STRING, "path")); mi.return_val.type = Variant::OBJECT; mi.return_val.class_name = "Resource"; return mi; } break; case INST2DICT: { - MethodInfo mi("inst2dict", PropertyInfo(Variant::OBJECT, "inst")); mi.return_val.type = Variant::DICTIONARY; return mi; } break; case DICT2INST: { - MethodInfo mi("dict2inst", PropertyInfo(Variant::DICTIONARY, "dict")); mi.return_val.type = Variant::OBJECT; return mi; } break; case VALIDATE_JSON: { - MethodInfo mi("validate_json", PropertyInfo(Variant::STRING, "json")); mi.return_val.type = Variant::STRING; return mi; } break; case PARSE_JSON: { - MethodInfo mi(Variant::NIL, "parse_json", PropertyInfo(Variant::STRING, "json")); mi.return_val.type = Variant::NIL; mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; return mi; } break; case TO_JSON: { - MethodInfo mi("to_json", PropertyInfo(Variant::NIL, "var", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT)); mi.return_val.type = Variant::STRING; return mi; } break; case HASH: { - MethodInfo mi("hash", PropertyInfo(Variant::NIL, "var", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT)); mi.return_val.type = Variant::INT; return mi; } break; case COLOR8: { - MethodInfo mi("Color8", PropertyInfo(Variant::INT, "r8"), PropertyInfo(Variant::INT, "g8"), PropertyInfo(Variant::INT, "b8"), PropertyInfo(Variant::INT, "a8")); mi.default_arguments.push_back(255); mi.return_val.type = Variant::COLOR; return mi; } break; case COLORN: { - MethodInfo mi("ColorN", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::FLOAT, "alpha")); mi.default_arguments.push_back(1.0f); mi.return_val.type = Variant::COLOR; @@ -2059,7 +1946,6 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { return mi; } break; default: { - ERR_FAIL_V(MethodInfo()); } break; } diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 8cc6986f34..1c07efaa3a 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -42,7 +42,6 @@ template <class T> T *GDScriptParser::alloc_node() { - T *t = memnew(T); t->next = list; @@ -61,7 +60,6 @@ static String _find_function_name(const GDScriptParser::OperatorNode *p_call); #endif // DEBUG_ENABLED bool GDScriptParser::_end_statement() { - if (tokenizer->get_token() == GDScriptTokenizer::TK_SEMICOLON) { tokenizer->advance(); return true; //handle next @@ -83,7 +81,6 @@ void GDScriptParser::_set_end_statement_error(String p_name) { } bool GDScriptParser::_enter_indent_block(BlockNode *p_block) { - if (tokenizer->get_token() != GDScriptTokenizer::TK_COLON) { // report location at the previous token (on the previous line) int error_line = tokenizer->get_token_line(-1); @@ -108,12 +105,10 @@ bool GDScriptParser::_enter_indent_block(BlockNode *p_block) { while (true) { if (tokenizer->get_token() != GDScriptTokenizer::TK_NEWLINE) { - return false; //wtf } else if (tokenizer->get_token(1) == GDScriptTokenizer::TK_EOF) { return false; } else if (tokenizer->get_token(1) != GDScriptTokenizer::TK_NEWLINE) { - int indent = tokenizer->get_token_line_indent(); int tabs = tokenizer->get_token_line_tab_indent(); IndentLevel current_level = indent_level.back()->get(); @@ -132,7 +127,6 @@ bool GDScriptParser::_enter_indent_block(BlockNode *p_block) { return true; } else if (p_block) { - NewLineNode *nl = alloc_node<NewLineNode>(); nl->line = tokenizer->get_token_line(); p_block->statements.push_back(nl); @@ -143,16 +137,13 @@ bool GDScriptParser::_enter_indent_block(BlockNode *p_block) { } bool GDScriptParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_static, bool p_can_codecomplete, bool p_parsing_constant) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { tokenizer->advance(); } else { - parenthesis++; int argidx = 0; while (true) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { _make_completable_call(argidx); completion_node = p_parent; @@ -178,9 +169,7 @@ bool GDScriptParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bo break; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { - if (tokenizer->get_token(1) == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { - _set_error("Expression expected"); return false; } @@ -200,7 +189,6 @@ bool GDScriptParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bo } void GDScriptParser::_make_completable_call(int p_arg) { - completion_cursor = StringName(); completion_type = COMPLETION_CALL_ARGUMENTS; completion_class = current_class; @@ -213,14 +201,12 @@ void GDScriptParser::_make_completable_call(int p_arg) { } bool GDScriptParser::_get_completable_identifier(CompletionType p_type, StringName &identifier) { - identifier = StringName(); if (tokenizer->is_token_literal()) { identifier = tokenizer->get_token_literal(); tokenizer->advance(); } if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { - completion_cursor = identifier; completion_type = p_type; completion_class = current_class; @@ -246,7 +232,6 @@ bool GDScriptParser::_get_completable_identifier(CompletionType p_type, StringNa } GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_static, bool p_allow_assign, bool p_parsing_constant) { - //Vector<Node*> expressions; //Vector<OperatorNode::Operator> operators; @@ -257,7 +242,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s int op_line = tokenizer->get_token_line(); // when operators are created at the bottom, the line might have been changed (\n found) while (true) { - /*****************/ /* Parse Operand */ /*****************/ @@ -289,7 +273,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s return nullptr; if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { - _set_error("Expected ')' in expression"); return nullptr; } @@ -306,7 +289,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s int line = tokenizer->get_token_line(); while (!done) { - switch (tokenizer->get_token()) { case GDScriptTokenizer::TK_CURSOR: { completion_type = COMPLETION_GET_NODE; @@ -320,7 +302,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); } break; case GDScriptTokenizer::TK_CONSTANT: { - if (!need_identifier) { done = true; break; @@ -337,7 +318,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } break; case GDScriptTokenizer::TK_OP_DIV: { - if (need_identifier) { done = true; break; @@ -392,7 +372,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s continue; //no point in cursor in the middle of expression } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT) { - //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = tokenizer->get_token_constant(); @@ -400,7 +379,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); expr = constant; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONST_PI) { - //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = Math_PI; @@ -408,7 +386,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); expr = constant; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONST_TAU) { - //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = Math_TAU; @@ -416,7 +393,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); expr = constant; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONST_INF) { - //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = Math_INF; @@ -424,7 +400,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); expr = constant; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONST_NAN) { - //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = Math_NAN; @@ -432,7 +407,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); expr = constant; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_PRELOAD) { - //constant defined by tokenizer tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) { @@ -493,7 +467,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s path = base_path.plus_file(path); path = path.replace("///", "//").simplify_path(); if (path == self_path) { - _set_error("Can't preload itself (use 'get_script()')."); return nullptr; } @@ -502,7 +475,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s dependencies.push_back(path); if (!dependencies_only) { if (!validating) { - //this can be too slow for just validating code if (for_completion && ScriptCodeCompletionCache::get_singleton() && FileAccess::exists(path)) { res = ScriptCodeCompletionCache::get_singleton()->get_cached_resource(path); @@ -510,7 +482,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s res = ResourceLoader::load(path); } } else { - if (!FileAccess::exists(path)) { _set_error("Can't preload resource at path: " + path); return nullptr; @@ -543,7 +514,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s expr = constant; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_YIELD) { - if (!current_function) { _set_error("\"yield()\" can only be used inside function blocks."); return nullptr; @@ -570,7 +540,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s expr = yield; tokenizer->advance(); } else { - parenthesis++; Node *object = _parse_and_reduce_expression(p_parent, p_static); @@ -586,7 +555,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { - completion_cursor = StringName(); completion_node = object; completion_type = COMPLETION_YIELD; @@ -617,7 +585,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } } else if (tokenizer->get_token() == GDScriptTokenizer::TK_SELF) { - if (p_static) { _set_error("\"self\" isn't allowed in a static function or constant expression."); return nullptr; @@ -627,28 +594,23 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); expr = self; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token(1) == GDScriptTokenizer::TK_PERIOD) { - Variant::Type bi_type = tokenizer->get_token_type(); tokenizer->advance(2); StringName identifier; if (_get_completable_identifier(COMPLETION_BUILT_IN_TYPE_CONSTANT, identifier)) { - completion_built_in_constant = bi_type; } if (identifier == StringName()) { - _set_error("Built-in type constant or static function expected after \".\"."); return nullptr; } if (!Variant::has_constant(bi_type, identifier)) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN && Variant::is_method_const(bi_type, identifier) && Variant::get_method_return_type(bi_type, identifier) == bi_type) { - tokenizer->advance(); OperatorNode *construct = alloc_node<OperatorNode>(); @@ -688,7 +650,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } } } else { - ConstantNode *cn = alloc_node<ConstantNode>(); cn->value = Variant::get_constant_value(bi_type, identifier); cn->datatype = _type_from_variant(cn->value); @@ -733,13 +694,11 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(2); } } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC) { - BuiltInFunctionNode *bn = alloc_node<BuiltInFunctionNode>(); bn->function = tokenizer->get_token_built_in_func(); op->arguments.push_back(bn); tokenizer->advance(2); } else { - SelfNode *self = alloc_node<SelfNode>(); op->arguments.push_back(self); @@ -913,7 +872,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } } else if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ADD || tokenizer->get_token() == GDScriptTokenizer::TK_OP_SUB || tokenizer->get_token() == GDScriptTokenizer::TK_OP_NOT || tokenizer->get_token() == GDScriptTokenizer::TK_OP_BIT_INVERT) { - //single prefix operators like !expr +expr -expr ++expr --expr alloc_node<OperatorNode>(); Expression e; @@ -979,9 +937,7 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s bool expecting_comma = false; while (true) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_EOF) { - _set_error("Unterminated array"); return nullptr; @@ -989,7 +945,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); break; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { - tokenizer->advance(); //ignore newline } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { if (!expecting_comma) { @@ -1035,14 +990,11 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s DictExpect expecting = DICT_EXPECT_KEY; while (true) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_EOF) { - _set_error("Unterminated dictionary"); return nullptr; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { - if (expecting == DICT_EXPECT_COLON) { _set_error("':' expected"); return nullptr; @@ -1054,10 +1006,8 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); break; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { - tokenizer->advance(); //ignore newline } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { - if (expecting == DICT_EXPECT_KEY) { _set_error("key or '}' expected"); return nullptr; @@ -1075,7 +1025,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(); //ignore newline } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COLON) { - if (expecting == DICT_EXPECT_KEY) { _set_error("key or '}' expected"); return nullptr; @@ -1092,7 +1041,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s expecting = DICT_EXPECT_VALUE; tokenizer->advance(); //ignore newline } else { - if (expecting == DICT_EXPECT_COMMA) { _set_error("',' or '}' expected"); return nullptr; @@ -1103,7 +1051,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } if (expecting == DICT_EXPECT_KEY) { - if (tokenizer->is_token_literal() && tokenizer->get_token(1) == GDScriptTokenizer::TK_OP_ASSIGN) { // We check with is_token_literal, as this allows us to use match/sync/etc. as a name //lua style identifier, easier to write @@ -1191,7 +1138,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s expr = tn; tokenizer->advance(); } else { - //find list [ or find dictionary { _set_error("Error parsing expression, misplaced: " + String(tokenizer->get_token_name(tokenizer->get_token()))); return nullptr; //nothing @@ -1204,11 +1150,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s /******************/ while (true) { - //expressions can be indexed any number of times if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD) { - //indexing using "." if (tokenizer->get_token(1) != GDScriptTokenizer::TK_CURSOR && !tokenizer->is_token_literal(1)) { @@ -1252,7 +1196,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s StringName identifier; if (_get_completable_identifier(COMPLETION_INDEX, identifier)) { - if (identifier == StringName()) { identifier = "@temp"; //so it parses alright } @@ -1478,16 +1421,13 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s /* Reduce the set set of expressions and place them in an operator tree, respecting precedence */ while (expression.size() > 1) { - int next_op = -1; int min_priority = 0xFFFFF; bool is_unary = false; bool is_ternary = false; for (int i = 0; i < expression.size(); i++) { - if (!expression[i].is_op) { - continue; } @@ -1499,7 +1439,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s bool right_to_left = false; switch (expression[i].op) { - case OperatorNode::OP_IS: case OperatorNode::OP_IS_BUILTIN: priority = -1; @@ -1650,17 +1589,14 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } if (next_op == -1) { - _set_error("Yet another parser bug...."); ERR_FAIL_V(nullptr); } // OK! create operator.. if (is_unary) { - int expr_pos = next_op; while (expression[expr_pos].is_op) { - expr_pos++; if (expr_pos == expression.size()) { //can happen.. @@ -1671,7 +1607,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { - OperatorNode *op = alloc_node<OperatorNode>(); op->op = expression[i].op; op->arguments.push_back(expression[i + 1].node); @@ -1701,7 +1636,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s op->line = op_line; //line might have been changed from a \n if (expression[next_op - 1].is_op) { - _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } @@ -1737,7 +1671,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s expression.remove(next_op); expression.remove(next_op); } else { - if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(nullptr); @@ -1748,7 +1681,6 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s op->line = op_line; //line might have been changed from a \n if (expression[next_op - 1].is_op) { - _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } @@ -1777,20 +1709,16 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to_const) { - switch (p_node->type) { - case Node::TYPE_BUILT_IN_FUNCTION: { //many may probably be optimizable return p_node; } break; case Node::TYPE_ARRAY: { - ArrayNode *an = static_cast<ArrayNode *>(p_node); bool all_constants = true; for (int i = 0; i < an->elements.size(); i++) { - an->elements.write[i] = _reduce_expression(an->elements[i], p_to_const); if (an->elements[i]->type != Node::TYPE_CONSTANT) all_constants = false; @@ -1815,12 +1743,10 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to } break; case Node::TYPE_DICTIONARY: { - DictionaryNode *dn = static_cast<DictionaryNode *>(p_node); bool all_constants = true; for (int i = 0; i < dn->elements.size(); i++) { - dn->elements.write[i].key = _reduce_expression(dn->elements[i].key, p_to_const); if (dn->elements[i].key->type != Node::TYPE_CONSTANT) all_constants = false; @@ -1849,14 +1775,12 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to } break; case Node::TYPE_OPERATOR: { - OperatorNode *op = static_cast<OperatorNode *>(p_node); bool all_constants = true; int last_not_constant = -1; for (int i = 0; i < op->arguments.size(); i++) { - op->arguments.write[i] = _reduce_expression(op->arguments[i], p_to_const); if (op->arguments[i]->type != Node::TYPE_CONSTANT) { all_constants = false; @@ -1875,15 +1799,12 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to } else if (op->op == OperatorNode::OP_CALL) { //can reduce base type constructors if ((op->arguments[0]->type == Node::TYPE_TYPE || (op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && GDScriptFunctions::is_deterministic(static_cast<BuiltInFunctionNode *>(op->arguments[0])->function))) && last_not_constant == 0) { - //native type constructor or intrinsic function const Variant **vptr = nullptr; Vector<Variant *> ptrs; if (op->arguments.size() > 1) { - ptrs.resize(op->arguments.size() - 1); for (int i = 0; i < ptrs.size(); i++) { - ConstantNode *cn = static_cast<ConstantNode *>(op->arguments[i + 1]); ptrs.write[i] = &cn->value; } @@ -1904,7 +1825,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to } if (ce.error != Callable::CallError::CALL_OK) { - String errwhere; if (op->arguments[0]->type == Node::TYPE_TYPE) { TypeNode *tn = static_cast<TypeNode *>(op->arguments[0]); @@ -1916,18 +1836,14 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to } switch (ce.error) { - case Callable::CallError::CALL_ERROR_INVALID_ARGUMENT: { - _set_error("Invalid argument (#" + itos(ce.argument + 1) + ") for " + errwhere + "."); } break; case Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: { - _set_error("Too many arguments for " + errwhere + "."); } break; case Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: { - _set_error("Too few arguments for " + errwhere + "."); } break; default: { @@ -1956,7 +1872,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to //can reduce indices into constant arrays or dictionaries if (all_constants) { - ConstantNode *ca = static_cast<ConstantNode *>(op->arguments[0]); ConstantNode *cb = static_cast<ConstantNode *>(op->arguments[1]); @@ -1978,9 +1893,7 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to return op; } else if (op->op == OperatorNode::OP_INDEX_NAMED) { - if (op->arguments[0]->type == Node::TYPE_CONSTANT && op->arguments[1]->type == Node::TYPE_IDENTIFIER) { - ConstantNode *ca = static_cast<ConstantNode *>(op->arguments[0]); IdentifierNode *ib = static_cast<IdentifierNode *>(op->arguments[1]); @@ -2003,7 +1916,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to //validate assignment (don't assign to constant expression switch (op->op) { - case OperatorNode::OP_ASSIGN: case OperatorNode::OP_ASSIGN_ADD: case OperatorNode::OP_ASSIGN_SUB: @@ -2015,7 +1927,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to case OperatorNode::OP_ASSIGN_BIT_AND: case OperatorNode::OP_ASSIGN_BIT_OR: case OperatorNode::OP_ASSIGN_BIT_XOR: { - if (op->arguments[0]->type == Node::TYPE_CONSTANT) { _set_error("Can't assign to constant", tokenizer->get_token_line() - 1); error_line = op->line; @@ -2072,7 +1983,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to return cn; switch (op->op) { - //unary operators case OperatorNode::OP_NEG: { _REDUCE_UNARY(Variant::OP_NEGATE); @@ -2164,7 +2074,6 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to } GDScriptParser::Node *GDScriptParser::_parse_and_reduce_expression(Node *p_parent, bool p_static, bool p_reduce_const, bool p_allow_assign) { - Node *expr = _parse_expression(p_parent, p_static, p_allow_assign, p_reduce_const); if (!expr || error_set) return nullptr; @@ -2175,7 +2084,6 @@ GDScriptParser::Node *GDScriptParser::_parse_and_reduce_expression(Node *p_paren } bool GDScriptParser::_reduce_export_var_type(Variant &p_value, int p_line) { - if (p_value.get_type() == Variant::ARRAY) { Array arr = p_value; for (int i = 0; i < arr.size(); i++) { @@ -2209,7 +2117,6 @@ bool GDScriptParser::_reduce_export_var_type(Variant &p_value, int p_line) { } bool GDScriptParser::_recover_from_completion() { - if (!completion_found) { return false; //can't recover if no completion } @@ -2227,7 +2134,6 @@ bool GDScriptParser::_recover_from_completion() { } GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) { - PatternNode *pattern = alloc_node<PatternNode>(); GDScriptTokenizer::Token token = tokenizer->get_token(); @@ -2244,7 +2150,6 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) { tokenizer->advance(); pattern->pt_type = GDScriptParser::PatternNode::PT_ARRAY; while (true) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_BRACKET_CLOSE) { tokenizer->advance(); break; @@ -2316,7 +2221,6 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) { tokenizer->advance(); pattern->pt_type = GDScriptParser::PatternNode::PT_DICTIONARY; while (true) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { tokenizer->advance(); break; @@ -2429,7 +2333,6 @@ void GDScriptParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBran bool catch_all_appeared = false; while (true) { - while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) ; @@ -2507,12 +2410,10 @@ void GDScriptParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBran } void GDScriptParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node *> &p_bindings) { - const DataType &to_match_type = p_node_to_match->get_datatype(); switch (p_pattern->pt_type) { case PatternNode::PT_CONSTANT: { - DataType pattern_type = _reduce_node_type(p_pattern->constant); if (error_set) { return; @@ -2576,7 +2477,6 @@ void GDScriptParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_m p_resulting_node = true_value; } break; case PatternNode::PT_ARRAY: { - bool open_ended = false; if (p_pattern->array.size() > 0) { @@ -2673,7 +2573,6 @@ void GDScriptParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_m } break; case PatternNode::PT_DICTIONARY: { - bool open_ended = false; if (p_pattern->array.size() > 0) { @@ -2742,7 +2641,6 @@ void GDScriptParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_m } for (Map<ConstantNode *, PatternNode *>::Element *e = p_pattern->dictionary.front(); e; e = e->next()) { - Node *condition = nullptr; // check for has, then for pattern @@ -2757,7 +2655,6 @@ void GDScriptParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_m has_call->arguments.push_back(e->key()); if (e->value()) { - OperatorNode *indexed_value = alloc_node<OperatorNode>(); indexed_value->op = OperatorNode::OP_INDEX; indexed_value->arguments.push_back(p_node_to_match); @@ -2795,7 +2692,6 @@ void GDScriptParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_m p_resulting_node = true_value; } break; default: { - } break; } } @@ -2816,7 +2712,6 @@ void GDScriptParser::_transform_match_statment(MatchNode *p_match_statement) { } for (int i = 0; i < p_match_statement->branches.size(); i++) { - PatternBranchNode *branch = p_match_statement->branches[i]; MatchNode::CompiledPatternBranch compiled_branch; @@ -2899,7 +2794,6 @@ void GDScriptParser::_transform_match_statment(MatchNode *p_match_statement) { } void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { - IndentLevel current_level = indent_level.back()->get(); #ifdef DEBUG_ENABLED @@ -2935,7 +2829,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } if (pending_newline != -1) { - NewLineNode *nl2 = alloc_node<NewLineNode>(); nl2->line = pending_newline; p_block->statements.push_back(nl2); @@ -2967,7 +2860,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { return; } break; case GDScriptTokenizer::TK_NEWLINE: { - int line = tokenizer->get_token_line(); if (!_parse_newline()) { @@ -2986,7 +2878,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } break; case GDScriptTokenizer::TK_CF_PASS: { if (tokenizer->get_token(1) != GDScriptTokenizer::TK_SEMICOLON && tokenizer->get_token(1) != GDScriptTokenizer::TK_NEWLINE && tokenizer->get_token(1) != GDScriptTokenizer::TK_EOF) { - _set_error("Expected \";\" or a line break."); return; } @@ -3003,7 +2894,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { tokenizer->advance(); int var_line = tokenizer->get_token_line(); if (!tokenizer->is_token_literal(0, true)) { - _set_error("Expected an identifier for the local variable name."); return; } @@ -3048,7 +2938,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { - tokenizer->advance(); Node *subexpr = _parse_and_reduce_expression(p_block, p_static); if (!subexpr) { @@ -3061,7 +2950,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { lv->assignments++; assigned = subexpr; } else { - assigned = _get_default_value_for_type(lv->datatype, var_line); } //must be added later, to avoid self-referencing. @@ -3088,7 +2976,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } break; case GDScriptTokenizer::TK_CF_IF: { - tokenizer->advance(); Node *condition = _parse_and_reduce_expression(p_block, p_static); @@ -3128,7 +3015,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { bool have_else = false; while (true) { - while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) ; @@ -3138,9 +3024,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_CF_ELIF) { - if (indent_level.back()->get().indent > current_level.indent) { - _set_error("Invalid indentation."); return; } @@ -3186,7 +3070,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { all_have_return = all_have_return && cf_else->body->has_return; } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CF_ELSE) { - if (indent_level.back()->get().indent > current_level.indent) { _set_error("Invalid indentation."); return; @@ -3223,7 +3106,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } break; case GDScriptTokenizer::TK_CF_WHILE: { - tokenizer->advance(); Node *condition2 = _parse_and_reduce_expression(p_block, p_static); if (!condition2) { @@ -3257,11 +3139,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { p_block->statements.push_back(cf_while); } break; case GDScriptTokenizer::TK_CF_FOR: { - tokenizer->advance(); if (!tokenizer->is_token_literal(0, true)) { - _set_error("Identifier expected after \"for\"."); } @@ -3288,7 +3168,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { DataType iter_type; if (container->type == Node::TYPE_OPERATOR) { - OperatorNode *op = static_cast<OperatorNode *>(container); if (op->op == OperatorNode::OP_CALL && op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && static_cast<BuiltInFunctionNode *>(op->arguments[0])->function == GDScriptFunctions::GEN_RANGE) { //iterating a range, so see if range() can be optimized without allocating memory, by replacing it by vectors (which can work as iterable too!) @@ -3313,9 +3192,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } if (args.size() > 0 && args.size() < 4) { - if (constant) { - ConstantNode *cn = alloc_node<ConstantNode>(); switch (args.size()) { case 1: @@ -3400,7 +3277,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { p_block->statements.push_back(cf_for); } break; case GDScriptTokenizer::TK_CF_CONTINUE: { - _mark_line_as_safe(tokenizer->get_token_line()); tokenizer->advance(); ControlFlowNode *cf_continue = alloc_node<ControlFlowNode>(); @@ -3412,7 +3288,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } } break; case GDScriptTokenizer::TK_CF_BREAK: { - _mark_line_as_safe(tokenizer->get_token_line()); tokenizer->advance(); ControlFlowNode *cf_break = alloc_node<ControlFlowNode>(); @@ -3424,7 +3299,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } } break; case GDScriptTokenizer::TK_CF_RETURN: { - tokenizer->advance(); ControlFlowNode *cf_return = alloc_node<ControlFlowNode>(); cf_return->cf_type = ControlFlowNode::CF_RETURN; @@ -3456,7 +3330,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } break; case GDScriptTokenizer::TK_CF_MATCH: { - tokenizer->advance(); MatchNode *match_node = alloc_node<MatchNode>(); @@ -3499,7 +3372,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { _end_statement(); } break; case GDScriptTokenizer::TK_PR_ASSERT: { - tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) { @@ -3543,7 +3415,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } } break; case GDScriptTokenizer::TK_PR_BREAKPOINT: { - tokenizer->advance(); BreakpointNode *bn = alloc_node<BreakpointNode>(); p_block->statements.push_back(bn); @@ -3554,7 +3425,6 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } } break; default: { - Node *expression = _parse_and_reduce_expression(p_block, p_static, false, true); if (!expression) { if (_recover_from_completion()) { @@ -3579,9 +3449,7 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { } bool GDScriptParser::_parse_newline() { - if (tokenizer->get_token(1) != GDScriptTokenizer::TK_EOF && tokenizer->get_token(1) != GDScriptTokenizer::TK_NEWLINE) { - IndentLevel current_level = indent_level.back()->get(); int indent = tokenizer->get_token_line_indent(); int tabs = tokenizer->get_token_line_tab_indent(); @@ -3598,9 +3466,7 @@ bool GDScriptParser::_parse_newline() { } if (indent < current_level.indent) { - while (indent < current_level.indent) { - //exit block if (indent_level.size() == 1) { _set_error("Invalid indentation. Bug?"); @@ -3610,7 +3476,6 @@ bool GDScriptParser::_parse_newline() { indent_level.pop_back(); if (indent_level.back()->get().indent < indent) { - _set_error("Unindent does not match any outer indentation level."); return false; } @@ -3633,15 +3498,12 @@ bool GDScriptParser::_parse_newline() { } void GDScriptParser::_parse_extends(ClassNode *p_class) { - if (p_class->extends_used) { - _set_error("\"extends\" can only be present once per script."); return; } if (!p_class->constant_expressions.empty() || !p_class->subclasses.empty() || !p_class->functions.empty() || !p_class->variables.empty()) { - _set_error("\"extends\" must be used before anything else."); return; } @@ -3658,10 +3520,8 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { // see if inheritance happens from a file if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT) { - Variant constant = tokenizer->get_token_constant(); if (constant.get_type() != Variant::STRING) { - _set_error("\"extends\" constant must be a string."); return; } @@ -3683,11 +3543,8 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { } while (true) { - switch (tokenizer->get_token()) { - case GDScriptTokenizer::TK_IDENTIFIER: { - StringName identifier = tokenizer->get_token_identifier(); p_class->extends_class.push_back(identifier); } break; @@ -3696,7 +3553,6 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { break; default: { - _set_error("Invalid \"extends\" syntax, expected string constant (path) and/or identifier (parent class)."); return; } @@ -3705,7 +3561,6 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { tokenizer->advance(1); switch (tokenizer->get_token()) { - case GDScriptTokenizer::TK_IDENTIFIER: case GDScriptTokenizer::TK_PERIOD: continue; @@ -3717,11 +3572,9 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { } void GDScriptParser::_parse_class(ClassNode *p_class) { - IndentLevel current_level = indent_level.back()->get(); while (true) { - GDScriptTokenizer::Token token = tokenizer->get_token(); if (error_set) return; @@ -3732,7 +3585,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } switch (token) { - case GDScriptTokenizer::TK_CURSOR: { tokenizer->advance(); } break; @@ -3752,7 +3604,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } } break; case GDScriptTokenizer::TK_PR_EXTENDS: { - _mark_line_as_safe(tokenizer->get_token_line()); _parse_extends(p_class); if (error_set) @@ -3764,7 +3615,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } break; case GDScriptTokenizer::TK_PR_CLASS_NAME: { - _mark_line_as_safe(tokenizer->get_token_line()); if (p_class->owner) { _set_error("\"class_name\" is only valid for the main class namespace."); @@ -3775,7 +3625,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { return; } if (tokenizer->get_token(1) != GDScriptTokenizer::TK_IDENTIFIER) { - _set_error("\"class_name\" syntax: \"class_name <UniqueName>\""); return; } @@ -3841,9 +3690,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } break; case GDScriptTokenizer::TK_PR_TOOL: { - if (p_class->tool) { - _set_error("The \"tool\" keyword can only be present once per script."); return; } @@ -3858,7 +3705,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { StringName name; if (tokenizer->get_token(1) != GDScriptTokenizer::TK_IDENTIFIER) { - _set_error("\"class\" syntax: \"class <Name>:\" or \"class <Name> extends <BaseClass>:\""); return; } @@ -3907,14 +3753,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { p_class->subclasses.push_back(newclass); if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_EXTENDS) { - _parse_extends(newclass); if (error_set) return; } if (!_enter_indent_block()) { - _set_error("Indented block expected."); return; } @@ -3932,7 +3776,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { case GDScriptTokenizer::TK_PR_STATIC: { tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { - _set_error("Expected \"func\"."); return; } @@ -3940,12 +3783,10 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { [[fallthrough]]; } case GDScriptTokenizer::TK_PR_FUNCTION: { - bool _static = false; pending_newline = -1; if (tokenizer->get_token(-1) == GDScriptTokenizer::TK_PR_STATIC) { - _static = true; } @@ -3956,7 +3797,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (name == StringName()) { - _set_error("Expected an identifier after \"func\" (syntax: \"func <identifier>([arguments]):\")."); return; } @@ -3989,7 +3829,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { #endif // DEBUG_ENABLED if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) { - _set_error("Expected \"(\" after the identifier (syntax: \"func <identifier>([arguments]):\" )."); return; } @@ -4009,19 +3848,16 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { //has arguments bool defaulting = false; while (true) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); continue; } if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_VAR) { - tokenizer->advance(); //var before the identifier is allowed } if (!tokenizer->is_token_literal(0, true)) { - _set_error("Expected an identifier for an argument."); return; } @@ -4053,7 +3889,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { argument_types.push_back(argtype); if (defaulting && tokenizer->get_token() != GDScriptTokenizer::TK_OP_ASSIGN) { - _set_error("Default parameter expected."); return; } @@ -4094,7 +3929,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); continue; } else if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { - _set_error("Expected \",\" or \")\"."); return; } @@ -4122,14 +3956,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED; if (name == "_init") { - if (_static) { _set_error("The constructor cannot be static."); return; } if (p_class->extends_used) { - OperatorNode *cparent = alloc_node<OperatorNode>(); cparent->op = OperatorNode::OP_PARENT_CALL; block->statements.push_back(cparent); @@ -4150,7 +3982,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { //has arguments parenthesis++; while (true) { - current_function = function; Node *arg = _parse_and_reduce_expression(p_class, _static); current_function = nullptr; @@ -4160,7 +3991,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); continue; } else if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { - _set_error("Expected \",\" or \")\"."); return; } @@ -4173,9 +4003,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); } } else { - if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD) { - _set_error("Parent constructor call found for a class without inheritance."); return; } @@ -4184,7 +4012,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { DataType return_type; if (tokenizer->get_token() == GDScriptTokenizer::TK_FORWARD_ARROW) { - if (!_parse_type(return_type, true)) { _set_error("Expected a return type for the function."); return; @@ -4192,7 +4019,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (!_enter_indent_block(block)) { - _set_error(vformat("Indented block expected after declaration of \"%s\" function.", function->name)); return; } @@ -4268,11 +4094,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } } break; case GDScriptTokenizer::TK_PR_EXPORT: { - tokenizer->advance(); if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { - #define _ADVANCE_AND_CONSUME_NEWLINES \ do { \ tokenizer->advance(); \ @@ -4297,7 +4121,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE) { - Variant::Type type = tokenizer->get_token_type(); if (type == Variant::NIL) { _set_error("Can't export null type."); @@ -4316,11 +4139,8 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { _ADVANCE_AND_CONSUME_NEWLINES; switch (type) { - case Variant::INT: { - if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FLAGS") { - _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { @@ -4333,7 +4153,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { bool first = true; while (true) { - if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { current_export = PropertyInfo(); _set_error("Expected a string constant in the named bit flags hint."); @@ -4364,7 +4183,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "LAYERS_2D_RENDER") { - _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected \")\" in the layers 2D render hint."); @@ -4375,7 +4193,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "LAYERS_2D_PHYSICS") { - _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected \")\" in the layers 2D physics hint."); @@ -4386,7 +4203,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "LAYERS_3D_RENDER") { - _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected \")\" in the layers 3D render hint."); @@ -4397,7 +4213,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "LAYERS_3D_PHYSICS") { - _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected \")\" in the layers 3D physics hint."); @@ -4412,9 +4227,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { current_export.hint = PROPERTY_HINT_ENUM; bool first = true; while (true) { - if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { - current_export = PropertyInfo(); _set_error("Expected a string constant in the enumeration hint."); return; @@ -4447,7 +4260,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { [[fallthrough]]; } case Variant::FLOAT: { - if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EASE") { current_export.hint = PROPERTY_HINT_EXP_EASING; _ADVANCE_AND_CONSUME_NEWLINES; @@ -4460,7 +4272,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { // range if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EXP") { - current_export.hint = PROPERTY_HINT_EXP_RANGE; _ADVANCE_AND_CONSUME_NEWLINES; @@ -4481,7 +4292,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { _ADVANCE_AND_CONSUME_NEWLINES; } if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { - current_export = PropertyInfo(); _set_error("Expected a range in the numeric hint."); return; @@ -4496,7 +4306,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { - current_export = PropertyInfo(); _set_error("Expected \",\" or \")\" in the numeric range hint."); return; @@ -4511,7 +4320,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { - current_export = PropertyInfo(); _set_error("Expected a number as upper bound in the numeric range hint."); return; @@ -4524,7 +4332,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { break; if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { - current_export = PropertyInfo(); _set_error("Expected \",\" or \")\" in the numeric range hint."); return; @@ -4538,7 +4345,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { - current_export = PropertyInfo(); _set_error("Expected a number as step in the numeric range hint."); return; @@ -4549,15 +4355,12 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } break; case Variant::STRING: { - if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING) { //enumeration current_export.hint = PROPERTY_HINT_ENUM; bool first = true; while (true) { - if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { - current_export = PropertyInfo(); _set_error("Expected a string constant in the enumeration hint."); return; @@ -4586,13 +4389,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "DIR") { - _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) current_export.hint = PROPERTY_HINT_DIR; else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { - _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier() == "GLOBAL")) { @@ -4618,16 +4419,13 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FILE") { - current_export.hint = PROPERTY_HINT_FILE; _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { - _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "GLOBAL") { - if (!p_class->tool) { _set_error("Global filesystem hints may only be used in tool scripts."); return; @@ -4646,7 +4444,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { - if (current_export.hint == PROPERTY_HINT_GLOBAL_FILE) _set_error("Expected string constant with filter."); else @@ -4665,7 +4462,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "MULTILINE") { - current_export.hint = PROPERTY_HINT_MULTILINE_TEXT; _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { @@ -4676,9 +4472,7 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } } break; case Variant::COLOR: { - if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER) { - current_export = PropertyInfo(); _set_error("Color type hint expects RGB or RGBA as hints."); return; @@ -4698,7 +4492,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } break; default: { - current_export = PropertyInfo(); _set_error("Type \"" + Variant::get_type_name(type) + "\" can't take hints."); return; @@ -4707,7 +4500,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } } else { - parenthesis++; Node *subexpr = _parse_and_reduce_expression(p_class, true, true); if (!subexpr) { @@ -4787,7 +4579,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { - current_export = PropertyInfo(); _set_error("Expected \")\" or \",\" after the export hint."); return; @@ -4809,7 +4600,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_ONREADY && tokenizer->get_token() != GDScriptTokenizer::TK_PR_REMOTE && tokenizer->get_token() != GDScriptTokenizer::TK_PR_MASTER && tokenizer->get_token() != GDScriptTokenizer::TK_PR_PUPPET && tokenizer->get_token() != GDScriptTokenizer::TK_PR_REMOTESYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_MASTERSYNC && tokenizer->get_token() != GDScriptTokenizer::TK_PR_PUPPETSYNC) { - current_export = PropertyInfo(); _set_error("Expected \"var\", \"onready\", \"remote\", \"master\", \"puppet\", \"remotesync\", \"mastersync\", \"puppetsync\"."); return; @@ -4818,7 +4608,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { continue; } break; case GDScriptTokenizer::TK_PR_ONREADY: { - //may be fallthrough from export, ignore if so tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) { @@ -4829,7 +4618,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { continue; } break; case GDScriptTokenizer::TK_PR_REMOTE: { - //may be fallthrough from export, ignore if so tokenizer->advance(); if (current_export.type) { @@ -4849,7 +4637,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { continue; } break; case GDScriptTokenizer::TK_PR_MASTER: { - //may be fallthrough from export, ignore if so tokenizer->advance(); if (current_export.type) { @@ -4869,7 +4656,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { continue; } break; case GDScriptTokenizer::TK_PR_PUPPET: { - //may be fallthrough from export, ignore if so tokenizer->advance(); if (current_export.type) { @@ -4889,7 +4675,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { continue; } break; case GDScriptTokenizer::TK_PR_REMOTESYNC: { - //may be fallthrough from export, ignore if so tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { @@ -4904,7 +4689,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { continue; } break; case GDScriptTokenizer::TK_PR_MASTERSYNC: { - //may be fallthrough from export, ignore if so tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { @@ -4919,7 +4703,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { continue; } break; case GDScriptTokenizer::TK_PR_PUPPETSYNC: { - //may be fallthrough from export, ignore if so tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { @@ -4948,7 +4731,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); if (!tokenizer->is_token_literal(0, true)) { - _set_error("Expected an identifier for the member variable name."); return; } @@ -5038,7 +4820,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { #endif if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { - #ifdef DEBUG_ENABLED int line = tokenizer->get_token_line(); #endif @@ -5054,12 +4835,10 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { //discourage common error if (!onready && subexpr->type == Node::TYPE_OPERATOR) { - OperatorNode *op = static_cast<OperatorNode *>(subexpr); if (op->op == OperatorNode::OP_CALL && op->arguments[0]->type == Node::TYPE_SELF && op->arguments[1]->type == Node::TYPE_IDENTIFIER) { IdentifierNode *id = static_cast<IdentifierNode *>(op->arguments[1]); if (id->name == "get_node") { - _set_error("Use \"onready var " + String(member.identifier) + " = get_node(...)\" instead."); return; } @@ -5069,16 +4848,13 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { member.expression = subexpr; if (autoexport && !member.data_type.has_type) { - if (subexpr->type != Node::TYPE_CONSTANT) { - _set_error("Type-less export needs a constant expression assigned to infer type."); return; } ConstantNode *cn = static_cast<ConstantNode *>(subexpr); if (cn->value.get_type() == Variant::NIL) { - _set_error("Can't accept a null constant expression for inferring export type."); return; } @@ -5101,7 +4877,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } #ifdef TOOLS_ENABLED if (subexpr->type == Node::TYPE_CONSTANT && (member._export.type != Variant::NIL || member.data_type.has_type)) { - ConstantNode *cn = static_cast<ConstantNode *>(subexpr); if (cn->value.get_type() != Variant::NIL) { if (member._export.type != Variant::NIL && cn->value.get_type() != member._export.type) { @@ -5144,7 +4919,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { member.initial_assignment = op; } else { - if (autoexport && !member.data_type.has_type) { _set_error("Type-less export needs a constant expression assigned to infer type."); return; @@ -5177,7 +4951,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_SETGET) { - tokenizer->advance(); if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { @@ -5218,7 +4991,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); if (!tokenizer->is_token_literal(0, true)) { - _set_error("Expected an identifier for the constant."); return; } @@ -5334,14 +5106,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { while (true) { if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { - tokenizer->advance(); // Ignore newlines } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { - tokenizer->advance(); break; // End of enum } else if (!tokenizer->is_token_literal(0, true)) { - if (tokenizer->get_token() == GDScriptTokenizer::TK_EOF) { _set_error("Unexpected end of file."); } else { @@ -5462,7 +5231,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } break; default: { - _set_error(String() + "Unexpected token: " + tokenizer->get_token_name(tokenizer->get_token()) + ":" + tokenizer->get_token_identifier()); return; @@ -5472,7 +5240,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive) { - if (p_class->base_type.has_type) { // Already determined } else if (p_class->extends_used) { @@ -5487,7 +5254,6 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive //path (and optionally subclasses) if (path.is_rel_path()) { - String base = base_path; if (base == "" || base.is_rel_path()) { @@ -5502,22 +5268,17 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive return; } if (!script->is_valid()) { - _set_error("Script isn't fully loaded (cyclic preload?): " + path, p_class->line); return; } if (p_class->extends_class.size()) { - for (int i = 0; i < p_class->extends_class.size(); i++) { - String sub = p_class->extends_class[i]; if (script->get_subclasses().has(sub)) { - Ref<Script> subclass = script->get_subclasses()[sub]; //avoid reference from disappearing script = subclass; } else { - _set_error("Couldn't find the subclass: " + sub, p_class->line); return; } @@ -5525,7 +5286,6 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive } } else { - if (p_class->extends_class.size() == 0) { _set_error("Parser bug: undecidable inheritance.", p_class->line); ERR_FAIL(); @@ -5572,7 +5332,6 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive } while (p) { - bool found = false; for (int i = 0; i < p->subclasses.size(); i++) { @@ -5624,21 +5383,17 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive } if (base_script.is_valid()) { - String ident = base; Ref<GDScript> find_subclass = base_script; for (int i = extend_iter; i < p_class->extends_class.size(); i++) { - String subclass = p_class->extends_class[i]; ident += ("." + subclass); if (find_subclass->get_subclasses().has(subclass)) { - find_subclass = find_subclass->get_subclasses()[subclass]; } else if (find_subclass->get_constants().has(subclass)) { - Ref<GDScript> new_base_class = find_subclass->get_constants()[subclass]; if (new_base_class.is_null()) { _set_error("Constant isn't a class: " + ident, p_class->line); @@ -5646,7 +5401,6 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive } find_subclass = new_base_class; } else { - _set_error("Couldn't find the subclass: " + ident, p_class->line); return; } @@ -5655,15 +5409,12 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive script = find_subclass; } else if (!base_class) { - if (p_class->extends_class.size() > 1) { - _set_error("Invalid inheritance (unknown class + subclasses).", p_class->line); return; } //if not found, try engine classes if (!GDScriptLanguage::get_singleton()->get_global_map().has(base)) { - _set_error("Unknown class: \"" + base + "\"", p_class->line); return; } @@ -5887,7 +5638,6 @@ GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source, result.has_type = true; while (name_part < full_name.size()) { - bool found = false; StringName id = full_name[name_part]; DataType base_type = result; @@ -6549,7 +6299,6 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) { DataType source_type = _reduce_node_type(cn->source_node); cn->cast_type = _resolve_type(cn->cast_type, cn->line); if (source_type.has_type) { - bool valid = false; if (check_types) { if (cn->cast_type.kind == DataType::BUILTIN && source_type.kind == DataType::BUILTIN) { @@ -6603,7 +6352,6 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) { } break; case OperatorNode::OP_IS: case OperatorNode::OP_IS_BUILTIN: { - if (op->arguments.size() != 2) { _set_error("Parser bug: binary operation without 2 arguments.", op->line); ERR_FAIL_V(DataType()); @@ -6639,7 +6387,6 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) { case OperatorNode::OP_POS: case OperatorNode::OP_NOT: case OperatorNode::OP_BIT_INVERT: { - DataType argument_type = _reduce_node_type(op->arguments[0]); if (!argument_type.has_type) { break; @@ -6677,7 +6424,6 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) { case OperatorNode::OP_BIT_AND: case OperatorNode::OP_BIT_OR: case OperatorNode::OP_BIT_XOR: { - if (op->arguments.size() != 2) { _set_error("Parser bug: binary operation without 2 arguments.", op->line); ERR_FAIL_V(DataType()); @@ -6745,7 +6491,6 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) { case OperatorNode::OP_ASSIGN_BIT_OR: case OperatorNode::OP_ASSIGN_BIT_XOR: case OperatorNode::OP_INIT_ASSIGN: { - _set_error("Assignment inside an expression isn't allowed (parser bug?).", op->line); return DataType(); @@ -6808,7 +6553,6 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) { } } break; case OperatorNode::OP_INDEX: { - if (op->arguments[1]->type == Node::TYPE_CONSTANT) { ConstantNode *cn = static_cast<ConstantNode *>(op->arguments[1]); if (cn->value.get_type() == Variant::STRING) { @@ -7007,7 +6751,6 @@ GDScriptParser::DataType GDScriptParser::_reduce_node_type(Node *p_node) { } bool GDScriptParser::_get_function_signature(DataType &p_base_type, const StringName &p_function, DataType &r_return_type, List<DataType> &r_arg_types, int &r_default_arg_count, bool &r_static, bool &r_vararg) const { - r_static = false; r_default_arg_count = 0; @@ -7729,7 +7472,6 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN } GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType *p_base_type, const StringName &p_identifier, int p_line, bool p_is_indexing) { - if (p_base_type && !p_base_type->has_type) { return DataType(); } @@ -7903,7 +7645,6 @@ GDScriptParser::DataType GDScriptParser::_reduce_identifier_type(const DataType } void GDScriptParser::_check_class_level_types(ClassNode *p_class) { - // Names of internal object properties that we check to avoid overriding them. // "__meta__" could also be in here, but since it doesn't really affect object metadata, // it is okay to override it on script. @@ -8109,7 +7850,6 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { } void GDScriptParser::_check_function_types(FunctionNode *p_function) { - p_function->return_type = _resolve_type(p_function->return_type, p_function->line); // Arguments @@ -8231,7 +7971,6 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) { } void GDScriptParser::_check_class_blocks_types(ClassNode *p_class) { - // Function blocks for (int i = 0; i < p_class->static_functions.size(); i++) { current_function = p_class->static_functions[i]; @@ -8300,7 +8039,6 @@ static String _find_function_name(const GDScriptParser::OperatorNode *p_call) { #endif // DEBUG_ENABLED void GDScriptParser::_check_block_types(BlockNode *p_block) { - Node *last_var_assign = nullptr; // Check each statement @@ -8659,7 +8397,6 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) { } void GDScriptParser::_set_error(const String &p_error, int p_line, int p_column) { - if (error_set) return; //allow no further errors @@ -8723,16 +8460,13 @@ void GDScriptParser::_add_warning(int p_code, int p_line, const Vector<String> & #endif // DEBUG_ENABLED String GDScriptParser::get_error() const { - return error; } int GDScriptParser::get_error_line() const { - return error_line; } int GDScriptParser::get_error_column() const { - return error_column; } @@ -8741,7 +8475,6 @@ bool GDScriptParser::has_error() const { } Error GDScriptParser::_parse(const String &p_base_path) { - base_path = p_base_path; //assume class @@ -8840,7 +8573,6 @@ Error GDScriptParser::_parse(const String &p_base_path) { } Error GDScriptParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const String &p_base_path, const String &p_self_path) { - clear(); self_path = p_self_path; @@ -8854,7 +8586,6 @@ Error GDScriptParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const St } Error GDScriptParser::parse(const String &p_code, const String &p_base_path, bool p_just_validate, const String &p_self_path, bool p_for_completion, Set<int> *r_safe_lines, bool p_dependencies_only) { - clear(); self_path = p_self_path; @@ -8875,19 +8606,15 @@ Error GDScriptParser::parse(const String &p_code, const String &p_base_path, boo } bool GDScriptParser::is_tool_script() const { - return (head && head->type == Node::TYPE_CLASS && static_cast<const ClassNode *>(head)->tool); } const GDScriptParser::Node *GDScriptParser::get_parse_tree() const { - return head; } void GDScriptParser::clear() { - while (list) { - Node *l = list; list = list->next; memdelete(l); @@ -8929,57 +8656,46 @@ void GDScriptParser::clear() { } GDScriptParser::CompletionType GDScriptParser::get_completion_type() { - return completion_type; } StringName GDScriptParser::get_completion_cursor() { - return completion_cursor; } int GDScriptParser::get_completion_line() { - return completion_line; } Variant::Type GDScriptParser::get_completion_built_in_constant() { - return completion_built_in_constant; } GDScriptParser::Node *GDScriptParser::get_completion_node() { - return completion_node; } GDScriptParser::BlockNode *GDScriptParser::get_completion_block() { - return completion_block; } GDScriptParser::ClassNode *GDScriptParser::get_completion_class() { - return completion_class; } GDScriptParser::FunctionNode *GDScriptParser::get_completion_function() { - return completion_function; } int GDScriptParser::get_completion_argument_index() { - return completion_argument; } bool GDScriptParser::get_completion_identifier_is_function() { - return completion_ident_is_call; } GDScriptParser::GDScriptParser() { - head = nullptr; list = nullptr; tokenizer = nullptr; @@ -8988,6 +8704,5 @@ GDScriptParser::GDScriptParser() { } GDScriptParser::~GDScriptParser() { - clear(); } diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 035af30b6a..4332fa7569 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -100,7 +100,6 @@ public: }; struct Node { - enum Type { TYPE_CLASS, TYPE_FUNCTION, @@ -139,7 +138,6 @@ public: struct OperatorNode; struct ClassNode : public Node { - bool tool; StringName name; bool extends_used; @@ -200,7 +198,6 @@ public: }; struct FunctionNode : public Node { - bool _static; MultiplayerAPI::RPCMode rpc_mode; bool has_yield; @@ -229,7 +226,6 @@ public: }; struct BlockNode : public Node { - ClassNode *parent_class = nullptr; BlockNode *parent_block = nullptr; List<Node *> statements; @@ -316,7 +312,6 @@ public: }; struct DictionaryNode : public Node { - struct Pair { Node *key; Node *value; @@ -406,7 +401,6 @@ public: }; struct PatternNode : public Node { - enum PatternType { PT_CONSTANT, PT_BIND, diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 1c8282e13e..f532a6b797 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -240,7 +240,6 @@ static const _kws _keyword_list[] = { }; const char *GDScriptTokenizer::get_token_name(Token p_token) { - ERR_FAIL_INDEX_V(p_token, TK_MAX, "<error>"); return token_names[p_token]; } @@ -364,27 +363,22 @@ StringName GDScriptTokenizer::get_token_literal(int p_offset) const { } static bool _is_text_char(CharType c) { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; } static bool _is_number(CharType c) { - return (c >= '0' && c <= '9'); } static bool _is_hex(CharType c) { - return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } static bool _is_bin(CharType c) { - return (c == '0' || c == '1'); } void GDScriptTokenizerText::_make_token(Token p_type) { - TokenData &tk = tk_rb[tk_rb_pos]; tk.type = p_type; @@ -394,7 +388,6 @@ void GDScriptTokenizerText::_make_token(Token p_type) { tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } void GDScriptTokenizerText::_make_identifier(const StringName &p_identifier) { - TokenData &tk = tk_rb[tk_rb_pos]; tk.type = TK_IDENTIFIER; @@ -406,7 +399,6 @@ void GDScriptTokenizerText::_make_identifier(const StringName &p_identifier) { } void GDScriptTokenizerText::_make_built_in_func(GDScriptFunctions::Function p_func) { - TokenData &tk = tk_rb[tk_rb_pos]; tk.type = TK_BUILT_IN_FUNC; @@ -417,7 +409,6 @@ void GDScriptTokenizerText::_make_built_in_func(GDScriptFunctions::Function p_fu tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } void GDScriptTokenizerText::_make_constant(const Variant &p_constant) { - TokenData &tk = tk_rb[tk_rb_pos]; tk.type = TK_CONSTANT; @@ -429,7 +420,6 @@ void GDScriptTokenizerText::_make_constant(const Variant &p_constant) { } void GDScriptTokenizerText::_make_type(const Variant::Type &p_type) { - TokenData &tk = tk_rb[tk_rb_pos]; tk.type = TK_BUILT_IN_TYPE; @@ -441,7 +431,6 @@ void GDScriptTokenizerText::_make_type(const Variant::Type &p_type) { } void GDScriptTokenizerText::_make_error(const String &p_error) { - error_flag = true; last_error = p_error; @@ -454,7 +443,6 @@ void GDScriptTokenizerText::_make_error(const String &p_error) { } void GDScriptTokenizerText::_make_newline(int p_indentation, int p_tabs) { - TokenData &tk = tk_rb[tk_rb_pos]; tk.type = TK_NEWLINE; tk.constant = Vector2(p_indentation, p_tabs); @@ -464,7 +452,6 @@ void GDScriptTokenizerText::_make_newline(int p_indentation, int p_tabs) { } void GDScriptTokenizerText::_advance() { - if (error_flag) { //parser broke _make_error(last_error); @@ -482,7 +469,6 @@ void GDScriptTokenizerText::_advance() { column += m_amount; \ } while (true) { - bool is_string_name = false; StringMode string_mode = STRING_DOUBLE_QUOTE; @@ -570,7 +556,6 @@ void GDScriptTokenizerText::_advance() { return; } case '/': { - switch (GETCHAR(1)) { case '=': { // diveq @@ -593,7 +578,6 @@ void GDScriptTokenizerText::_advance() { } break; case '<': { if (GETCHAR(1) == '=') { - _make_token(TK_OP_LESS_EQUAL); INCPOS(1); } else if (GETCHAR(1) == '<') { @@ -684,7 +668,6 @@ void GDScriptTokenizerText::_advance() { break; case '&': { if (GETCHAR(1) == '&') { - _make_token(TK_OP_AND); INCPOS(1); } else if (GETCHAR(1) == '=') { @@ -696,7 +679,6 @@ void GDScriptTokenizerText::_advance() { } break; case '|': { if (GETCHAR(1) == '|') { - _make_token(TK_OP_OR); INCPOS(1); } else if (GETCHAR(1) == '=') { @@ -707,7 +689,6 @@ void GDScriptTokenizerText::_advance() { } } break; case '*': { - if (GETCHAR(1) == '=') { _make_token(TK_OP_ASSIGN_MUL); INCPOS(1); @@ -716,7 +697,6 @@ void GDScriptTokenizerText::_advance() { } } break; case '+': { - if (GETCHAR(1) == '=') { _make_token(TK_OP_ASSIGN_ADD); INCPOS(1); @@ -731,7 +711,6 @@ void GDScriptTokenizerText::_advance() { } break; case '-': { - if (GETCHAR(1) == '=') { _make_token(TK_OP_ASSIGN_SUB); INCPOS(1); @@ -743,7 +722,6 @@ void GDScriptTokenizerText::_advance() { } } break; case '%': { - if (GETCHAR(1) == '=') { _make_token(TK_OP_ASSIGN_MOD); INCPOS(1); @@ -761,7 +739,6 @@ void GDScriptTokenizerText::_advance() { [[fallthrough]]; case '\'': case '"': { - if (GETCHAR(0) == '\'') string_mode = STRING_SINGLE_QUOTE; @@ -774,7 +751,6 @@ void GDScriptTokenizerText::_advance() { String str; while (true) { if (CharType(GETCHAR(i)) == 0) { - _make_error("Unterminated String"); return; } else if (string_mode == STRING_DOUBLE_QUOTE && CharType(GETCHAR(i)) == '"') { @@ -802,7 +778,6 @@ void GDScriptTokenizerText::_advance() { CharType res = 0; switch (next) { - case 'a': res = '\a'; break; @@ -869,7 +844,6 @@ void GDScriptTokenizerText::_advance() { column = 1; } break; default: { - _make_error("Invalid escape sequence"); return; } break; @@ -901,7 +875,6 @@ void GDScriptTokenizerText::_advance() { _make_token(TK_CURSOR); } break; default: { - if (_is_number(GETCHAR(0)) || (GETCHAR(0) == '.' && _is_number(GETCHAR(1)))) { // parse number bool period_found = false; @@ -933,7 +906,6 @@ void GDScriptTokenizerText::_advance() { } hexa_found = true; } else if (hexa_found && _is_hex(GETCHAR(i))) { - } else if (!hexa_found && GETCHAR(i) == 'b') { if (bin_found || str.length() != 1 || !((i == 1 && str[0] == '0') || (i == 2 && str[1] == '0' && str[0] == '-'))) { _make_error("Invalid numeric constant at 'b'"); @@ -950,7 +922,6 @@ void GDScriptTokenizerText::_advance() { //all ok } else if (bin_found && _is_bin(GETCHAR(i))) { - } else if ((GETCHAR(i) == '-' || GETCHAR(i) == '+') && exponent_found) { if (sign_found) { _make_error("Invalid numeric constant at '-'"); @@ -1018,15 +989,12 @@ void GDScriptTokenizerText::_advance() { } else if (str == "false") { _make_constant(false); } else { - bool found = false; { - int idx = 0; while (_type_list[idx].text) { - if (str == _type_list[idx].text) { _make_type(_type_list[idx].type); found = true; @@ -1037,13 +1005,10 @@ void GDScriptTokenizerText::_advance() { } if (!found) { - //built in func? for (int j = 0; j < GDScriptFunctions::FUNC_MAX; j++) { - if (str == GDScriptFunctions::get_func_name(GDScriptFunctions::Function(j))) { - _make_built_in_func(GDScriptFunctions::Function(j)); found = true; break; @@ -1058,7 +1023,6 @@ void GDScriptTokenizerText::_advance() { found = false; while (_keyword_list[idx].text) { - if (str == _keyword_list[idx].text) { _make_token(_keyword_list[idx].token); found = true; @@ -1091,7 +1055,6 @@ void GDScriptTokenizerText::_advance() { } void GDScriptTokenizerText::set_code(const String &p_code) { - code = p_code; len = p_code.length(); if (len) { @@ -1146,7 +1109,6 @@ const Variant &GDScriptTokenizerText::get_token_constant(int p_offset) const { } StringName GDScriptTokenizerText::get_token_identifier(int p_offset) const { - ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, StringName()); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, StringName()); @@ -1156,7 +1118,6 @@ StringName GDScriptTokenizerText::get_token_identifier(int p_offset) const { } GDScriptFunctions::Function GDScriptTokenizerText::get_token_built_in_func(int p_offset) const { - ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, GDScriptFunctions::FUNC_MAX); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, GDScriptFunctions::FUNC_MAX); @@ -1166,7 +1127,6 @@ GDScriptFunctions::Function GDScriptTokenizerText::get_token_built_in_func(int p } Variant::Type GDScriptTokenizerText::get_token_type(int p_offset) const { - ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, Variant::NIL); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, Variant::NIL); @@ -1176,7 +1136,6 @@ Variant::Type GDScriptTokenizerText::get_token_type(int p_offset) const { } int GDScriptTokenizerText::get_token_line_indent(int p_offset) const { - ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, 0); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, 0); @@ -1186,7 +1145,6 @@ int GDScriptTokenizerText::get_token_line_indent(int p_offset) const { } int GDScriptTokenizerText::get_token_line_tab_indent(int p_offset) const { - ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, 0); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, 0); @@ -1196,7 +1154,6 @@ int GDScriptTokenizerText::get_token_line_tab_indent(int p_offset) const { } String GDScriptTokenizerText::get_token_error(int p_offset) const { - ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, String()); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, String()); @@ -1206,7 +1163,6 @@ String GDScriptTokenizerText::get_token_error(int p_offset) const { } void GDScriptTokenizerText::advance(int p_amount) { - ERR_FAIL_COND(p_amount <= 0); for (int i = 0; i < p_amount; i++) _advance(); @@ -1217,7 +1173,6 @@ void GDScriptTokenizerText::advance(int p_amount) { #define BYTECODE_VERSION 13 Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) { - const uint8_t *buf = p_buffer.ptr(); int total_len = p_buffer.size(); ERR_FAIL_COND_V(p_buffer.size() < 24 || p_buffer[0] != 'G' || p_buffer[1] != 'D' || p_buffer[2] != 'S' || p_buffer[3] != 'C', ERR_INVALID_DATA); @@ -1235,7 +1190,6 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) identifiers.resize(identifier_count); for (int i = 0; i < identifier_count; i++) { - int len = decode_uint32(b); ERR_FAIL_COND_V(len > total_len, ERR_INVALID_DATA); b += 4; @@ -1255,7 +1209,6 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) constants.resize(constant_count); for (int i = 0; i < constant_count; i++) { - Variant v; int len; // An object cannot be constant, never decode objects @@ -1270,7 +1223,6 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) ERR_FAIL_COND_V(line_count * 8 > total_len, ERR_INVALID_DATA); for (int i = 0; i < line_count; i++) { - uint32_t token = decode_uint32(b); b += 4; uint32_t linecol = decode_uint32(b); @@ -1283,7 +1235,6 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) tokens.resize(token_count); for (int i = 0; i < token_count; i++) { - ERR_FAIL_COND_V(total_len < 1, ERR_INVALID_DATA); if ((*b) & TOKEN_BYTE_MASK) { //little endian always @@ -1304,7 +1255,6 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) } Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) { - Vector<uint8_t> buf; Map<StringName, int> identifier_map; @@ -1317,16 +1267,13 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) int line = -1; while (true) { - if (tt.get_token_line() != line) { - line = tt.get_token_line(); line_map[line] = token_array.size(); } uint32_t token = tt.get_token(); switch (tt.get_token()) { - case TK_IDENTIFIER: { StringName id = tt.get_token_identifier(); if (!identifier_map.has(id)) { @@ -1336,7 +1283,6 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) token |= identifier_map[id] << TOKEN_BITS; } break; case TK_CONSTANT: { - const Variant &c = tt.get_token_constant(); if (!constant_map.has(c)) { int idx = constant_map.size(); @@ -1345,20 +1291,16 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) token |= constant_map[c] << TOKEN_BITS; } break; case TK_BUILT_IN_TYPE: { - token |= tt.get_token_type() << TOKEN_BITS; } break; case TK_BUILT_IN_FUNC: { - token |= tt.get_token_built_in_func() << TOKEN_BITS; } break; case TK_NEWLINE: { - token |= tt.get_token_line_indent() << TOKEN_BITS; } break; case TK_ERROR: { - ERR_FAIL_V(Vector<uint8_t>()); } break; default: { @@ -1405,7 +1347,6 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) //save identifiers for (Map<int, StringName>::Element *E = rev_identifier_map.front(); E; E = E->next()) { - CharString cs = String(E->get()).utf8(); int len = cs.length() + 1; int extra = 4 - (len % 4); @@ -1426,7 +1367,6 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) } for (Map<int, Variant>::Element *E = rev_constant_map.front(); E; E = E->next()) { - int len; // Objects cannot be constant, never encode objects Error err = encode_variant(E->get(), nullptr, len, false); @@ -1437,7 +1377,6 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) } for (Map<int, uint32_t>::Element *E = rev_line_map.front(); E; E = E->next()) { - uint8_t ibuf[8]; encode_uint32(E->key(), &ibuf[0]); encode_uint32(E->get(), &ibuf[4]); @@ -1446,7 +1385,6 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) } for (int i = 0; i < token_array.size(); i++) { - uint32_t token = token_array[i]; if (token & ~TOKEN_MASK) { @@ -1464,7 +1402,6 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) } GDScriptTokenizerBuffer::Token GDScriptTokenizerBuffer::get_token(int p_offset) const { - int offset = token + p_offset; if (offset < 0 || offset >= tokens.size()) @@ -1474,7 +1411,6 @@ GDScriptTokenizerBuffer::Token GDScriptTokenizerBuffer::get_token(int p_offset) } StringName GDScriptTokenizerBuffer::get_token_identifier(int p_offset) const { - int offset = token + p_offset; ERR_FAIL_INDEX_V(offset, tokens.size(), StringName()); @@ -1485,14 +1421,12 @@ StringName GDScriptTokenizerBuffer::get_token_identifier(int p_offset) const { } GDScriptFunctions::Function GDScriptTokenizerBuffer::get_token_built_in_func(int p_offset) const { - int offset = token + p_offset; ERR_FAIL_INDEX_V(offset, tokens.size(), GDScriptFunctions::FUNC_MAX); return GDScriptFunctions::Function(tokens[offset] >> TOKEN_BITS); } Variant::Type GDScriptTokenizerBuffer::get_token_type(int p_offset) const { - int offset = token + p_offset; ERR_FAIL_INDEX_V(offset, tokens.size(), Variant::NIL); @@ -1500,7 +1434,6 @@ Variant::Type GDScriptTokenizerBuffer::get_token_type(int p_offset) const { } int GDScriptTokenizerBuffer::get_token_line(int p_offset) const { - int offset = token + p_offset; int pos = lines.find_nearest(offset); @@ -1513,7 +1446,6 @@ int GDScriptTokenizerBuffer::get_token_line(int p_offset) const { return l & TOKEN_LINE_MASK; } int GDScriptTokenizerBuffer::get_token_column(int p_offset) const { - int offset = token + p_offset; int pos = lines.find_nearest(offset); if (pos < 0) @@ -1525,13 +1457,11 @@ int GDScriptTokenizerBuffer::get_token_column(int p_offset) const { return l >> TOKEN_LINE_BITS; } int GDScriptTokenizerBuffer::get_token_line_indent(int p_offset) const { - int offset = token + p_offset; ERR_FAIL_INDEX_V(offset, tokens.size(), 0); return tokens[offset] >> TOKEN_BITS; } const Variant &GDScriptTokenizerBuffer::get_token_constant(int p_offset) const { - int offset = token + p_offset; ERR_FAIL_INDEX_V(offset, tokens.size(), nil); uint32_t constant = tokens[offset] >> TOKEN_BITS; @@ -1539,16 +1469,13 @@ const Variant &GDScriptTokenizerBuffer::get_token_constant(int p_offset) const { return constants[constant]; } String GDScriptTokenizerBuffer::get_token_error(int p_offset) const { - ERR_FAIL_V(String()); } void GDScriptTokenizerBuffer::advance(int p_amount) { - ERR_FAIL_INDEX(p_amount + token, tokens.size()); token += p_amount; } GDScriptTokenizerBuffer::GDScriptTokenizerBuffer() { - token = 0; } diff --git a/modules/gdscript/gdscript_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h index 76410433de..32603c010f 100644 --- a/modules/gdscript/gdscript_tokenizer.h +++ b/modules/gdscript/gdscript_tokenizer.h @@ -180,7 +180,6 @@ public: }; class GDScriptTokenizerText : public GDScriptTokenizer { - enum { MAX_LOOKAHEAD = 4, TK_RB_SIZE = MAX_LOOKAHEAD * 2 + 1 @@ -252,7 +251,6 @@ public: }; class GDScriptTokenizerBuffer : public GDScriptTokenizer { - enum { TOKEN_BYTE_MASK = 0x80, diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index a6b749059a..9338dcadbe 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -35,7 +35,6 @@ #include "gdscript_workspace.h" void ExtendGDScriptParser::update_diagnostics() { - diagnostics.clear(); if (has_error()) { @@ -80,12 +79,10 @@ void ExtendGDScriptParser::update_diagnostics() { } void ExtendGDScriptParser::update_symbols() { - members.clear(); const GDScriptParser::Node *head = get_parse_tree(); if (const GDScriptParser::ClassNode *gdclass = dynamic_cast<const GDScriptParser::ClassNode *>(head)) { - parse_class_symbol(gdclass, class_symbol); for (int i = 0; i < class_symbol.children.size(); i++) { @@ -141,7 +138,6 @@ void ExtendGDScriptParser::update_document_links(const String &p_code) { } void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p_class, lsp::DocumentSymbol &r_symbol) { - const String uri = get_uri(); r_symbol.uri = uri; @@ -161,7 +157,6 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p r_symbol.documentation = parse_documentation(is_root_class ? 0 : LINE_NUMBER_TO_INDEX(p_class->line), is_root_class); for (int i = 0; i < p_class->variables.size(); ++i) { - const GDScriptParser::ClassNode::Member &m = p_class->variables[i]; lsp::DocumentSymbol symbol; @@ -289,7 +284,6 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p } void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionNode *p_func, lsp::DocumentSymbol &r_symbol) { - const String uri = get_uri(); r_symbol.name = p_func->name; @@ -384,7 +378,6 @@ String ExtendGDScriptParser::parse_documentation(int p_line, bool p_docs_down) { int step = p_docs_down ? 1 : -1; int start_line = p_docs_down ? p_line : p_line - 1; for (int i = start_line; true; i += step) { - if (i < 0 || i >= lines.size()) break; @@ -409,17 +402,14 @@ String ExtendGDScriptParser::parse_documentation(int p_line, bool p_docs_down) { } String ExtendGDScriptParser::get_text_for_completion(const lsp::Position &p_cursor) const { - String longthing; int len = lines.size(); for (int i = 0; i < len; i++) { - if (i == p_cursor.line) { longthing += lines[i].substr(0, p_cursor.character); longthing += String::chr(0xFFFF); //not unicode, represents the cursor longthing += lines[i].substr(p_cursor.character, lines[i].size()); } else { - longthing += lines[i]; } @@ -434,7 +424,6 @@ String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_c String longthing; int len = lines.size(); for (int i = 0; i < len; i++) { - if (i == p_cursor.line) { String line = lines[i]; String first_part = line.substr(0, p_cursor.character); @@ -458,7 +447,6 @@ String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_c } longthing += last_part; } else { - longthing += lines[i]; } @@ -470,7 +458,6 @@ String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_c } String ExtendGDScriptParser::get_identifier_under_position(const lsp::Position &p_position, Vector2i &p_offset) const { - ERR_FAIL_INDEX_V(p_position.line, lines.size(), ""); String line = lines[p_position.line]; ERR_FAIL_INDEX_V(p_position.character, line.size(), ""); @@ -525,7 +512,6 @@ const lsp::DocumentSymbol *ExtendGDScriptParser::search_symbol_defined_at_line(i } Error ExtendGDScriptParser::get_left_function_call(const lsp::Position &p_position, lsp::Position &r_func_pos, int &r_arg_index) const { - ERR_FAIL_INDEX_V(p_position.line, lines.size(), ERR_INVALID_PARAMETER); int bracket_stack = 0; @@ -577,7 +563,6 @@ const lsp::DocumentSymbol *ExtendGDScriptParser::get_symbol_defined_at_line(int } const lsp::DocumentSymbol *ExtendGDScriptParser::get_member_symbol(const String &p_name, const String &p_subclass) const { - if (p_subclass.empty()) { const lsp::DocumentSymbol *const *ptr = members.getptr(p_name); if (ptr) { @@ -600,12 +585,9 @@ const List<lsp::DocumentLink> &ExtendGDScriptParser::get_document_links() const } const Array &ExtendGDScriptParser::get_member_completions() { - if (member_completions.empty()) { - const String *name = members.next(nullptr); while (name) { - const lsp::DocumentSymbol *symbol = members.get(*name); lsp::CompletionItem item = symbol->make_completion_item(); item.data = JOIN_SYMBOLS(path, *name); @@ -616,7 +598,6 @@ const Array &ExtendGDScriptParser::get_member_completions() { const String *_class = inner_classes.next(nullptr); while (_class) { - const ClassMembers *inner_class = inner_classes.getptr(*_class); const String *member_name = inner_class->next(nullptr); while (member_name) { @@ -697,7 +678,6 @@ Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode Array constants; for (Map<StringName, GDScriptParser::ClassNode::Constant>::Element *E = p_class->constant_expressions.front(); E; E = E->next()) { - const GDScriptParser::ClassNode::Constant &c = E->value(); const GDScriptParser::ConstantNode *node = dynamic_cast<const GDScriptParser::ConstantNode *>(c.expression); ERR_FAIL_COND_V(!node, class_api); @@ -766,7 +746,6 @@ Dictionary ExtendGDScriptParser::dump_class_api(const GDScriptParser::ClassNode } Dictionary ExtendGDScriptParser::generate_api() const { - Dictionary api; const GDScriptParser::Node *head = get_parse_tree(); if (const GDScriptParser::ClassNode *gdclass = dynamic_cast<const GDScriptParser::ClassNode *>(head)) { diff --git a/modules/gdscript/language_server/gdscript_extend_parser.h b/modules/gdscript/language_server/gdscript_extend_parser.h index 43dfce994b..0c031d7883 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.h +++ b/modules/gdscript/language_server/gdscript_extend_parser.h @@ -50,7 +50,6 @@ typedef HashMap<String, const lsp::DocumentSymbol *> ClassMembers; class ExtendGDScriptParser : public GDScriptParser { - String path; Vector<String> lines; diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp index 69662e96f7..c5bce5bb87 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.cpp +++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp @@ -145,7 +145,6 @@ String GDScriptLanguageProtocol::process_message(const String &p_text) { } String GDScriptLanguageProtocol::format_output(const String &p_text) { - String header = "Content-Length: "; CharString charstr = p_text.utf8(); size_t len = charstr.length(); @@ -168,7 +167,6 @@ void GDScriptLanguageProtocol::_bind_methods() { } Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) { - lsp::InitializeResult ret; String root_uri = p_params["rootUri"]; @@ -183,7 +181,6 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) { if (root_uri.length() && is_same_workspace) { workspace->root_uri = root_uri; } else { - workspace->root_uri = "file://" + workspace->root; Dictionary params; @@ -208,12 +205,10 @@ Dictionary GDScriptLanguageProtocol::initialize(const Dictionary &p_params) { } void GDScriptLanguageProtocol::initialized(const Variant &p_params) { - lsp::GodotCapabilities capabilities; DocData *doc = EditorHelp::get_doc_data(); for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) { - lsp::GodotNativeClassInfo gdclass; gdclass.name = E->get().name; gdclass.class_doc = &(E->get()); diff --git a/modules/gdscript/language_server/gdscript_language_server.cpp b/modules/gdscript/language_server/gdscript_language_server.cpp index e1d86ecdd4..d53914814f 100644 --- a/modules/gdscript/language_server/gdscript_language_server.cpp +++ b/modules/gdscript/language_server/gdscript_language_server.cpp @@ -48,7 +48,6 @@ GDScriptLanguageServer::GDScriptLanguageServer() { } void GDScriptLanguageServer::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_ENTER_TREE: start(); diff --git a/modules/gdscript/language_server/gdscript_text_document.cpp b/modules/gdscript/language_server/gdscript_text_document.cpp index f065b33570..778cb4d254 100644 --- a/modules/gdscript/language_server/gdscript_text_document.cpp +++ b/modules/gdscript/language_server/gdscript_text_document.cpp @@ -85,19 +85,15 @@ void GDScriptTextDocument::notify_client_show_symbol(const lsp::DocumentSymbol * } void GDScriptTextDocument::initialize() { - if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) { - const HashMap<StringName, ClassMembers> &native_members = GDScriptLanguageProtocol::get_singleton()->get_workspace()->native_members; const StringName *class_ptr = native_members.next(nullptr); while (class_ptr) { - const ClassMembers &members = native_members.get(*class_ptr); const String *name = members.next(nullptr); while (name) { - const lsp::DocumentSymbol *symbol = members.get(*name); lsp::CompletionItem item = symbol->make_completion_item(); item.data = JOIN_SYMBOLS(String(*class_ptr), *name); @@ -112,7 +108,6 @@ void GDScriptTextDocument::initialize() { } Variant GDScriptTextDocument::nativeSymbol(const Dictionary &p_params) { - Variant ret; lsp::NativeSymbolInspectParams params; @@ -142,7 +137,6 @@ Array GDScriptTextDocument::documentSymbol(const Dictionary &p_params) { } Array GDScriptTextDocument::completion(const Dictionary &p_params) { - Array arr; lsp::CompletionParams params; @@ -153,12 +147,10 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) { GDScriptLanguageProtocol::get_singleton()->get_workspace()->completion(params, &options); if (!options.empty()) { - int i = 0; arr.resize(options.size()); for (const List<ScriptCodeCompletionOption>::Element *E = options.front(); E; E = E->next()) { - const ScriptCodeCompletionOption &option = E->get(); lsp::CompletionItem item; item.label = option.display; @@ -201,11 +193,9 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) { i++; } } else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) { - arr = native_member_completions.duplicate(); for (Map<String, ExtendGDScriptParser *>::Element *E = GDScriptLanguageProtocol::get_singleton()->get_workspace()->scripts.front(); E; E = E->next()) { - ExtendGDScriptParser *script = E->get(); const Array &items = script->get_member_completions(); @@ -220,7 +210,6 @@ Array GDScriptTextDocument::completion(const Dictionary &p_params) { } Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) { - lsp::CompletionItem item; item.load(p_params); @@ -230,18 +219,15 @@ Dictionary GDScriptTextDocument::resolve(const Dictionary &p_params) { const lsp::DocumentSymbol *symbol = nullptr; if (data.get_type() == Variant::DICTIONARY) { - params.load(p_params["data"]); symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params, item.label, item.kind == lsp::CompletionItemKind::Method || item.kind == lsp::CompletionItemKind::Function); } else if (data.get_type() == Variant::STRING) { - String query = data; Vector<String> param_symbols = query.split(SYMBOL_SEPERATOR, false); if (param_symbols.size() >= 2) { - String class_ = param_symbols[0]; StringName class_name = class_; String member_name = param_symbols[param_symbols.size() - 1]; @@ -313,13 +299,11 @@ Array GDScriptTextDocument::colorPresentation(const Dictionary &p_params) { } Variant GDScriptTextDocument::hover(const Dictionary &p_params) { - lsp::TextDocumentPositionParams params; params.load(p_params); const lsp::DocumentSymbol *symbol = GDScriptLanguageProtocol::get_singleton()->get_workspace()->resolve_symbol(params); if (symbol) { - lsp::Hover hover; hover.contents = symbol->render(); hover.range.start = params.position; @@ -327,7 +311,6 @@ Variant GDScriptTextDocument::hover(const Dictionary &p_params) { return hover.to_json(); } else if (GDScriptLanguageProtocol::get_singleton()->is_smart_resolve_enabled()) { - Dictionary ret; Array contents; List<const lsp::DocumentSymbol *> list; diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index be036b44c4..7c432bfc80 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -71,7 +71,6 @@ void GDScriptWorkspace::remove_cache_parser(const String &p_path) { } const lsp::DocumentSymbol *GDScriptWorkspace::get_native_symbol(const String &p_class, const String &p_member) const { - StringName class_name = p_class; StringName empty; @@ -190,7 +189,6 @@ Error GDScriptWorkspace::initialize() { DocData *doc = EditorHelp::get_doc_data(); for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) { - const DocData::ClassDoc &class_data = E->value(); lsp::DocumentSymbol class_symbol; String class_name = E->key(); @@ -315,14 +313,12 @@ Error GDScriptWorkspace::initialize() { } Error GDScriptWorkspace::parse_script(const String &p_path, const String &p_content) { - ExtendGDScriptParser *parser = memnew(ExtendGDScriptParser); Error err = parser->parse(p_content, p_path); Map<String, ExtendGDScriptParser *>::Element *last_parser = parse_results.find(p_path); Map<String, ExtendGDScriptParser *>::Element *last_script = scripts.find(p_path); if (err == OK) { - remove_cache_parser(p_path); parse_results[p_path] = parser; scripts[p_path] = parser; @@ -386,7 +382,6 @@ void GDScriptWorkspace::_get_owners(EditorFileSystemDirectory *efsd, String p_pa } for (int i = 0; i < efsd->get_file_count(); i++) { - Vector<String> deps = efsd->get_file_deps(i); bool found = false; for (int j = 0; j < deps.size(); j++) { @@ -422,7 +417,6 @@ Node *GDScriptWorkspace::_get_owner_scene_node(String p_path) { } void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<ScriptCodeCompletionOption> *r_options) { - String path = get_file_path(p_params.textDocument.uri); String call_hint; bool forced = false; @@ -438,12 +432,10 @@ void GDScriptWorkspace::completion(const lsp::CompletionParams &p_params, List<S } const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocumentPositionParams &p_doc_pos, const String &p_symbol_name, bool p_func_requred) { - const lsp::DocumentSymbol *symbol = nullptr; String path = get_file_path(p_doc_pos.textDocument.uri); if (const ExtendGDScriptParser *parser = get_parse_result(path)) { - String symbol_identifier = p_symbol_name; Vector<String> identifier_parts = symbol_identifier.split("("); if (identifier_parts.size()) { @@ -458,19 +450,14 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu } if (!symbol_identifier.empty()) { - if (ScriptServer::is_global_class(symbol_identifier)) { - String class_path = ScriptServer::get_global_class_path(symbol_identifier); symbol = get_script_symbol(class_path); } else { - ScriptLanguage::LookupResult ret; if (OK == GDScriptLanguage::get_singleton()->lookup_code(parser->get_text_for_lookup_symbol(pos, symbol_identifier, p_func_requred), symbol_identifier, path, nullptr, ret)) { - if (ret.type == ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION) { - String target_script_path = path; if (!ret.script.is_null()) { target_script_path = ret.script->get_path(); @@ -481,7 +468,6 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu } } else { - String member = ret.class_member; if (member.empty() && symbol_identifier != ret.class_name) { member = symbol_identifier; @@ -499,10 +485,8 @@ const lsp::DocumentSymbol *GDScriptWorkspace::resolve_symbol(const lsp::TextDocu } void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionParams &p_doc_pos, List<const lsp::DocumentSymbol *> &r_list) { - String path = get_file_path(p_doc_pos.textDocument.uri); if (const ExtendGDScriptParser *parser = get_parse_result(path)) { - String symbol_identifier; Vector2i offset; symbol_identifier = parser->get_identifier_under_position(p_doc_pos.position, offset); @@ -526,7 +510,6 @@ void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionP const HashMap<String, ClassMembers> &inner_classes = script->get_inner_classes(); const String *_class = inner_classes.next(nullptr); while (_class) { - const ClassMembers *inner_class = inner_classes.getptr(*_class); if (const lsp::DocumentSymbol *const *symbol = inner_class->getptr(symbol_identifier)) { r_list.push_back(*symbol); @@ -539,7 +522,6 @@ void GDScriptWorkspace::resolve_related_symbols(const lsp::TextDocumentPositionP } const lsp::DocumentSymbol *GDScriptWorkspace::resolve_native_symbol(const lsp::NativeSymbolInspectParams &p_params) { - if (Map<StringName, lsp::DocumentSymbol>::Element *E = native_symbols.find(p_params.native_class)) { const lsp::DocumentSymbol &symbol = E->get(); if (p_params.symbol_name.empty() || p_params.symbol_name == symbol.name) { @@ -575,12 +557,10 @@ Dictionary GDScriptWorkspace::generate_script_api(const String &p_path) { Error GDScriptWorkspace::resolve_signature(const lsp::TextDocumentPositionParams &p_doc_pos, lsp::SignatureHelp &r_signature) { if (const ExtendGDScriptParser *parser = get_parse_result(get_file_path(p_doc_pos.textDocument.uri))) { - lsp::TextDocumentPositionParams text_pos; text_pos.textDocument = p_doc_pos.textDocument; if (parser->get_left_function_call(p_doc_pos.position, text_pos.position, r_signature.activeParameter) == OK) { - List<const lsp::DocumentSymbol *> symbols; if (const lsp::DocumentSymbol *symbol = resolve_symbol(text_pos)) { @@ -592,7 +572,6 @@ Error GDScriptWorkspace::resolve_signature(const lsp::TextDocumentPositionParams for (List<const lsp::DocumentSymbol *>::Element *E = symbols.front(); E; E = E->next()) { const lsp::DocumentSymbol *symbol = E->get(); if (symbol->kind == lsp::SymbolKind::Method || symbol->kind == lsp::SymbolKind::Function) { - lsp::SignatureInformation signature_info; signature_info.label = symbol->detail; signature_info.documentation = symbol->render(); diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp index e469a26df8..f979171b6e 100644 --- a/modules/gdscript/language_server/lsp.hpp +++ b/modules/gdscript/language_server/lsp.hpp @@ -149,7 +149,6 @@ struct Location { * Represents a link between a source and a target location. */ struct LocationLink { - /** * Span of the origin of this link. * @@ -220,7 +219,6 @@ struct DocumentLinkParams { * text document or a web site. */ struct DocumentLink { - /** * The range this link applies to. */ @@ -1107,7 +1105,6 @@ struct DocumentedSymbolInformation : public SymbolInformation { * e.g. the range of an identifier. */ struct DocumentSymbol { - /** * The name of this symbol. Will be displayed in the user interface and therefore must not be * an empty string or a string only consisting of white spaces. @@ -1216,7 +1213,6 @@ struct DocumentSymbol { } _FORCE_INLINE_ CompletionItem make_completion_item(bool resolved = false) const { - lsp::CompletionItem item; item.label = name; @@ -1260,7 +1256,6 @@ struct DocumentSymbol { }; struct NativeSymbolInspectParams { - String native_class; String symbol_name; @@ -1292,7 +1287,6 @@ static const String Region = "region"; * Represents a folding range. */ struct FoldingRange { - /** * The zero-based line number from where the folded range starts. */ @@ -1375,7 +1369,6 @@ struct CompletionContext { }; struct CompletionParams : public TextDocumentPositionParams { - /** * The completion context. This is only available if the client specifies * to send this using `ClientCapabilities.textDocument.completion.contextSupport === true` @@ -1416,7 +1409,6 @@ struct Hover { * have a label and a doc-comment. */ struct ParameterInformation { - /** * The label of this parameter information. * @@ -1695,7 +1687,6 @@ struct InitializeResult { }; struct GodotNativeClassInfo { - String name; const DocData::ClassDoc *class_doc = nullptr; const ClassDB::ClassInfo *class_info = nullptr; @@ -1710,7 +1701,6 @@ struct GodotNativeClassInfo { /** Features not included in the standard lsp specifications */ struct GodotCapabilities { - /** * Native class list */ @@ -1729,7 +1719,6 @@ struct GodotCapabilities { /** Format BBCode documentation from DocData to markdown */ static String marked_documentation(const String &p_bbcode) { - String markdown = p_bbcode.strip_edges(); Vector<String> lines = markdown.split("\n"); diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 62b9d94d6c..161ab692c9 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -54,12 +54,10 @@ Ref<ResourceFormatSaverGDScript> resource_saver_gd; #endif // !GDSCRIPT_NO_LSP class EditorExportGDScript : public EditorExportPlugin { - GDCLASS(EditorExportGDScript, EditorExportPlugin); public: virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features) { - int script_mode = EditorExportPreset::MODE_SCRIPT_COMPILED; String script_key; @@ -82,9 +80,7 @@ public: file = GDScriptTokenizerBuffer::parse_code_string(txt); if (!file.empty()) { - if (script_mode == EditorExportPreset::MODE_SCRIPT_ENCRYPTED) { - String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("script.gde"); FileAccess *fa = FileAccess::open(tmp_path, FileAccess::WRITE); @@ -127,7 +123,6 @@ public: DirAccess::remove_file_or_error(tmp_path); } else { - add_file(p_path.get_basename() + ".gdc", file, true); } } @@ -135,7 +130,6 @@ public: }; static void _editor_init() { - Ref<EditorExportGDScript> gd_export; gd_export.instance(); EditorExport::get_singleton()->add_export_plugin(gd_export); @@ -151,7 +145,6 @@ static void _editor_init() { #endif // TOOLS_ENABLED void register_gdscript_types() { - ClassDB::register_class<GDScript>(); ClassDB::register_virtual_class<GDScriptFunctionState>(); @@ -171,7 +164,6 @@ void register_gdscript_types() { } void unregister_gdscript_types() { - ScriptServer::unregister_language(script_language_gd); if (script_language_gd) diff --git a/modules/glslang/register_types.cpp b/modules/glslang/register_types.cpp index 5203460830..736c85eb0b 100644 --- a/modules/glslang/register_types.cpp +++ b/modules/glslang/register_types.cpp @@ -143,7 +143,6 @@ static const TBuiltInResource default_builtin_resource = { }; static Vector<uint8_t> _compile_shader_glsl(RenderingDevice::ShaderStage p_stage, const String &p_source_code, RenderingDevice::ShaderLanguage p_language, String *r_error) { - Vector<uint8_t> ret; ERR_FAIL_COND_V(p_language == RenderingDevice::SHADER_LANGUAGE_HLSL, ret); @@ -177,7 +176,6 @@ static Vector<uint8_t> _compile_shader_glsl(RenderingDevice::ShaderStage p_stage //preprocess if (!shader.preprocess(&default_builtin_resource, DefaultVersion, ENoProfile, false, false, messages, &pre_processed_code, includer)) { - if (r_error) { (*r_error) = "Failed pre-process:\n"; (*r_error) += shader.getInfoLog(); @@ -241,6 +239,5 @@ void preregister_glslang_types() { void register_glslang_types() { } void unregister_glslang_types() { - glslang::FinalizeProcess(); } diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 0dbefbb39f..cf14447232 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -40,22 +40,18 @@ #include "servers/rendering_server.h" bool GridMap::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; if (name == "data") { - Dictionary d = p_value; if (d.has("cells")) { - Vector<int> cells = d["cells"]; int amount = cells.size(); const int *r = cells.ptr(); ERR_FAIL_COND_V(amount % 3, false); // not even cell_map.clear(); for (int i = 0; i < amount / 3; i++) { - IndexKey ik; ik.key = decode_uint64((const uint8_t *)&r[i * 3]); Cell cell; @@ -67,7 +63,6 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { _recreate_octant_data(); } else if (name == "baked_meshes") { - clear_baked_meshes(); Array meshes = p_value; @@ -96,11 +91,9 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) { } bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; if (name == "data") { - Dictionary d; Vector<int> cells; @@ -109,7 +102,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { int *w = cells.ptrw(); int i = 0; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next(), i++) { - encode_uint64(E->key().key, (uint8_t *)&w[i * 3]); encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]); } @@ -119,7 +111,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { r_ret = d; } else if (name == "baked_meshes") { - Array ret; ret.resize(baked_meshes.size()); for (int i = 0; i < baked_meshes.size(); i++) { @@ -134,7 +125,6 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { } void GridMap::_get_property_list(List<PropertyInfo> *p_list) const { - if (baked_meshes.size()) { p_list->push_back(PropertyInfo(Variant::ARRAY, "baked_meshes", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); } @@ -143,29 +133,24 @@ void GridMap::_get_property_list(List<PropertyInfo> *p_list) const { } void GridMap::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; _reset_physic_bodies_collision_filters(); } uint32_t GridMap::get_collision_layer() const { - return collision_layer; } void GridMap::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; _reset_physic_bodies_collision_filters(); } uint32_t GridMap::get_collision_mask() const { - return collision_mask; } void GridMap::set_collision_mask_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -175,12 +160,10 @@ void GridMap::set_collision_mask_bit(int p_bit, bool p_value) { } bool GridMap::get_collision_mask_bit(int p_bit) const { - return get_collision_mask() & (1 << p_bit); } void GridMap::set_collision_layer_bit(int p_bit, bool p_value) { - uint32_t mask = get_collision_layer(); if (p_value) mask |= 1 << p_bit; @@ -190,12 +173,10 @@ void GridMap::set_collision_layer_bit(int p_bit, bool p_value) { } bool GridMap::get_collision_layer_bit(int p_bit) const { - return get_collision_layer() & (1 << p_bit); } void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) { - if (!mesh_library.is_null()) mesh_library->unregister_owner(this); mesh_library = p_mesh_library; @@ -207,7 +188,6 @@ void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) { } Ref<MeshLibrary> GridMap::get_mesh_library() const { - return mesh_library; } @@ -218,23 +198,19 @@ void GridMap::set_cell_size(const Vector3 &p_size) { emit_signal("cell_size_changed", cell_size); } Vector3 GridMap::get_cell_size() const { - return cell_size; } void GridMap::set_octant_size(int p_size) { - ERR_FAIL_COND(p_size == 0); octant_size = p_size; _recreate_octant_data(); } int GridMap::get_octant_size() const { - return octant_size; } void GridMap::set_center_x(bool p_enable) { - center_x = p_enable; _recreate_octant_data(); } @@ -244,7 +220,6 @@ bool GridMap::get_center_x() const { } void GridMap::set_center_y(bool p_enable) { - center_y = p_enable; _recreate_octant_data(); } @@ -254,7 +229,6 @@ bool GridMap::get_center_y() const { } void GridMap::set_center_z(bool p_enable) { - center_z = p_enable; _recreate_octant_data(); } @@ -264,7 +238,6 @@ bool GridMap::get_center_z() const { } void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { - if (baked_meshes.size() && !recreating_octants) { //if you set a cell item, baked meshes go good bye clear_baked_meshes(); @@ -313,7 +286,6 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { SceneTree *st = SceneTree::get_singleton(); if (st && st->is_debugging_collisions_hint()) { - g->collision_debug = RenderingServer::get_singleton()->mesh_create(); g->collision_debug_instance = RenderingServer::get_singleton()->instance_create(); RenderingServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug); @@ -340,7 +312,6 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { } int GridMap::get_cell_item(int p_x, int p_y, int p_z) const { - ERR_FAIL_INDEX_V(ABS(p_x), 1 << 20, INVALID_CELL_ITEM); ERR_FAIL_INDEX_V(ABS(p_y), 1 << 20, INVALID_CELL_ITEM); ERR_FAIL_INDEX_V(ABS(p_z), 1 << 20, INVALID_CELL_ITEM); @@ -356,7 +327,6 @@ int GridMap::get_cell_item(int p_x, int p_y, int p_z) const { } int GridMap::get_cell_item_orientation(int p_x, int p_y, int p_z) const { - ERR_FAIL_INDEX_V(ABS(p_x), 1 << 20, -1); ERR_FAIL_INDEX_V(ABS(p_y), 1 << 20, -1); ERR_FAIL_INDEX_V(ABS(p_z), 1 << 20, -1); @@ -389,7 +359,6 @@ Vector3 GridMap::map_to_world(int p_x, int p_y, int p_z) const { } void GridMap::_octant_transform(const OctantKey &p_key) { - ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); @@ -414,7 +383,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { //erase body shapes debug if (g.collision_debug.is_valid()) { - RS::get_singleton()->mesh_clear(g.collision_debug); } @@ -427,7 +395,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { //erase multimeshes for (int i = 0; i < g.multimesh_instances.size(); i++) { - RS::get_singleton()->free(g.multimesh_instances[i].instance); RS::get_singleton()->free(g.multimesh_instances[i].multimesh); } @@ -450,7 +417,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { Map<int, List<Pair<Transform, IndexKey>>> multimesh_items; for (Set<IndexKey>::Element *E = g.cells.front(); E; E = E->next()) { - ERR_CONTINUE(!cell_map.has(E->get())); const Cell &c = cell_map[E->get()]; @@ -509,7 +475,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { //update multimeshes, only if not baked if (baked_meshes.size() == 0) { - for (Map<int, List<Pair<Transform, IndexKey>>>::Element *E = multimesh_items.front(); E; E = E->next()) { Octant::MultimeshInstance mmi; @@ -548,7 +513,6 @@ bool GridMap::_octant_update(const OctantKey &p_key) { } if (col_debug.size()) { - Array arr; arr.resize(RS::ARRAY_MAX); arr[RS::ARRAY_VERTEX] = col_debug; @@ -573,7 +537,6 @@ void GridMap::_reset_physic_bodies_collision_filters() { } void GridMap::_octant_enter_world(const OctantKey &p_key) { - ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); @@ -591,7 +554,6 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { if (navigation && mesh_library.is_valid()) { for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) { - if (cell_map.has(F->key()) && F->get().region.is_valid() == false) { Ref<NavigationMesh> nm = mesh_library->get_item_navmesh(cell_map[F->key()].item); if (nm.is_valid()) { @@ -607,14 +569,12 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) { } void GridMap::_octant_exit_world(const OctantKey &p_key) { - ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; PhysicsServer3D::get_singleton()->body_set_state(g.static_body, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); PhysicsServer3D::get_singleton()->body_set_space(g.static_body, RID()); if (g.collision_debug_instance.is_valid()) { - RS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID()); } @@ -624,7 +584,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { if (navigation) { for (Map<IndexKey, Octant::NavMesh>::Element *F = g.navmesh_ids.front(); F; F = F->next()) { - if (F->get().region.is_valid()) { NavigationServer3D::get_singleton()->free(F->get().region); F->get().region = RID(); @@ -634,7 +593,6 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) { } void GridMap::_octant_clean_up(const OctantKey &p_key) { - ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; @@ -654,7 +612,6 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { //erase multimeshes for (int i = 0; i < g.multimesh_instances.size(); i++) { - RS::get_singleton()->free(g.multimesh_instances[i].instance); RS::get_singleton()->free(g.multimesh_instances[i].multimesh); } @@ -662,11 +619,8 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { } void GridMap::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_WORLD: { - Node3D *c = this; while (c) { navigation = Object::cast_to<Navigation3D>(c); @@ -690,7 +644,6 @@ void GridMap::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - Transform new_xform = get_global_transform(); if (new_xform == last_transform) break; @@ -707,7 +660,6 @@ void GridMap::_notification(int p_what) { } break; case NOTIFICATION_EXIT_WORLD: { - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { _octant_exit_world(E->key()); } @@ -744,7 +696,6 @@ void GridMap::_update_visibility() { } void GridMap::_queue_octants_dirty() { - if (awaiting_update) return; @@ -753,19 +704,16 @@ void GridMap::_queue_octants_dirty() { } void GridMap::_recreate_octant_data() { - recreating_octants = true; Map<IndexKey, Cell> cell_copy = cell_map; _clear_internal(); for (Map<IndexKey, Cell>::Element *E = cell_copy.front(); E; E = E->next()) { - set_cell_item(E->key().x, E->key().y, E->key().z, E->get().item, E->get().rot); } recreating_octants = false; } void GridMap::_clear_internal() { - for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { if (is_inside_world()) _octant_exit_world(E->key()); @@ -779,24 +727,20 @@ void GridMap::_clear_internal() { } void GridMap::clear() { - _clear_internal(); clear_baked_meshes(); } void GridMap::resource_changed(const RES &p_res) { - _recreate_octant_data(); } void GridMap::_update_octants_callback() { - if (!awaiting_update) return; List<OctantKey> to_delete; for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - if (_octant_update(E->key())) { to_delete.push_back(E->key()); } @@ -812,7 +756,6 @@ void GridMap::_update_octants_callback() { } void GridMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &GridMap::set_collision_layer); ClassDB::bind_method(D_METHOD("get_collision_layer"), &GridMap::get_collision_layer); @@ -885,7 +828,6 @@ void GridMap::_bind_methods() { } void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3::Axis p_axis) { - if (!p_enabled && !clip) return; if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis) @@ -898,7 +840,6 @@ void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3:: //make it all update for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - Octant *g = E->get(); g->dirty = true; } @@ -907,18 +848,15 @@ void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3:: } void GridMap::set_cell_scale(float p_scale) { - cell_scale = p_scale; _recreate_octant_data(); } float GridMap::get_cell_scale() const { - return cell_scale; } Array GridMap::get_used_cells() const { - Array a; a.resize(cell_map.size()); int i = 0; @@ -931,7 +869,6 @@ Array GridMap::get_used_cells() const { } Array GridMap::get_meshes() { - if (mesh_library.is_null()) return Array(); @@ -939,7 +876,6 @@ Array GridMap::get_meshes() { Array meshes; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { - int id = E->get().item; if (!mesh_library->has_item(id)) continue; @@ -973,7 +909,6 @@ Vector3 GridMap::_get_offset() const { } void GridMap::clear_baked_meshes() { - for (int i = 0; i < baked_meshes.size(); i++) { RS::get_singleton()->free(baked_meshes[i].instance); } @@ -983,7 +918,6 @@ void GridMap::clear_baked_meshes() { } void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texel_size) { - if (!mesh_library.is_valid()) return; @@ -991,7 +925,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> surface_map; for (Map<IndexKey, Cell>::Element *E = cell_map.front(); E; E = E->next()) { - IndexKey key = E->key(); int item = E->get().item; @@ -1023,7 +956,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe Map<Ref<Material>, Ref<SurfaceTool>> &mat_map = surface_map[ok]; for (int i = 0; i < mesh->get_surface_count(); i++) { - if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) continue; @@ -1041,7 +973,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe } for (Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>>::Element *E = surface_map.front(); E; E = E->next()) { - Ref<ArrayMesh> mesh; mesh.instance(); for (Map<Ref<Material>, Ref<SurfaceTool>>::Element *F = E->get().front(); F; F = F->next()) { @@ -1068,7 +999,6 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe } Array GridMap::get_bake_meshes() { - if (!baked_meshes.size()) { make_baked_meshes(true); } @@ -1083,13 +1013,11 @@ Array GridMap::get_bake_meshes() { } RID GridMap::get_bake_mesh_instance(int p_idx) { - ERR_FAIL_INDEX_V(p_idx, baked_meshes.size(), RID()); return baked_meshes[p_idx].instance; } GridMap::GridMap() { - collision_layer = 1; collision_mask = 1; @@ -1113,7 +1041,6 @@ GridMap::GridMap() { } GridMap::~GridMap() { - if (!mesh_library.is_null()) mesh_library->unregister_owner(this); diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 3f3da09fe9..9eb9aee7d1 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -40,7 +40,6 @@ //should scale better with hardware that supports instancing class GridMap : public Node3D { - GDCLASS(GridMap, Node3D); enum { @@ -49,7 +48,6 @@ class GridMap : public Node3D { }; union IndexKey { - struct { int16_t x; int16_t y; @@ -58,7 +56,6 @@ class GridMap : public Node3D { uint64_t key; _FORCE_INLINE_ bool operator<(const IndexKey &p_key) const { - return key < p_key.key; } @@ -69,7 +66,6 @@ class GridMap : public Node3D { * @brief A Cell is a single cell in the cube map space; it is defined by its coordinates and the populating Item, identified by int id. */ union Cell { - struct { unsigned int item : 16; unsigned int rot : 5; @@ -89,7 +85,6 @@ class GridMap : public Node3D { * A GridMap can have multiple Octants. */ struct Octant { - struct NavMesh { RID region; Transform xform; @@ -118,7 +113,6 @@ class GridMap : public Node3D { }; union OctantKey { - struct { int16_t x; int16_t y; @@ -129,7 +123,6 @@ class GridMap : public Node3D { uint64_t key; _FORCE_INLINE_ bool operator<(const OctantKey &p_key) const { - return key < p_key.key; } @@ -165,7 +158,6 @@ class GridMap : public Node3D { void _recreate_octant_data(); struct BakeLight { - RS::LightType type; Vector3 pos; Vector3 dir; @@ -173,7 +165,6 @@ class GridMap : public Node3D { }; _FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const { - return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size; } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index fc545430f5..e8f7d09bb2 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -40,13 +40,11 @@ #include "scene/main/window.h" void GridMapEditor::_node_removed(Node *p_node) { - if (p_node == node) node = nullptr; } void GridMapEditor::_configure() { - if (!node) return; @@ -54,9 +52,7 @@ void GridMapEditor::_configure() { } void GridMapEditor::_menu_option(int p_option) { - switch (p_option) { - case MENU_OPTION_PREV_LEVEL: { floor->set_value(floor->get_value() - 1); } break; @@ -66,7 +62,6 @@ void GridMapEditor::_menu_option(int p_option) { } break; case MENU_OPTION_LOCK_VIEW: { - int index = options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW); lock_view = !options->get_popup()->is_item_checked(index); @@ -75,10 +70,8 @@ void GridMapEditor::_menu_option(int p_option) { case MENU_OPTION_CLIP_DISABLED: case MENU_OPTION_CLIP_ABOVE: case MENU_OPTION_CLIP_BELOW: { - clip_mode = ClipMode(p_option - MENU_OPTION_CLIP_DISABLED); for (int i = 0; i < 3; i++) { - int index = options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED + i); options->get_popup()->set_item_checked(index, i == clip_mode); } @@ -88,7 +81,6 @@ void GridMapEditor::_menu_option(int p_option) { case MENU_OPTION_X_AXIS: case MENU_OPTION_Y_AXIS: case MENU_OPTION_Z_AXIS: { - int new_axis = p_option - MENU_OPTION_X_AXIS; for (int i = 0; i < 3; i++) { int idx = options->get_popup()->get_item_index(MENU_OPTION_X_AXIS + i); @@ -114,10 +106,8 @@ void GridMapEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CURSOR_ROTATE_Y: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -131,10 +121,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_ROTATE_X: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -148,10 +136,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_ROTATE_Z: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -165,10 +151,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_Y: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(0, 1, 0), Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -182,10 +166,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_X: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(1, 0, 0), Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -199,10 +181,8 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_Z: { - Basis r; if (input_action == INPUT_PASTE) { - r.set_orthogonal_index(paste_indicator.orientation); r.rotate(Vector3(0, 0, 1), Math_PI / 2.0); paste_indicator.orientation = r.get_orthogonal_index(); @@ -216,9 +196,7 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_CLEAR_ROTATION: { - if (input_action == INPUT_PASTE) { - paste_indicator.orientation = 0; _update_paste_indicator(); break; @@ -273,7 +251,6 @@ void GridMapEditor::_menu_option(int p_option) { } void GridMapEditor::_update_cursor_transform() { - cursor_transform = Transform(); cursor_transform.origin = cursor_origin; cursor_transform.basis.set_orthogonal_index(cursor_rot); @@ -291,7 +268,6 @@ void GridMapEditor::_update_selection_transform() { xf_zero.basis.set_zero(); if (!selection.active) { - RenderingServer::get_singleton()->instance_set_transform(selection_instance, xf_zero); for (int i = 0; i < 3; i++) { RenderingServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf_zero); @@ -309,7 +285,6 @@ void GridMapEditor::_update_selection_transform() { if (i != edit_axis || (edit_floor[edit_axis] < selection.begin[edit_axis]) || (edit_floor[edit_axis] > selection.end[edit_axis] + 1)) { RenderingServer::get_singleton()->instance_set_transform(selection_level_instance[i], xf_zero); } else { - Vector3 scale = (selection.end - selection.begin + Vector3(1, 1, 1)); scale[edit_axis] = 1.0; Vector3 pos = selection.begin; @@ -328,7 +303,6 @@ void GridMapEditor::_update_selection_transform() { } void GridMapEditor::_validate_selection() { - if (!selection.active) return; selection.begin = selection.click; @@ -345,7 +319,6 @@ void GridMapEditor::_validate_selection() { } void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const Vector3 &p_end) { - selection.active = p_active; selection.begin = p_begin; selection.end = p_end; @@ -363,7 +336,6 @@ void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const } bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, bool p_click) { - if (!spatial_editor) return false; @@ -394,7 +366,6 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b // Make sure the intersection is inside the frustum planes, to avoid // Painting on invisible regions. for (int i = 0; i < planes.size(); i++) { - Plane fp = local_xform.xform(planes[i]); if (fp.is_point_over(inters)) return false; @@ -404,11 +375,9 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b float cell_size[3] = { node->get_cell_size().x, node->get_cell_size().y, node->get_cell_size().z }; for (int i = 0; i < 3; i++) { - if (i == edit_axis) cell[i] = edit_floor[i]; else { - cell[i] = inters[i] / node->get_cell_size()[i]; if (inters[i] < 0) cell[i] -= 1; // Compensate negative. @@ -419,7 +388,6 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b RS::get_singleton()->instance_set_transform(grid_instance[edit_axis], node->get_global_transform() * edit_grid_xform); if (cursor_instance.is_valid()) { - cursor_origin = (Vector3(cell[0], cell[1], cell[2]) + Vector3(0.5 * node->get_center_x(), 0.5 * node->get_center_y(), 0.5 * node->get_center_z())) * node->get_cell_size(); cursor_visible = true; @@ -431,12 +399,10 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b } if (input_action == INPUT_PASTE) { - paste_indicator.current = Vector3(cell[0], cell[1], cell[2]); _update_paste_indicator(); } else if (input_action == INPUT_SELECT) { - selection.current = Vector3(cell[0], cell[1], cell[2]); if (p_click) selection.click = selection.current; @@ -445,7 +411,6 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b return true; } else if (input_action == INPUT_PICK) { - int item = node->get_cell_item(cell[0], cell[1], cell[2]); if (item >= 0) { selected_palette = item; @@ -481,17 +446,13 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b } void GridMapEditor::_delete_selection() { - if (!selection.active) return; undo_redo->create_action(TTR("GridMap Delete Selection")); for (int i = selection.begin.x; i <= selection.end.x; i++) { - for (int j = selection.begin.y; j <= selection.end.y; j++) { - for (int k = selection.begin.z; k <= selection.end.z; k++) { - undo_redo->add_do_method(node, "set_cell_item", i, j, k, GridMap::INVALID_CELL_ITEM); undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k)); } @@ -503,17 +464,13 @@ void GridMapEditor::_delete_selection() { } void GridMapEditor::_fill_selection() { - if (!selection.active) return; undo_redo->create_action(TTR("GridMap Fill Selection")); for (int i = selection.begin.x; i <= selection.end.x; i++) { - for (int j = selection.begin.y; j <= selection.end.y; j++) { - for (int k = selection.begin.z; k <= selection.end.z; k++) { - undo_redo->add_do_method(node, "set_cell_item", i, j, k, selected_palette, cursor_rot); undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k)); } @@ -525,9 +482,7 @@ void GridMapEditor::_fill_selection() { } void GridMapEditor::_clear_clipboard_data() { - for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) { - RenderingServer::get_singleton()->free(E->get().instance); } @@ -535,17 +490,13 @@ void GridMapEditor::_clear_clipboard_data() { } void GridMapEditor::_set_clipboard_data() { - _clear_clipboard_data(); Ref<MeshLibrary> meshLibrary = node->get_mesh_library(); for (int i = selection.begin.x; i <= selection.end.x; i++) { - for (int j = selection.begin.y; j <= selection.end.y; j++) { - for (int k = selection.begin.z; k <= selection.end.z; k++) { - int itm = node->get_cell_item(i, j, k); if (itm == GridMap::INVALID_CELL_ITEM) continue; @@ -565,9 +516,7 @@ void GridMapEditor::_set_clipboard_data() { } void GridMapEditor::_update_paste_indicator() { - if (input_action != INPUT_PASTE) { - Transform xf; xf.basis.set_zero(); RenderingServer::get_singleton()->instance_set_transform(paste_instance, xf); @@ -587,7 +536,6 @@ void GridMapEditor::_update_paste_indicator() { RenderingServer::get_singleton()->instance_set_transform(paste_instance, node->get_global_transform() * xf); for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) { - ClipboardItem &item = E->get(); xf = Transform(); @@ -604,7 +552,6 @@ void GridMapEditor::_update_paste_indicator() { } void GridMapEditor::_do_paste() { - int idx = options->get_popup()->get_item_index(MENU_OPTION_PASTE_SELECTS); bool reselect = options->get_popup()->is_item_checked(idx); @@ -615,7 +562,6 @@ void GridMapEditor::_do_paste() { undo_redo->create_action(TTR("GridMap Paste Selection")); for (List<ClipboardItem>::Element *E = clipboard_items.front(); E; E = E->next()) { - ClipboardItem &item = E->get(); Vector3 pos = rot.xform(item.grid_offset) + paste_indicator.begin + ofs; @@ -629,7 +575,6 @@ void GridMapEditor::_do_paste() { } if (reselect) { - undo_redo->add_do_method(this, "_set_selection", true, paste_indicator.begin + ofs, paste_indicator.end + ofs); undo_redo->add_undo_method(this, "_set_selection", selection.active, selection.begin, selection.end); } @@ -647,7 +592,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { - if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) { if (mb->is_pressed()) floor->set_value(floor->get_value() + mb->get_factor()); @@ -664,7 +608,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In if ((nav_scheme == Node3DEditorViewport::NAVIGATION_MAYA || nav_scheme == Node3DEditorViewport::NAVIGATION_MODO) && mb->get_alt()) { input_action = INPUT_NONE; } else if (mb->get_button_index() == BUTTON_LEFT) { - bool can_edit = (node && node->get_mesh_library().is_valid()); if (input_action == INPUT_PASTE) { _do_paste(); @@ -698,18 +641,14 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); } else { - if ((mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) || (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) { - if (set_items.size()) { undo_redo->create_action(TTR("GridMap Paint")); for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) { - const SetItem &si = E->get(); undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); } for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) { - const SetItem &si = E->get(); undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); } @@ -722,7 +661,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In } if (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_SELECT) { - undo_redo->create_action("GridMap Selection"); undo_redo->add_do_method(this, "_set_selection", selection.active, selection.begin, selection.end); undo_redo->add_undo_method(this, "_set_selection", last_selection.active, last_selection.begin, last_selection.end); @@ -730,7 +668,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In } if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) { - set_items.clear(); input_action = INPUT_NONE; return true; @@ -745,7 +682,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In Ref<InputEventMouseMotion> mm = p_event; if (mm.is_valid()) { - return do_input_action(p_camera, mm->get_position(), false); } @@ -754,7 +690,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In if (k.is_valid()) { if (k->is_pressed()) { if (k->get_keycode() == KEY_ESCAPE) { - if (input_action == INPUT_PASTE) { _clear_clipboard_data(); input_action = INPUT_NONE; @@ -773,7 +708,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In } if (k->get_shift() && selection.active && input_action != INPUT_PASTE) { - if (k->get_keycode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) { selection.click[edit_axis]--; _validate_selection(); @@ -790,7 +724,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { - if (pan_gesture->get_alt() && (pan_gesture->get_command() || pan_gesture->get_shift())) { const real_t delta = pan_gesture->get_delta().y * 0.5; accumulated_floor_delta += delta; @@ -811,7 +744,6 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In } struct _CGMEItemSort { - String name; int id; _FORCE_INLINE_ bool operator<(const _CGMEItemSort &r_it) const { return name < r_it.name; } @@ -840,11 +772,9 @@ void GridMapEditor::_text_changed(const String &p_text) { } void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { - const Ref<InputEventKey> k = p_ie; if (k.is_valid() && (k->get_keycode() == KEY_UP || k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) { - // Forward the key input to the ItemList so it can be scrolled mesh_library_palette->call("_gui_input", k); search_box->accept_event(); @@ -852,12 +782,10 @@ void GridMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { } void GridMapEditor::_mesh_library_palette_input(const Ref<InputEvent> &p_ie) { - const Ref<InputEventMouseButton> mb = p_ie; // Zoom in/out using Ctrl + mouse wheel if (mb.is_valid() && mb->is_pressed() && mb->get_command()) { - if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) { size_slider->set_value(size_slider->get_value() + 0.2); } @@ -911,7 +839,6 @@ void GridMapEditor::update_palette() { List<_CGMEItemSort> il; for (int i = 0; i < ids.size(); i++) { - _CGMEItemSort is; is.id = ids[i]; is.name = mesh_library->get_item_name(ids[i]); @@ -993,7 +920,6 @@ void GridMapEditor::edit(GridMap *p_gridmap) { } void GridMapEditor::_update_clip() { - node->set_meta("_editor_clip_", clip_mode); if (clip_mode == CLIP_DISABLED) node->set_clip(false); @@ -1002,7 +928,6 @@ void GridMapEditor::_update_clip() { } void GridMapEditor::update_grid() { - grid_xform.origin.x -= 1; // Force update in hackish way. grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size()[edit_axis]; @@ -1031,7 +956,6 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) { Vector<Color> grid_colors[3]; for (int i = 0; i < 3; i++) { - Vector3 axis; axis[i] = 1; Vector3 axis_n1; @@ -1040,9 +964,7 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) { axis_n2[(i + 2) % 3] = cell_size[(i + 2) % 3]; for (int j = -GRID_CURSOR_SIZE; j <= GRID_CURSOR_SIZE; j++) { - for (int k = -GRID_CURSOR_SIZE; k <= GRID_CURSOR_SIZE; k++) { - Vector3 p = axis_n1 * j + axis_n2 * k; float trans = Math::pow(MAX(0, 1.0 - (Vector2(j, k).length() / GRID_CURSOR_SIZE)), 2); @@ -1074,14 +996,11 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) { } void GridMapEditor::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { get_tree()->connect("node_removed", callable_mp(this, &GridMapEditor::_node_removed)); mesh_library_palette->connect("item_selected", callable_mp(this, &GridMapEditor::_item_selected_cbk)); for (int i = 0; i < 3; i++) { - grid[i] = RS::get_singleton()->mesh_create(); grid_instance[i] = RS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world_3d()->get_scenario()); selection_level_instance[i] = RenderingServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world_3d()->get_scenario()); @@ -1099,7 +1018,6 @@ void GridMapEditor::_notification(int p_what) { _clear_clipboard_data(); for (int i = 0; i < 3; i++) { - RS::get_singleton()->free(grid_instance[i]); RS::get_singleton()->free(grid[i]); grid_instance[i] = RID(); @@ -1122,7 +1040,6 @@ void GridMapEditor::_notification(int p_what) { if (xf != grid_xform) { for (int i = 0; i < 3; i++) { - RS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform); } grid_xform = xf; @@ -1132,7 +1049,6 @@ void GridMapEditor::_notification(int p_what) { update_palette(); if (lock_view) { - EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0)); Plane p; @@ -1163,11 +1079,9 @@ void GridMapEditor::_update_cursor_instance() { cursor_instance = RID(); if (selected_palette >= 0) { - if (node && !node->get_mesh_library().is_null()) { Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette); if (!mesh.is_null() && mesh->get_rid().is_valid()) { - cursor_instance = RenderingServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world_3d()->get_scenario()); RenderingServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform); } @@ -1182,7 +1096,6 @@ void GridMapEditor::_item_selected_cbk(int idx) { } void GridMapEditor::_floor_changed(float p_value) { - if (updating) return; @@ -1198,13 +1111,11 @@ void GridMapEditor::_floor_mouse_exited() { } void GridMapEditor::_bind_methods() { - ClassDB::bind_method("_configure", &GridMapEditor::_configure); ClassDB::bind_method("_set_selection", &GridMapEditor::_set_selection); } GridMapEditor::GridMapEditor(EditorNode *p_editor) { - input_action = INPUT_NONE; editor = p_editor; undo_redo = p_editor->get_undo_redo(); @@ -1364,18 +1275,15 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { Vector<Vector3> square[3]; for (int i = 0; i < 6; i++) { - Vector3 face_points[4]; for (int j = 0; j < 4; j++) { - float v[3]; v[0] = 1.0; v[1] = 1 - 2 * ((j >> 1) & 1); v[2] = v[1] * (1 - 2 * (j & 1)); for (int k = 0; k < 3; k++) { - if (i < 3) face_points[j][(i + k) % 3] = v[k]; else @@ -1393,7 +1301,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { } for (int i = 0; i < 12; i++) { - AABB base(Vector3(0, 0, 0), Vector3(1, 1, 1)); Vector3 a, b; base.get_edge(i, a, b); @@ -1404,7 +1311,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { for (int i = 0; i < 3; i++) { Vector3 points[4]; for (int j = 0; j < 4; j++) { - static const bool orderx[4] = { false, true, true, false }; static const bool ordery[4] = { false, false, true, true }; @@ -1420,7 +1326,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { } for (int j = 0; j < 4; j++) { - Vector3 ofs; ofs[i] += 0.01; square[i].push_back(points[j] - ofs); @@ -1487,11 +1392,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { } GridMapEditor::~GridMapEditor() { - _clear_clipboard_data(); for (int i = 0; i < 3; i++) { - if (grid[i].is_valid()) RenderingServer::get_singleton()->free(grid[i]); if (grid_instance[i].is_valid()) @@ -1514,9 +1417,7 @@ GridMapEditor::~GridMapEditor() { } void GridMapEditorPlugin::_notification(int p_what) { - if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - switch ((int)EditorSettings::get_singleton()->get("editors/grid_map/editor_side")) { case 0: { // Left. Node3DEditor::get_singleton()->get_palette_split()->move_child(grid_map_editor, 0); @@ -1529,23 +1430,19 @@ void GridMapEditorPlugin::_notification(int p_what) { } void GridMapEditorPlugin::edit(Object *p_object) { - grid_map_editor->edit(Object::cast_to<GridMap>(p_object)); } bool GridMapEditorPlugin::handles(Object *p_object) const { - return p_object->is_class("GridMap"); } void GridMapEditorPlugin::make_visible(bool p_visible) { - if (p_visible) { grid_map_editor->show(); grid_map_editor->spatial_editor_hb->show(); grid_map_editor->set_process(true); } else { - grid_map_editor->spatial_editor_hb->hide(); grid_map_editor->hide(); grid_map_editor->edit(nullptr); @@ -1554,7 +1451,6 @@ void GridMapEditorPlugin::make_visible(bool p_visible) { } GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) { - editor = p_node; EDITOR_DEF("editors/grid_map/editor_side", 1); diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index fd880e8b7b..19eea18965 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -85,7 +85,6 @@ class GridMapEditor : public VBoxContainer { Label *spin_box_label; struct SetItem { - Vector3 pos; int new_value; int new_orientation; @@ -133,7 +132,6 @@ class GridMapEditor : public VBoxContainer { bool updating; struct Selection { - Vector3 click; Vector3 current; Vector3 begin; @@ -143,7 +141,6 @@ class GridMapEditor : public VBoxContainer { Selection last_selection; struct PasteIndicator { - Vector3 click; Vector3 current; Vector3 begin; @@ -191,7 +188,6 @@ class GridMapEditor : public VBoxContainer { Node3DEditorPlugin *spatial_editor; struct AreaDisplay { - RID mesh; RID instance; }; @@ -251,7 +247,6 @@ public: }; class GridMapEditorPlugin : public EditorPlugin { - GDCLASS(GridMapEditorPlugin, EditorPlugin); GridMapEditor *grid_map_editor; diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp index afd51945ab..906e506b62 100644 --- a/modules/gridmap/register_types.cpp +++ b/modules/gridmap/register_types.cpp @@ -36,7 +36,6 @@ #endif void register_gridmap_types() { - #ifndef _3D_DISABLED ClassDB::register_class<GridMap>(); #ifdef TOOLS_ENABLED diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp index c03ae4ab1f..19cd8ae584 100644 --- a/modules/hdr/image_loader_hdr.cpp +++ b/modules/hdr/image_loader_hdr.cpp @@ -34,7 +34,6 @@ #include "core/print_string.h" Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { - String header = f->get_token(); ERR_FAIL_COND_V_MSG(header != "#?RADIANCE" && header != "#?RGBE", ERR_FILE_UNRECOGNIZED, "Unsupported header information in HDR: " + header + "."); @@ -68,7 +67,6 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force imgdata.resize(height * width * sizeof(uint32_t)); { - uint8_t *w = imgdata.ptrw(); uint8_t *ptr = (uint8_t *)w; @@ -123,7 +121,6 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force //convert for (int i = 0; i < width * height; i++) { - float exp = pow(2.0f, ptr[3] - 128.0f); Color c( @@ -146,7 +143,6 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force } void ImageLoaderHDR::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("hdr"); } diff --git a/modules/hdr/image_loader_hdr.h b/modules/hdr/image_loader_hdr.h index a5f1f9c387..ef8e116616 100644 --- a/modules/hdr/image_loader_hdr.h +++ b/modules/hdr/image_loader_hdr.h @@ -34,7 +34,6 @@ #include "core/io/image_loader.h" class ImageLoaderHDR : public ImageFormatLoader { - public: virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale); virtual void get_recognized_extensions(List<String> *p_extensions) const; diff --git a/modules/hdr/register_types.cpp b/modules/hdr/register_types.cpp index 5f2d1578c5..e749928f60 100644 --- a/modules/hdr/register_types.cpp +++ b/modules/hdr/register_types.cpp @@ -35,12 +35,10 @@ static ImageLoaderHDR *image_loader_hdr = nullptr; void register_hdr_types() { - image_loader_hdr = memnew(ImageLoaderHDR); ImageLoader::add_image_format_loader(image_loader_hdr); } void unregister_hdr_types() { - memdelete(image_loader_hdr); } diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index 1a2afeb5b9..16ebd65147 100644 --- a/modules/jpg/image_loader_jpegd.cpp +++ b/modules/jpg/image_loader_jpegd.cpp @@ -37,7 +37,6 @@ #include <string.h> Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p_buffer_len) { - jpgd::jpeg_decoder_mem_stream mem_stream(p_buffer, p_buffer_len); jpgd::jpeg_decoder decoder(&mem_stream); @@ -102,7 +101,6 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p } Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { - Vector<uint8_t> src_image; int src_image_len = f->get_len(); ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); @@ -120,13 +118,11 @@ Error ImageLoaderJPG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force } void ImageLoaderJPG::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("jpg"); p_extensions->push_back("jpeg"); } static Ref<Image> _jpegd_mem_loader_func(const uint8_t *p_png, int p_size) { - Ref<Image> img; img.instance(); Error err = jpeg_load_image_from_buffer(img.ptr(), p_png, p_size); @@ -135,6 +131,5 @@ static Ref<Image> _jpegd_mem_loader_func(const uint8_t *p_png, int p_size) { } ImageLoaderJPG::ImageLoaderJPG() { - Image::_jpg_mem_loader_func = _jpegd_mem_loader_func; } diff --git a/modules/jpg/image_loader_jpegd.h b/modules/jpg/image_loader_jpegd.h index 9ef37ae303..9aebaad9e3 100644 --- a/modules/jpg/image_loader_jpegd.h +++ b/modules/jpg/image_loader_jpegd.h @@ -34,7 +34,6 @@ #include "core/io/image_loader.h" class ImageLoaderJPG : public ImageFormatLoader { - public: virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale); virtual void get_recognized_extensions(List<String> *p_extensions) const; diff --git a/modules/jpg/register_types.cpp b/modules/jpg/register_types.cpp index 61375fef10..b31746f769 100644 --- a/modules/jpg/register_types.cpp +++ b/modules/jpg/register_types.cpp @@ -35,12 +35,10 @@ static ImageLoaderJPG *image_loader_jpg = nullptr; void register_jpg_types() { - image_loader_jpg = memnew(ImageLoaderJPG); ImageLoader::add_image_format_loader(image_loader_jpg); } void unregister_jpg_types() { - memdelete(image_loader_jpg); } diff --git a/modules/jsonrpc/jsonrpc.cpp b/modules/jsonrpc/jsonrpc.cpp index 208ce24f3d..f744dd50d2 100644 --- a/modules/jsonrpc/jsonrpc.cpp +++ b/modules/jsonrpc/jsonrpc.cpp @@ -147,7 +147,6 @@ Variant JSONRPC::process_action(const Variant &p_action, bool p_process_arr_elem } String JSONRPC::process_string(const String &p_input) { - if (p_input.empty()) return String(); diff --git a/modules/lightmapper_rd/lightmapper_rd.cpp b/modules/lightmapper_rd/lightmapper_rd.cpp index 10f8512237..cf54754a16 100644 --- a/modules/lightmapper_rd/lightmapper_rd.cpp +++ b/modules/lightmapper_rd/lightmapper_rd.cpp @@ -81,7 +81,6 @@ void LightmapperRD::add_omni_light(bool p_static, const Vector3 &p_position, con lights.push_back(l); } void LightmapperRD::add_spot_light(bool p_static, const Vector3 &p_position, const Vector3 p_direction, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_spot_angle, float p_spot_attenuation, float p_size) { - Light l; l.type = LIGHT_TYPE_SPOT; l.position[0] = p_position.x; @@ -113,11 +112,9 @@ void LightmapperRD::add_probe(const Vector3 &p_position) { } void LightmapperRD::_plot_triangle_into_triangle_index_list(int p_size, const Vector3i &p_ofs, const AABB &p_bounds, const Vector3 p_points[3], uint32_t p_triangle_index, LocalVector<TriangleSort> &triangles, uint32_t p_grid_size) { - int half_size = p_size / 2; for (int i = 0; i < 8; i++) { - AABB aabb = p_bounds; aabb.size *= 0.5; Vector3i n = p_ofs; @@ -157,11 +154,9 @@ void LightmapperRD::_plot_triangle_into_triangle_index_list(int p_size, const Ve } Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_size, Vector<Ref<Image>> &albedo_images, Vector<Ref<Image>> &emission_images, AABB &bounds, Size2i &atlas_size, int &atlas_slices, BakeStepFunc p_step_function, void *p_bake_userdata) { - Vector<Size2i> sizes; for (int m_i = 0; m_i < mesh_instances.size(); m_i++) { - MeshInstance &mi = mesh_instances.write[m_i]; Size2i s = Size2i(mi.data.albedo_on_uv2->get_width(), mi.data.albedo_on_uv2->get_height()); sizes.push_back(s); @@ -189,7 +184,6 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ //determine best texture array atlas size by bruteforce fitting while (atlas_size.x <= p_max_texture_size && atlas_size.y <= p_max_texture_size) { - Vector<Vector2i> source_sizes = sizes; Vector<int> source_indices; source_indices.resize(source_sizes.size()); @@ -202,7 +196,6 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ int slices = 0; while (source_sizes.size() > 0) { - Vector<Vector3i> offsets = Geometry::partial_pack_rects(source_sizes, atlas_size); Vector<int> new_indices; Vector<Vector2i> new_sources; @@ -266,7 +259,6 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ //assign uv positions for (int m_i = 0; m_i < mesh_instances.size(); m_i++) { - MeshInstance &mi = mesh_instances.write[m_i]; mi.offset.x = best_atlas_offsets[m_i].x; mi.offset.y = best_atlas_offsets[m_i].y; @@ -279,7 +271,6 @@ Lightmapper::BakeError LightmapperRD::_blit_meshes_into_atlas(int p_max_texture_ } void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i atlas_size, int atlas_slices, AABB &bounds, int grid_size, Vector<Probe> &probe_positions, GenerateProbes p_generate_probes, Vector<int> &slice_triangle_count, Vector<int> &slice_seam_count, RID &vertex_buffer, RID &triangle_buffer, RID &box_buffer, RID &lights_buffer, RID &triangle_cell_indices_buffer, RID &probe_positions_buffer, RID &grid_texture, RID &grid_texture_sdf, RID &seams_buffer, BakeStepFunc p_step_function, void *p_bake_userdata) { - HashMap<Vertex, uint32_t, VertexHash> vertex_map; //fill triangles array and vertex array @@ -299,7 +290,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i bounds = AABB(); for (int m_i = 0; m_i < mesh_instances.size(); m_i++) { - if (p_step_function) { float p = float(m_i + 1) / mesh_instances.size() * 0.1; p_step_function(0.3 + p, vformat(TTR("Plotting mesh into acceleration structure %d/%d"), m_i + 1, mesh_instances.size()), p_bake_userdata, false); @@ -316,7 +306,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i } for (int i = 0; i < mi.data.points.size(); i += 3) { - Vector3 vtxs[3] = { mi.data.points[i + 0], mi.data.points[i + 1], mi.data.points[i + 2] }; Vector2 uvs[3] = { mi.data.uv2[i + 0] * uv_scale + uv_offset, mi.data.uv2[i + 1] * uv_scale + uv_offset, mi.data.uv2[i + 2] * uv_scale + uv_offset }; Vector3 normal[3] = { mi.data.normal[i + 0], mi.data.normal[i + 1], mi.data.normal[i + 2] }; @@ -325,7 +314,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i Triangle t; t.slice = mi.slice; for (int k = 0; k < 3; k++) { - bounds.expand_to(vtxs[k]); Vertex v; @@ -427,7 +415,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i //fill list of triangles in grid LocalVector<TriangleSort> triangle_sort; for (uint32_t i = 0; i < triangles.size(); i++) { - const Triangle &t = triangles[i]; Vector3 face[3] = { Vector3(vertex_array[t.indices[0]].position[0], vertex_array[t.indices[0]].position[1], vertex_array[t.indices[0]].position[2]), @@ -571,7 +558,6 @@ void LightmapperRD::_create_acceleration_structures(RenderingDevice *rd, Size2i } void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int atlas_slices, int grid_size, AABB bounds, float p_bias, Vector<int> slice_triangle_count, RID position_tex, RID unocclude_tex, RID normal_tex, RID raster_depth_buffer, RID rasterize_shader, RID raster_base_uniform) { - Vector<RID> framebuffers; for (int i = 0; i < atlas_slices; i++) { @@ -594,7 +580,6 @@ void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int RID raster_pipeline = rd->render_pipeline_create(rasterize_shader, rd->framebuffer_get_format(framebuffers[0]), RD::INVALID_FORMAT_ID, RD::RENDER_PRIMITIVE_TRIANGLES, RD::PipelineRasterizationState(), RD::PipelineMultisampleState(), ds, RD::PipelineColorBlendState::create_disabled(3), 0); RID raster_pipeline_wire; { - RD::PipelineRasterizationState rw; rw.wireframe = true; raster_pipeline_wire = rd->render_pipeline_create(rasterize_shader, rd->framebuffer_get_format(framebuffers[0]), RD::INVALID_FORMAT_ID, RD::RENDER_PRIMITIVE_TRIANGLES, rw, RD::PipelineMultisampleState(), ds, RD::PipelineColorBlendState::create_disabled(3), 0); @@ -607,7 +592,6 @@ void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int clear_colors.push_back(Color(0, 0, 0, 0)); for (int i = 0; i < atlas_slices; i++) { - RasterPushConstant raster_push_constant; raster_push_constant.atlas_size[0] = atlas_size.x; raster_push_constant.atlas_size[1] = atlas_size.y; @@ -644,7 +628,6 @@ void LightmapperRD::_raster_geometry(RenderingDevice *rd, Size2i atlas_size, int } LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function, void *p_bake_userdata) { - if (p_step_function) { p_step_function(0.0, TTR("Begin Bake"), p_bake_userdata, true); } @@ -840,7 +823,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d Vector<RD::Uniform> base_uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_STORAGE_BUFFER; u.binding = 1; @@ -975,7 +957,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d compute_shader.instance(); err = compute_shader->parse_versions_from_text(lm_compute_shader_glsl, p_bake_sh ? "\n#define USE_SH_LIGHTMAPS\n" : ""); if (err != OK) { - FREE_TEXTURES FREE_BUFFERS FREE_RASTER_RESOURCES @@ -1062,11 +1043,9 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d /* UNOCCLUDE */ { - Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_IMAGE; u.binding = 0; @@ -1104,11 +1083,9 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d /* PRIMARY (direct) LIGHT PASS */ { - Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_IMAGE; u.binding = 0; @@ -1186,11 +1163,9 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d } if (p_bounces > 0) { - Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_IMAGE; u.binding = 0; @@ -1286,7 +1261,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d for (int i = 0; i < x_regions; i++) { for (int j = 0; j < y_regions; j++) { - int x = i * max_region_size; int y = j * max_region_size; int w = MIN((i + 1) * max_region_size, atlas_size.width) - x; @@ -1298,7 +1272,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d group_size = Vector3i((w - 1) / 8 + 1, (h - 1) / 8 + 1, 1); for (int k = 0; k < ray_iterations; k++) { - RD::ComputeListID compute_list = rd->compute_list_begin(); rd->compute_list_bind_compute_pipeline(compute_list, compute_shader_secondary_pipeline); rd->compute_list_bind_uniform_set(compute_list, compute_base_uniform_set, 0); @@ -1332,7 +1305,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d RID light_probe_buffer; if (probe_positions.size()) { - light_probe_buffer = rd->storage_buffer_create(sizeof(float) * 4 * 9 * probe_positions.size()); if (p_step_function) { @@ -1341,9 +1313,7 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d Vector<RD::Uniform> uniforms; { - { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_STORAGE_BUFFER; u.binding = 0; @@ -1396,7 +1366,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d int ray_iterations = (push_constant.ray_count - 1) / max_rays + 1; for (int i = 0; i < ray_iterations; i++) { - RD::ComputeListID compute_list = rd->compute_list_begin(); rd->compute_list_bind_compute_pipeline(compute_list, compute_shader_light_probes_pipeline); rd->compute_list_bind_uniform_set(compute_list, compute_base_uniform_set, 0); @@ -1486,13 +1455,11 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d /* DILATE LIGHTMAP */ { - SWAP(light_accum_tex, light_accum_tex2); Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_IMAGE; u.binding = 0; @@ -1567,7 +1534,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d rd->free(blendseams_triangle_raster_shader); { - //pre copy for (int i = 0; i < atlas_slices * (p_bake_sh ? 4 : 1); i++) { rd->texture_copy(light_accum_tex, light_accum_tex2, Vector3(), Vector3(), Vector3(atlas_size.width, atlas_size.height, 1), 0, 0, i, i, true); @@ -1585,7 +1551,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d Vector<RD::Uniform> uniforms; { { - RD::Uniform u; u.type = RD::UNIFORM_TYPE_TEXTURE; u.binding = 0; @@ -1615,10 +1580,8 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d Vector<Color> clear_colors; clear_colors.push_back(Color(0, 0, 0, 1)); for (int i = 0; i < atlas_slices; i++) { - int subslices = (p_bake_sh ? 4 : 1); for (int k = 0; k < subslices; k++) { - RasterSeamsPushConstant seams_push_constant; seams_push_constant.slice = uint32_t(i * subslices + k); seams_push_constant.debug = debug; @@ -1668,7 +1631,6 @@ LightmapperRD::BakeError LightmapperRD::bake(BakeQuality p_quality, bool p_use_d rd->draw_list_bind_render_pipeline(draw_list, blendseams_line_raster_pipeline); for (int j = 1; j < uv_offset_count; j++) { - seams_push_constant.base_index = seam_offset; seams_push_constant.uv_offset[0] = uv_offsets[j].x / float(atlas_size.width); seams_push_constant.uv_offset[1] = uv_offsets[j].y / float(atlas_size.height); @@ -1750,7 +1712,6 @@ Variant LightmapperRD::get_bake_mesh_userdata(int p_index) const { return mesh_instances[p_index].data.userdata; } Rect2 LightmapperRD::get_bake_mesh_uv_scale(int p_index) const { - ERR_FAIL_COND_V(bake_textures.size() == 0, Rect2()); Rect2 uv_ofs; Vector2 atlas_size = Vector2(bake_textures[0]->get_width(), bake_textures[0]->get_height()); diff --git a/modules/lightmapper_rd/lightmapper_rd.h b/modules/lightmapper_rd/lightmapper_rd.h index c6f1b0e710..6cb3ecbe9e 100644 --- a/modules/lightmapper_rd/lightmapper_rd.h +++ b/modules/lightmapper_rd/lightmapper_rd.h @@ -198,7 +198,6 @@ class LightmapperRD : public Lightmapper { }; struct RasterSeamsPushConstant { - uint32_t base_index; uint32_t slice; float uv_offset[2]; diff --git a/modules/lightmapper_rd/lm_blendseams.glsl b/modules/lightmapper_rd/lm_blendseams.glsl index ef1ece8ea1..8a9ea91311 100644 --- a/modules/lightmapper_rd/lm_blendseams.glsl +++ b/modules/lightmapper_rd/lm_blendseams.glsl @@ -26,7 +26,6 @@ VERSION_DEFINES layout(location = 0) out vec3 uv_interp; void main() { - #ifdef MODE_TRIANGLES uint triangle_idx = params.base_index + gl_VertexIndex / 3; @@ -103,7 +102,6 @@ layout(location = 0) out vec4 dst_color; layout(set = 1, binding = 0) uniform texture2DArray src_color_tex; void main() { - if (params.debug) { #ifdef MODE_TRIANGLES dst_color = vec4(1, 0, 1, 1); diff --git a/modules/lightmapper_rd/lm_compute.glsl b/modules/lightmapper_rd/lm_compute.glsl index a178bd9b2e..5a1f1ceda3 100644 --- a/modules/lightmapper_rd/lm_compute.glsl +++ b/modules/lightmapper_rd/lm_compute.glsl @@ -97,7 +97,6 @@ params; //check it, but also return distance and barycentric coords (for uv lookup) bool ray_hits_triangle(vec3 from, vec3 dir, float max_dist, vec3 p0, vec3 p1, vec3 p2, out float r_distance, out vec3 r_barycentric) { - const vec3 e0 = p1 - p0; const vec3 e1 = p0 - p2; vec3 triangleNormal = cross(e1, e0); @@ -146,7 +145,6 @@ bool trace_ray(vec3 p_from, vec3 p_to uint iters = 0; while (all(greaterThanEqual(icell, ivec3(0))) && all(lessThan(icell, ivec3(params.grid_size))) && iters < 1000) { - uvec2 cell_data = texelFetch(usampler3D(grid, linear_sampler), icell, 0).xy; if (cell_data.x > 0) { //triangles here @@ -258,7 +256,6 @@ float quick_hash(vec2 pos) { } void main() { - #ifdef MODE_LIGHT_PROBES int probe_index = int(gl_GlobalInvocationID.x); if (probe_index >= params.atlas_size.x) { //too large, do nothing @@ -294,7 +291,6 @@ void main() { #endif for (uint i = 0; i < params.light_count; i++) { - vec3 light_pos; float attenuation; if (lights.data[i].type == LIGHT_TYPE_DIRECTIONAL) { @@ -313,7 +309,6 @@ void main() { attenuation = pow(max(1.0 - d, 0.0), lights.data[i].attenuation); if (lights.data[i].type == LIGHT_TYPE_SPOT) { - vec3 rel = normalize(position - light_pos); float angle = acos(dot(rel, lights.data[i].direction)); if (angle > lights.data[i].spot_angle) { @@ -512,7 +507,6 @@ void main() { vec3 norm; if (trace_ray(base_pos, ray_to, d, norm)) { - if (d < min_d) { vertex_pos = base_pos + rays[i] * d + norm * params.bias * 10.0; //this bias needs to be greater than the regular bias, because otherwise later, rays will go the other side when pointing back. min_d = d; @@ -561,7 +555,6 @@ void main() { light = textureLod(sampler2DArray(source_light, linear_sampler), uvw, 0.0).rgb; light += textureLod(sampler2DArray(source_direct_light, linear_sampler), uvw, 0.0).rgb; } else { - //did not hit a triangle, reach out for the sky vec3 sky_dir = normalize(mat3(params.env_transform) * ray_dir); diff --git a/modules/lightmapper_rd/lm_raster.glsl b/modules/lightmapper_rd/lm_raster.glsl index ae3038aead..41b3e89a3f 100644 --- a/modules/lightmapper_rd/lm_raster.glsl +++ b/modules/lightmapper_rd/lm_raster.glsl @@ -31,7 +31,6 @@ params; /* clang-format on */ void main() { - uint triangle_idx = params.base_triangle + gl_VertexIndex / 3; uint triangle_subidx = gl_VertexIndex % 3; @@ -95,7 +94,6 @@ layout(location = 1) out vec4 normal; layout(location = 2) out vec4 unocclude; void main() { - vec3 vertex_pos = vertex_interp; { diff --git a/modules/lightmapper_rd/register_types.cpp b/modules/lightmapper_rd/register_types.cpp index f3938f3190..0e6d7590cc 100644 --- a/modules/lightmapper_rd/register_types.cpp +++ b/modules/lightmapper_rd/register_types.cpp @@ -41,7 +41,6 @@ static Lightmapper *create_lightmapper_rd() { #endif void register_lightmapper_rd_types() { - GLOBAL_DEF("rendering/gpu_lightmapper/quality/low_quality_ray_count", 16); GLOBAL_DEF("rendering/gpu_lightmapper/quality/medium_quality_ray_count", 64); GLOBAL_DEF("rendering/gpu_lightmapper/quality/high_quality_ray_count", 256); diff --git a/modules/mbedtls/crypto_mbedtls.cpp b/modules/mbedtls/crypto_mbedtls.cpp index a47a4503a5..1f9d8c2aa3 100644 --- a/modules/mbedtls/crypto_mbedtls.cpp +++ b/modules/mbedtls/crypto_mbedtls.cpp @@ -155,7 +155,6 @@ Crypto *CryptoMbedTLS::create() { } void CryptoMbedTLS::initialize_crypto() { - #ifdef DEBUG_ENABLED mbedtls_debug_set_threshold(1); #endif diff --git a/modules/mbedtls/crypto_mbedtls.h b/modules/mbedtls/crypto_mbedtls.h index db3d00a5e3..48855d082a 100644 --- a/modules/mbedtls/crypto_mbedtls.h +++ b/modules/mbedtls/crypto_mbedtls.h @@ -41,7 +41,6 @@ class CryptoMbedTLS; class SSLContextMbedTLS; class CryptoKeyMbedTLS : public CryptoKey { - private: mbedtls_pk_context pkey; int locks; @@ -70,7 +69,6 @@ public: }; class X509CertificateMbedTLS : public X509Certificate { - private: mbedtls_x509_crt cert; int locks; @@ -100,7 +98,6 @@ public: }; class CryptoMbedTLS : public Crypto { - private: mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; diff --git a/modules/mbedtls/dtls_server_mbedtls.cpp b/modules/mbedtls/dtls_server_mbedtls.cpp index f31f067f4e..d9961b026f 100644 --- a/modules/mbedtls/dtls_server_mbedtls.cpp +++ b/modules/mbedtls/dtls_server_mbedtls.cpp @@ -54,12 +54,10 @@ Ref<PacketPeerDTLS> DTLSServerMbedTLS::take_connection(Ref<PacketPeerUDP> p_udp_ } DTLSServer *DTLSServerMbedTLS::_create_func() { - return memnew(DTLSServerMbedTLS); } void DTLSServerMbedTLS::initialize() { - _create = _create_func; available = true; } diff --git a/modules/mbedtls/dtls_server_mbedtls.h b/modules/mbedtls/dtls_server_mbedtls.h index d61ab3179e..d93553bf7f 100644 --- a/modules/mbedtls/dtls_server_mbedtls.h +++ b/modules/mbedtls/dtls_server_mbedtls.h @@ -35,7 +35,6 @@ #include "ssl_context_mbedtls.h" class DTLSServerMbedTLS : public DTLSServer { - private: static DTLSServer *_create_func(); Ref<CryptoKey> _key; diff --git a/modules/mbedtls/packet_peer_mbed_dtls.cpp b/modules/mbedtls/packet_peer_mbed_dtls.cpp index 37477e1246..210c9877df 100644 --- a/modules/mbedtls/packet_peer_mbed_dtls.cpp +++ b/modules/mbedtls/packet_peer_mbed_dtls.cpp @@ -35,7 +35,6 @@ #include "core/os/file_access.h" int PacketPeerMbedDTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) { - if (buf == nullptr || len <= 0) return 0; @@ -53,7 +52,6 @@ int PacketPeerMbedDTLS::bio_send(void *ctx, const unsigned char *buf, size_t len } int PacketPeerMbedDTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { - if (buf == nullptr || len <= 0) return 0; @@ -79,7 +77,6 @@ int PacketPeerMbedDTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { } void PacketPeerMbedDTLS::_cleanup() { - ssl_ctx->clear(); base = Ref<PacketPeer>(); status = STATUS_DISCONNECTED; @@ -116,7 +113,6 @@ Error PacketPeerMbedDTLS::_do_handshake() { } Error PacketPeerMbedDTLS::connect_to_peer(Ref<PacketPeerUDP> p_base, bool p_validate_certs, const String &p_for_hostname, Ref<X509Certificate> p_ca_certs) { - ERR_FAIL_COND_V(!p_base.is_valid() || !p_base->is_connected_to_host(), ERR_INVALID_PARAMETER); base = p_base; @@ -141,7 +137,6 @@ Error PacketPeerMbedDTLS::connect_to_peer(Ref<PacketPeerUDP> p_base, bool p_vali } Error PacketPeerMbedDTLS::accept_peer(Ref<PacketPeerUDP> p_base, Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert, Ref<X509Certificate> p_ca_chain, Ref<CookieContextMbedTLS> p_cookies) { - Error err = ssl_ctx->init_server(MBEDTLS_SSL_TRANSPORT_DATAGRAM, MBEDTLS_SSL_VERIFY_NONE, p_key, p_cert, p_cookies); ERR_FAIL_COND_V(err != OK, err); @@ -170,7 +165,6 @@ Error PacketPeerMbedDTLS::accept_peer(Ref<PacketPeerUDP> p_base, Ref<CryptoKey> } Error PacketPeerMbedDTLS::put_packet(const uint8_t *p_buffer, int p_bytes) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); if (p_bytes == 0) @@ -189,7 +183,6 @@ Error PacketPeerMbedDTLS::put_packet(const uint8_t *p_buffer, int p_bytes) { } Error PacketPeerMbedDTLS::get_packet(const uint8_t **r_buffer, int &r_bytes) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); r_bytes = 0; @@ -215,7 +208,6 @@ Error PacketPeerMbedDTLS::get_packet(const uint8_t **r_buffer, int &r_bytes) { } void PacketPeerMbedDTLS::poll() { - if (status == STATUS_HANDSHAKING) { _do_handshake(); return; @@ -240,19 +232,16 @@ void PacketPeerMbedDTLS::poll() { } int PacketPeerMbedDTLS::get_available_packet_count() const { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, 0); return mbedtls_ssl_get_bytes_avail(&(ssl_ctx->ssl)) > 0 ? 1 : 0; } int PacketPeerMbedDTLS::get_max_packet_size() const { - return 488; // 512 (UDP in Godot) - 24 (DTLS header) } PacketPeerMbedDTLS::PacketPeerMbedDTLS() { - ssl_ctx.instance(); status = STATUS_DISCONNECTED; } @@ -262,7 +251,6 @@ PacketPeerMbedDTLS::~PacketPeerMbedDTLS() { } void PacketPeerMbedDTLS::disconnect_from_peer() { - if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) return; @@ -278,17 +266,14 @@ void PacketPeerMbedDTLS::disconnect_from_peer() { } PacketPeerMbedDTLS::Status PacketPeerMbedDTLS::get_status() const { - return status; } PacketPeerDTLS *PacketPeerMbedDTLS::_create_func() { - return memnew(PacketPeerMbedDTLS); } void PacketPeerMbedDTLS::initialize_dtls() { - _create = _create_func; available = true; } diff --git a/modules/mbedtls/register_types.cpp b/modules/mbedtls/register_types.cpp index d39af7fe87..84a27c29bd 100755..100644 --- a/modules/mbedtls/register_types.cpp +++ b/modules/mbedtls/register_types.cpp @@ -36,7 +36,6 @@ #include "stream_peer_mbedtls.h" void register_mbedtls_types() { - CryptoMbedTLS::initialize_crypto(); StreamPeerMbedTLS::initialize_ssl(); PacketPeerMbedDTLS::initialize_dtls(); @@ -44,7 +43,6 @@ void register_mbedtls_types() { } void unregister_mbedtls_types() { - DTLSServerMbedTLS::finalize(); PacketPeerMbedDTLS::finalize_dtls(); StreamPeerMbedTLS::finalize_ssl(); diff --git a/modules/mbedtls/ssl_context_mbedtls.cpp b/modules/mbedtls/ssl_context_mbedtls.cpp index 1ffb9bda05..b0ca4a9e44 100644 --- a/modules/mbedtls/ssl_context_mbedtls.cpp +++ b/modules/mbedtls/ssl_context_mbedtls.cpp @@ -33,7 +33,6 @@ static void my_debug(void *ctx, int level, const char *file, int line, const char *str) { - printf("%s:%04d: %s", file, line, str); fflush(stdout); } diff --git a/modules/mbedtls/ssl_context_mbedtls.h b/modules/mbedtls/ssl_context_mbedtls.h index d3e1f87a8e..baaeb6eb85 100644 --- a/modules/mbedtls/ssl_context_mbedtls.h +++ b/modules/mbedtls/ssl_context_mbedtls.h @@ -47,7 +47,6 @@ class SSLContextMbedTLS; class CookieContextMbedTLS : public Reference { - friend class SSLContextMbedTLS; protected: @@ -65,7 +64,6 @@ public: }; class SSLContextMbedTLS : public Reference { - protected: bool inited; diff --git a/modules/mbedtls/stream_peer_mbedtls.cpp b/modules/mbedtls/stream_peer_mbedtls.cpp index af36b29dac..0be473b97e 100644 --- a/modules/mbedtls/stream_peer_mbedtls.cpp +++ b/modules/mbedtls/stream_peer_mbedtls.cpp @@ -34,7 +34,6 @@ #include "core/os/file_access.h" int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) { - if (buf == nullptr || len <= 0) return 0; @@ -54,7 +53,6 @@ int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) } int StreamPeerMbedTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { - if (buf == nullptr || len <= 0) return 0; @@ -74,7 +72,6 @@ int StreamPeerMbedTLS::bio_recv(void *ctx, unsigned char *buf, size_t len) { } void StreamPeerMbedTLS::_cleanup() { - ssl_ctx->clear(); base = Ref<StreamPeer>(); status = STATUS_DISCONNECTED; @@ -104,7 +101,6 @@ Error StreamPeerMbedTLS::_do_handshake() { } Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_validate_certs, const String &p_for_hostname, Ref<X509Certificate> p_ca_certs) { - ERR_FAIL_COND_V(p_base.is_null(), ERR_INVALID_PARAMETER); base = p_base; @@ -127,7 +123,6 @@ Error StreamPeerMbedTLS::connect_to_stream(Ref<StreamPeer> p_base, bool p_valida } Error StreamPeerMbedTLS::accept_stream(Ref<StreamPeer> p_base, Ref<CryptoKey> p_key, Ref<X509Certificate> p_cert, Ref<X509Certificate> p_ca_chain) { - ERR_FAIL_COND_V(p_base.is_null(), ERR_INVALID_PARAMETER); Error err = ssl_ctx->init_server(MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_VERIFY_NONE, p_key, p_cert); @@ -147,7 +142,6 @@ Error StreamPeerMbedTLS::accept_stream(Ref<StreamPeer> p_base, Ref<CryptoKey> p_ return OK; } Error StreamPeerMbedTLS::put_data(const uint8_t *p_data, int p_bytes) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); Error err; @@ -168,7 +162,6 @@ Error StreamPeerMbedTLS::put_data(const uint8_t *p_data, int p_bytes) { } Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); r_sent = 0; @@ -195,14 +188,12 @@ Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, in } Error StreamPeerMbedTLS::get_data(uint8_t *p_buffer, int p_bytes) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); Error err; int got = 0; while (p_bytes > 0) { - err = get_partial_data(p_buffer, p_bytes, got); if (err != OK) { @@ -217,7 +208,6 @@ Error StreamPeerMbedTLS::get_data(uint8_t *p_buffer, int p_bytes) { } Error StreamPeerMbedTLS::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, ERR_UNCONFIGURED); r_received = 0; @@ -240,7 +230,6 @@ Error StreamPeerMbedTLS::get_partial_data(uint8_t *p_buffer, int p_bytes, int &r } void StreamPeerMbedTLS::poll() { - ERR_FAIL_COND(status != STATUS_CONNECTED && status != STATUS_HANDSHAKING); ERR_FAIL_COND(!base.is_valid()); @@ -274,13 +263,11 @@ void StreamPeerMbedTLS::poll() { } int StreamPeerMbedTLS::get_available_bytes() const { - ERR_FAIL_COND_V(status != STATUS_CONNECTED, 0); return mbedtls_ssl_get_bytes_avail(&(ssl_ctx->ssl)); } StreamPeerMbedTLS::StreamPeerMbedTLS() { - ssl_ctx.instance(); status = STATUS_DISCONNECTED; } @@ -290,7 +277,6 @@ StreamPeerMbedTLS::~StreamPeerMbedTLS() { } void StreamPeerMbedTLS::disconnect_from_stream() { - if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) return; @@ -304,23 +290,19 @@ void StreamPeerMbedTLS::disconnect_from_stream() { } StreamPeerMbedTLS::Status StreamPeerMbedTLS::get_status() const { - return status; } StreamPeerSSL *StreamPeerMbedTLS::_create_func() { - return memnew(StreamPeerMbedTLS); } void StreamPeerMbedTLS::initialize_ssl() { - _create = _create_func; available = true; } void StreamPeerMbedTLS::finalize_ssl() { - available = false; _create = nullptr; } diff --git a/modules/mono/class_db_api_json.cpp b/modules/mono/class_db_api_json.cpp index 384685d04b..39e3a95afa 100644 --- a/modules/mono/class_db_api_json.cpp +++ b/modules/mono/class_db_api_json.cpp @@ -45,14 +45,12 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { const StringName *k = nullptr; while ((k = ClassDB::classes.next(k))) { - names.push_back(*k); } //must be alphabetically sorted for hash to compute names.sort_custom<StringName::AlphCompare>(); for (List<StringName>::Element *E = names.front(); E; E = E->next()) { - ClassDB::ClassInfo *t = ClassDB::classes.getptr(E->get()); ERR_FAIL_COND(!t); if (t->api != p_api || !t->exposed) @@ -70,7 +68,6 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { k = nullptr; while ((k = t->method_map.next(k))) { - String name = k->operator String(); ERR_CONTINUE(name.empty()); @@ -135,7 +132,6 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { k = nullptr; while ((k = t->constant_map.next(k))) { - snames.push_back(*k); } @@ -163,7 +159,6 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { k = nullptr; while ((k = t->signal_map.next(k))) { - snames.push_back(*k); } @@ -199,7 +194,6 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { k = nullptr; while ((k = t->property_setget.next(k))) { - snames.push_back(*k); } diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 43c86d3e28..a5aae5175b 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -67,7 +67,6 @@ #ifdef TOOLS_ENABLED static bool _create_project_solution_if_needed() { - String sln_path = GodotSharpDirs::get_project_sln_path(); String csproj_path = GodotSharpDirs::get_project_csproj_path(); @@ -85,28 +84,23 @@ static bool _create_project_solution_if_needed() { CSharpLanguage *CSharpLanguage::singleton = nullptr; String CSharpLanguage::get_name() const { - return "C#"; } String CSharpLanguage::get_type() const { - return "CSharpScript"; } String CSharpLanguage::get_extension() const { - return "cs"; } Error CSharpLanguage::execute_file(const String &p_path) { - // ?? return OK; } void CSharpLanguage::init() { - #ifdef DEBUG_METHODS_ENABLED if (OS::get_singleton()->get_cmdline_args().find("--class-db-json")) { class_db_api_to_json("user://class_db_api.json", ClassDB::API_CORE); @@ -140,7 +134,6 @@ void CSharpLanguage::init() { } void CSharpLanguage::finish() { - if (finalized) return; @@ -184,7 +177,6 @@ void CSharpLanguage::finish() { } void CSharpLanguage::get_reserved_words(List<String> *p_words) const { - static const char *_reserved_words[] = { // Reserved keywords "abstract", @@ -307,13 +299,11 @@ void CSharpLanguage::get_reserved_words(List<String> *p_words) const { } void CSharpLanguage::get_comment_delimiters(List<String> *p_delimiters) const { - p_delimiters->push_back("//"); // single-line comment p_delimiters->push_back("/* */"); // delimited comment } void CSharpLanguage::get_string_delimiters(List<String> *p_delimiters) const { - p_delimiters->push_back("' '"); // character literal p_delimiters->push_back("\" \""); // regular string literal // Verbatim string literals (`@" "`) don't render correctly, so don't highlight them. @@ -321,7 +311,6 @@ void CSharpLanguage::get_string_delimiters(List<String> *p_delimiters) const { } static String get_base_class_name(const String &p_base_class_name, const String p_class_name) { - String base_class = p_base_class_name; if (p_class_name == base_class) { base_class = "Godot." + base_class; @@ -330,7 +319,6 @@ static String get_base_class_name(const String &p_base_class_name, const String } Ref<Script> CSharpLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { - String script_template = "using " BINDINGS_NAMESPACE ";\n" "using System;\n" "\n" @@ -366,12 +354,10 @@ Ref<Script> CSharpLanguage::get_template(const String &p_class_name, const Strin } bool CSharpLanguage::is_using_templates() { - return true; } void CSharpLanguage::make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) { - String src = p_script->get_source_code(); String base_class_name = get_base_class_name(p_base_class_name, p_class_name); src = src.replace("%BASE%", base_class_name) @@ -381,7 +367,6 @@ void CSharpLanguage::make_template(const String &p_class_name, const String &p_b } String CSharpLanguage::validate_path(const String &p_path) const { - String class_name = p_path.get_file().get_basename(); List<String> keywords; get_reserved_words(&keywords); @@ -392,23 +377,19 @@ String CSharpLanguage::validate_path(const String &p_path) const { } Script *CSharpLanguage::create_script() const { - return memnew(CSharpScript); } bool CSharpLanguage::has_named_classes() const { - return false; } bool CSharpLanguage::supports_builtin_mode() const { - return false; } #ifdef TOOLS_ENABLED static String variant_type_to_managed_name(const String &p_var_type_name) { - if (p_var_type_name.empty()) return "object"; @@ -531,12 +512,10 @@ String CSharpLanguage::_get_indentation() const { } String CSharpLanguage::debug_get_error() const { - return _debug_error; } int CSharpLanguage::debug_get_stack_level_count() const { - if (_debug_parse_err_line >= 0) return 1; @@ -545,7 +524,6 @@ int CSharpLanguage::debug_get_stack_level_count() const { } int CSharpLanguage::debug_get_stack_level_line(int p_level) const { - if (_debug_parse_err_line >= 0) return _debug_parse_err_line; @@ -554,7 +532,6 @@ int CSharpLanguage::debug_get_stack_level_line(int p_level) const { } String CSharpLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_line >= 0) return String(); @@ -563,7 +540,6 @@ String CSharpLanguage::debug_get_stack_level_function(int p_level) const { } String CSharpLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_line >= 0) return _debug_parse_err_file; @@ -572,7 +548,6 @@ String CSharpLanguage::debug_get_stack_level_source(int p_level) const { } Vector<ScriptLanguage::StackInfo> CSharpLanguage::debug_get_current_stack_info() { - #ifdef DEBUG_ENABLED // Printing an error here will result in endless recursion, so we must be careful static thread_local bool _recursion_flag_ = false; @@ -604,7 +579,6 @@ Vector<ScriptLanguage::StackInfo> CSharpLanguage::debug_get_current_stack_info() #ifdef DEBUG_ENABLED Vector<ScriptLanguage::StackInfo> CSharpLanguage::stack_trace_get_info(MonoObject *p_stack_trace) { - // Printing an error here will result in endless recursion, so we must be careful static thread_local bool _recursion_flag_ = false; if (_recursion_flag_) @@ -678,7 +652,6 @@ void CSharpLanguage::pre_unsafe_unreference(Object *p_obj) { } void CSharpLanguage::frame() { - if (gdmono && gdmono->is_runtime_initialized() && gdmono->get_core_api_assembly() != nullptr) { const Ref<MonoGCHandleRef> &task_scheduler_handle = GDMonoCache::cached_data.task_scheduler_handle; @@ -698,7 +671,6 @@ void CSharpLanguage::frame() { } struct CSharpScriptDepSort { - // must support sorting so inheritance works properly (parent must be reloaded first) bool operator()(const Ref<CSharpScript> &A, const Ref<CSharpScript> &B) const { if (A == B) @@ -718,7 +690,6 @@ struct CSharpScriptDepSort { }; void CSharpLanguage::reload_all_scripts() { - #ifdef GD_MONO_HOT_RELOAD if (is_assembly_reloading_needed()) { GD_MONO_SCOPE_THREAD_ATTACH; @@ -728,7 +699,6 @@ void CSharpLanguage::reload_all_scripts() { } void CSharpLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) { - (void)p_script; // UNUSED CRASH_COND(!Engine::get_singleton()->is_editor_hint()); @@ -747,7 +717,6 @@ void CSharpLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft #ifdef GD_MONO_HOT_RELOAD bool CSharpLanguage::is_assembly_reloading_needed() { - if (!gdmono->is_runtime_initialized()) return false; @@ -782,7 +751,6 @@ bool CSharpLanguage::is_assembly_reloading_needed() { } void CSharpLanguage::reload_assemblies(bool p_soft_reload) { - if (!gdmono->is_runtime_initialized()) return; @@ -1173,7 +1141,6 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { #endif void CSharpLanguage::_load_scripts_metadata() { - scripts_metadata.clear(); String scripts_metadata_filename = "scripts_metadata."; @@ -1218,24 +1185,20 @@ void CSharpLanguage::_load_scripts_metadata() { } void CSharpLanguage::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("cs"); } #ifdef TOOLS_ENABLED Error CSharpLanguage::open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) { - return (Error)(int)get_godotsharp_editor()->call("OpenInExternalEditor", p_script, p_line, p_col); } bool CSharpLanguage::overrides_external_editor() { - return get_godotsharp_editor()->call("OverridesExternalEditor"); } #endif void CSharpLanguage::thread_enter() { - #if 0 if (gdmono->is_runtime_initialized()) { GDMonoUtils::attach_current_thread(); @@ -1244,7 +1207,6 @@ void CSharpLanguage::thread_enter() { } void CSharpLanguage::thread_exit() { - #if 0 if (gdmono->is_runtime_initialized()) { GDMonoUtils::detach_current_thread(); @@ -1253,7 +1215,6 @@ void CSharpLanguage::thread_exit() { } bool CSharpLanguage::debug_break_parse(const String &p_file, int p_line, const String &p_error) { - // Not a parser error in our case, but it's still used for other type of errors if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = p_line; @@ -1267,7 +1228,6 @@ bool CSharpLanguage::debug_break_parse(const String &p_file, int p_line, const S } bool CSharpLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { _debug_parse_err_line = -1; _debug_parse_err_file = ""; @@ -1301,7 +1261,6 @@ void CSharpLanguage::_on_scripts_domain_unloaded() { #ifdef TOOLS_ENABLED void CSharpLanguage::_editor_init_callback() { - register_editor_internal_calls(); // Initialize GodotSharpEditor @@ -1328,13 +1287,11 @@ void CSharpLanguage::_editor_init_callback() { #endif void CSharpLanguage::set_language_index(int p_idx) { - ERR_FAIL_COND(lang_idx != -1); lang_idx = p_idx; } void CSharpLanguage::release_script_gchandle(MonoGCHandleData &p_gchandle) { - if (!p_gchandle.is_released()) { // Do not lock unnecessarily MutexLock lock(get_singleton()->script_gchandle_release_mutex); p_gchandle.release(); @@ -1342,7 +1299,6 @@ void CSharpLanguage::release_script_gchandle(MonoGCHandleData &p_gchandle) { } void CSharpLanguage::release_script_gchandle(MonoObject *p_expected_obj, MonoGCHandleData &p_gchandle) { - uint32_t pinned_gchandle = GDMonoUtils::new_strong_gchandle_pinned(p_expected_obj); // We might lock after this, so pin it if (!p_gchandle.is_released()) { // Do not lock unnecessarily @@ -1363,19 +1319,16 @@ void CSharpLanguage::release_script_gchandle(MonoObject *p_expected_obj, MonoGCH } CSharpLanguage::CSharpLanguage() { - ERR_FAIL_COND_MSG(singleton, "C# singleton already exist."); singleton = this; } CSharpLanguage::~CSharpLanguage() { - finish(); singleton = nullptr; } bool CSharpLanguage::setup_csharp_script_binding(CSharpScriptBinding &r_script_binding, Object *p_object) { - #ifdef DEBUG_ENABLED // I don't trust you if (p_object->get_script_instance()) { @@ -1424,7 +1377,6 @@ bool CSharpLanguage::setup_csharp_script_binding(CSharpScriptBinding &r_script_b } void *CSharpLanguage::alloc_instance_binding_data(Object *p_object) { - MutexLock lock(language_bind_mutex); Map<Object *, CSharpScriptBinding>::Element *match = script_bindings.find(p_object); @@ -1440,12 +1392,10 @@ void *CSharpLanguage::alloc_instance_binding_data(Object *p_object) { } Map<Object *, CSharpScriptBinding>::Element *CSharpLanguage::insert_script_binding(Object *p_object, const CSharpScriptBinding &p_script_binding) { - return script_bindings.insert(p_object, p_script_binding); } void CSharpLanguage::free_instance_binding_data(void *p_data) { - if (GDMono::get_singleton() == nullptr) { #ifdef DEBUG_ENABLED CRASH_COND(!script_bindings.empty()); @@ -1481,7 +1431,6 @@ void CSharpLanguage::free_instance_binding_data(void *p_data) { } void CSharpLanguage::refcount_incremented_instance_binding(Object *p_object) { - Reference *ref_owner = Object::cast_to<Reference>(p_object); #ifdef DEBUG_ENABLED @@ -1517,7 +1466,6 @@ void CSharpLanguage::refcount_incremented_instance_binding(Object *p_object) { } bool CSharpLanguage::refcount_decremented_instance_binding(Object *p_object) { - Reference *ref_owner = Object::cast_to<Reference>(p_object); #ifdef DEBUG_ENABLED @@ -1558,7 +1506,6 @@ bool CSharpLanguage::refcount_decremented_instance_binding(Object *p_object) { } CSharpInstance *CSharpInstance::create_for_managed_type(Object *p_owner, CSharpScript *p_script, const MonoGCHandleData &p_gchandle) { - CSharpInstance *instance = memnew(CSharpInstance(Ref<CSharpScript>(p_script))); Reference *ref = Object::cast_to<Reference>(p_owner); @@ -1576,7 +1523,6 @@ CSharpInstance *CSharpInstance::create_for_managed_type(Object *p_owner, CSharpS } MonoObject *CSharpInstance::get_mono_object() const { - ERR_FAIL_COND_V(gchandle.is_released(), nullptr); return gchandle.get_target(); } @@ -1586,7 +1532,6 @@ Object *CSharpInstance::get_owner() { } bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) { - ERR_FAIL_COND_V(!script.is_valid(), false); GD_MONO_SCOPE_THREAD_ATTACH; @@ -1640,7 +1585,6 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) { } bool CSharpInstance::get(const StringName &p_name, Variant &r_ret) const { - ERR_FAIL_COND_V(!script.is_valid(), false); GD_MONO_SCOPE_THREAD_ATTACH; @@ -1704,7 +1648,6 @@ bool CSharpInstance::get(const StringName &p_name, Variant &r_ret) const { } void CSharpInstance::get_properties_state_for_reloading(List<Pair<StringName, Variant>> &r_state) { - List<PropertyInfo> pinfo; get_property_list(&pinfo); @@ -1729,7 +1672,6 @@ void CSharpInstance::get_properties_state_for_reloading(List<Pair<StringName, Va } void CSharpInstance::get_event_signals_state_for_reloading(List<Pair<StringName, Array>> &r_state) { - MonoObject *owner_managed = get_mono_object(); ERR_FAIL_NULL(owner_managed); @@ -1760,7 +1702,6 @@ void CSharpInstance::get_event_signals_state_for_reloading(List<Pair<StringName, } void CSharpInstance::get_property_list(List<PropertyInfo> *p_properties) const { - for (Map<StringName, PropertyInfo>::Element *E = script->member_info.front(); E; E = E->next()) { p_properties->push_back(E->value()); } @@ -1797,7 +1738,6 @@ void CSharpInstance::get_property_list(List<PropertyInfo> *p_properties) const { } Variant::Type CSharpInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { - if (script->member_info.has(p_name)) { if (r_is_valid) *r_is_valid = true; @@ -1811,7 +1751,6 @@ Variant::Type CSharpInstance::get_property_type(const StringName &p_name, bool * } bool CSharpInstance::has_method(const StringName &p_method) const { - if (!script.is_valid()) return false; @@ -1831,7 +1770,6 @@ bool CSharpInstance::has_method(const StringName &p_method) const { } Variant CSharpInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - ERR_FAIL_COND_V(!script.is_valid(), Variant()); GD_MONO_SCOPE_THREAD_ATTACH; @@ -1869,7 +1807,6 @@ Variant CSharpInstance::call(const StringName &p_method, const Variant **p_args, } void CSharpInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { - GD_MONO_SCOPE_THREAD_ATTACH; if (script.is_valid()) { @@ -1882,7 +1819,6 @@ void CSharpInstance::call_multilevel(const StringName &p_method, const Variant * } void CSharpInstance::_call_multilevel(MonoObject *p_mono_object, const StringName &p_method, const Variant **p_args, int p_argcount) { - GD_MONO_ASSERT_THREAD_ATTACHED; GDMonoClass *top = script->script_class; @@ -1900,14 +1836,12 @@ void CSharpInstance::_call_multilevel(MonoObject *p_mono_object, const StringNam } void CSharpInstance::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { - // Sorry, the method is the one that controls the call order call_multilevel(p_method, p_args, p_argcount); } bool CSharpInstance::_reference_owner_unsafe() { - #ifdef DEBUG_ENABLED CRASH_COND(!base_ref); CRASH_COND(owner == nullptr); @@ -1929,7 +1863,6 @@ bool CSharpInstance::_reference_owner_unsafe() { } bool CSharpInstance::_unreference_owner_unsafe() { - #ifdef DEBUG_ENABLED CRASH_COND(!base_ref); CRASH_COND(owner == nullptr); @@ -1991,7 +1924,6 @@ MonoObject *CSharpInstance::_internal_new_managed() { } void CSharpInstance::mono_object_disposed(MonoObject *p_obj) { - disconnect_event_signals(); #ifdef DEBUG_ENABLED @@ -2002,7 +1934,6 @@ void CSharpInstance::mono_object_disposed(MonoObject *p_obj) { } void CSharpInstance::mono_object_disposed_baseref(MonoObject *p_obj, bool p_is_finalizer, bool &r_delete_owner, bool &r_remove_script_instance) { - #ifdef DEBUG_ENABLED CRASH_COND(!base_ref); CRASH_COND(gchandle.is_released()); @@ -2063,7 +1994,6 @@ void CSharpInstance::disconnect_event_signals() { } void CSharpInstance::refcount_incremented() { - #ifdef DEBUG_ENABLED CRASH_COND(!base_ref); CRASH_COND(owner == nullptr); @@ -2086,7 +2016,6 @@ void CSharpInstance::refcount_incremented() { } bool CSharpInstance::refcount_decremented() { - #ifdef DEBUG_ENABLED CRASH_COND(!base_ref); CRASH_COND(owner == nullptr); @@ -2156,7 +2085,6 @@ MultiplayerAPI::RPCMode CSharpInstance::get_rset_mode(const StringName &p_variab } void CSharpInstance::notification(int p_notification) { - GD_MONO_SCOPE_THREAD_ATTACH; if (p_notification == Object::NOTIFICATION_PREDELETE) { @@ -2195,7 +2123,6 @@ void CSharpInstance::notification(int p_notification) { } void CSharpInstance::_call_notification(int p_notification) { - GD_MONO_ASSERT_THREAD_ATTACHED; MonoObject *mono_object = get_mono_object(); @@ -2252,12 +2179,10 @@ String CSharpInstance::to_string(bool *r_valid) { } Ref<Script> CSharpInstance::get_script() const { - return script; } ScriptLanguage *CSharpInstance::get_language() { - return CSharpLanguage::get_singleton(); } @@ -2266,7 +2191,6 @@ CSharpInstance::CSharpInstance(const Ref<CSharpScript> &p_script) : } CSharpInstance::~CSharpInstance() { - GD_MONO_SCOPE_THREAD_ATTACH; destructing_script_instance = true; @@ -2348,14 +2272,12 @@ CSharpInstance::~CSharpInstance() { #ifdef TOOLS_ENABLED void CSharpScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { - placeholders.erase(p_placeholder); } #endif #ifdef TOOLS_ENABLED void CSharpScript::_update_exports_values(Map<StringName, Variant> &values, List<PropertyInfo> &propnames) { - if (base_cache.is_valid()) { base_cache->_update_exports_values(values, propnames); } @@ -2370,7 +2292,6 @@ void CSharpScript::_update_exports_values(Map<StringName, Variant> &values, List } void CSharpScript::_update_member_info_no_exports() { - if (exports_invalidated) { GD_MONO_ASSERT_THREAD_ATTACHED; @@ -2419,7 +2340,6 @@ void CSharpScript::_update_member_info_no_exports() { #endif bool CSharpScript::_update_exports() { - #ifdef TOOLS_ENABLED bool is_editor = Engine::get_singleton()->is_editor_hint(); if (is_editor) @@ -2592,7 +2512,6 @@ bool CSharpScript::_update_exports() { } void CSharpScript::load_script_signals(GDMonoClass *p_class, GDMonoClass *p_native_class) { - // no need to load the script's signals more than once if (!signals_invalidated) { return; @@ -2699,7 +2618,6 @@ bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoMethod *p_delegate_in * If there was an error, r_prop_info and r_exported are not assigned any value. */ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect_export, PropertyInfo &r_prop_info, bool &r_exported) { - GD_MONO_ASSERT_THREAD_ATTACHED; // Goddammit, C++. All I wanted was some nested functions. @@ -2798,7 +2716,6 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect #ifdef TOOLS_ENABLED int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, ManagedType p_type, Variant::Type p_variant_type, bool p_allow_generics, PropertyHint &r_hint, String &r_hint_string) { - if (p_variant_type == Variant::NIL) { // System.Object (Variant) return 1; @@ -2898,7 +2815,6 @@ int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, Manage #endif void CSharpScript::_clear() { - tool = false; valid = false; @@ -2908,7 +2824,6 @@ void CSharpScript::_clear() { } Variant CSharpScript::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (unlikely(GDMono::get_singleton() == nullptr)) { // Probably not the best error but eh. r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; @@ -2940,7 +2855,6 @@ Variant CSharpScript::call(const StringName &p_method, const Variant **p_args, i } void CSharpScript::_resource_path_changed() { - String path = get_path(); if (!path.empty()) { @@ -2949,9 +2863,7 @@ void CSharpScript::_resource_path_changed() { } bool CSharpScript::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == CSharpLanguage::singleton->string_names._script_source) { - r_ret = get_source_code(); return true; } @@ -2960,9 +2872,7 @@ bool CSharpScript::_get(const StringName &p_name, Variant &r_ret) const { } bool CSharpScript::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == CSharpLanguage::singleton->string_names._script_source) { - set_source_code(p_value); reload(); return true; @@ -2972,17 +2882,14 @@ bool CSharpScript::_set(const StringName &p_name, const Variant &p_value) { } void CSharpScript::_get_property_list(List<PropertyInfo> *p_properties) const { - p_properties->push_back(PropertyInfo(Variant::STRING, CSharpLanguage::singleton->string_names._script_source, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); } void CSharpScript::_bind_methods() { - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "new", &CSharpScript::_new, MethodInfo("new")); } Ref<CSharpScript> CSharpScript::create_for_managed_type(GDMonoClass *p_class, GDMonoClass *p_native) { - // This method should not fail, only assertions allowed CRASH_COND(p_class == nullptr); @@ -2996,7 +2903,6 @@ Ref<CSharpScript> CSharpScript::create_for_managed_type(GDMonoClass *p_class, GD } void CSharpScript::initialize_for_managed_type(Ref<CSharpScript> p_script, GDMonoClass *p_class, GDMonoClass *p_native) { - // This method should not fail, only assertions allowed CRASH_COND(p_class == nullptr); @@ -3060,7 +2966,6 @@ void CSharpScript::initialize_for_managed_type(Ref<CSharpScript> p_script, GDMon } bool CSharpScript::can_instance() const { - #ifdef TOOLS_ENABLED bool extra_cond = tool || ScriptServer::is_scripting_enabled(); #else @@ -3084,7 +2989,6 @@ bool CSharpScript::can_instance() const { } StringName CSharpScript::get_instance_base_type() const { - if (native) return native->get_name(); else @@ -3092,7 +2996,6 @@ StringName CSharpScript::get_instance_base_type() const { } CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Callable::CallError &r_error) { - GD_MONO_ASSERT_THREAD_ATTACHED; /* STEP 1, CREATE */ @@ -3182,7 +3085,6 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg } Variant CSharpScript::_new(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - if (!valid) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; return Variant(); @@ -3218,7 +3120,6 @@ Variant CSharpScript::_new(const Variant **p_args, int p_argcount, Callable::Cal } ScriptInstance *CSharpScript::instance_create(Object *p_this) { - #ifdef DEBUG_ENABLED CRASH_COND(!valid); #endif @@ -3243,7 +3144,6 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { } PlaceHolderScriptInstance *CSharpScript::placeholder_instance_create(Object *p_this) { - #ifdef TOOLS_ENABLED PlaceHolderScriptInstance *si = memnew(PlaceHolderScriptInstance(CSharpLanguage::get_singleton(), Ref<Script>(this), p_this)); placeholders.insert(si); @@ -3255,23 +3155,19 @@ PlaceHolderScriptInstance *CSharpScript::placeholder_instance_create(Object *p_t } bool CSharpScript::instance_has(const Object *p_this) const { - MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex); return instances.has((Object *)p_this); } bool CSharpScript::has_source_code() const { - return !source.empty(); } String CSharpScript::get_source_code() const { - return source; } void CSharpScript::set_source_code(const String &p_code) { - if (source == p_code) return; source = p_code; @@ -3281,7 +3177,6 @@ void CSharpScript::set_source_code(const String &p_code) { } void CSharpScript::get_script_method_list(List<MethodInfo> *p_list) const { - if (!script_class) return; @@ -3295,7 +3190,6 @@ void CSharpScript::get_script_method_list(List<MethodInfo> *p_list) const { } bool CSharpScript::has_method(const StringName &p_method) const { - if (!script_class) return false; @@ -3305,7 +3199,6 @@ bool CSharpScript::has_method(const StringName &p_method) const { } MethodInfo CSharpScript::get_method_info(const StringName &p_method) const { - if (!script_class) return MethodInfo(); @@ -3326,7 +3219,6 @@ MethodInfo CSharpScript::get_method_info(const StringName &p_method) const { } Error CSharpScript::reload(bool p_keep_state) { - bool has_instances; { MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex); @@ -3488,12 +3380,10 @@ Error CSharpScript::reload(bool p_keep_state) { } ScriptLanguage *CSharpScript::get_language() const { - return CSharpLanguage::get_singleton(); } bool CSharpScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { - #ifdef TOOLS_ENABLED const Map<StringName, Variant>::Element *E = exported_members_defval_cache.find(p_property); @@ -3511,7 +3401,6 @@ bool CSharpScript::get_property_default_value(const StringName &p_property, Vari } void CSharpScript::update_exports() { - #ifdef TOOLS_ENABLED _update_exports(); #endif @@ -3522,7 +3411,6 @@ bool CSharpScript::has_script_signal(const StringName &p_signal) const { } void CSharpScript::get_script_signal_list(List<MethodInfo> *r_signals) const { - for (const Map<StringName, Vector<SignalParameter>>::Element *E = _signals.front(); E; E = E->next()) { MethodInfo mi; mi.name = E->key(); @@ -3579,26 +3467,22 @@ bool CSharpScript::inherits_script(const Ref<Script> &p_script) const { } Ref<Script> CSharpScript::get_base_script() const { - // TODO search in metadata file once we have it, not important any way? return Ref<Script>(); } void CSharpScript::get_script_property_list(List<PropertyInfo> *p_list) const { - for (Map<StringName, PropertyInfo>::Element *E = member_info.front(); E; E = E->next()) { p_list->push_back(E->value()); } } int CSharpScript::get_member_line(const StringName &p_member) const { - // TODO omnisharp return -1; } MultiplayerAPI::RPCMode CSharpScript::_member_get_rpc_mode(IMonoClassMember *p_member) const { - if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute))) return MultiplayerAPI::RPC_MODE_REMOTE; if (p_member->has_attribute(CACHED_CLASS(MasterAttribute))) @@ -3670,7 +3554,6 @@ MultiplayerAPI::RPCMode CSharpScript::get_rset_mode(const StringName &p_variable } Error CSharpScript::load_source_code(const String &p_path) { - Error ferr = read_all_file_utf8(p_path, source); ERR_FAIL_COND_V_MSG(ferr != OK, ferr, @@ -3687,12 +3570,10 @@ Error CSharpScript::load_source_code(const String &p_path) { } StringName CSharpScript::get_script_name() const { - return name; } CSharpScript::CSharpScript() { - _clear(); _resource_path_changed(); @@ -3706,7 +3587,6 @@ CSharpScript::CSharpScript() { } CSharpScript::~CSharpScript() { - #ifdef DEBUG_ENABLED MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex); CSharpLanguage::get_singleton()->script_list.remove(&this->script_list); @@ -3716,7 +3596,6 @@ CSharpScript::~CSharpScript() { /*************** RESOURCE ***************/ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_FILE_CANT_OPEN; @@ -3742,22 +3621,18 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p } void ResourceFormatLoaderCSharpScript::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("cs"); } bool ResourceFormatLoaderCSharpScript::handles_type(const String &p_type) const { - return p_type == "Script" || p_type == CSharpLanguage::get_singleton()->get_type(); } String ResourceFormatLoaderCSharpScript::get_resource_type(const String &p_path) const { - return p_path.get_extension().to_lower() == "cs" ? CSharpLanguage::get_singleton()->get_type() : ""; } Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Ref<CSharpScript> sqscr = p_resource; ERR_FAIL_COND_V(sqscr.is_null(), ERR_INVALID_PARAMETER); @@ -3801,19 +3676,16 @@ Error ResourceFormatSaverCSharpScript::save(const String &p_path, const RES &p_r } void ResourceFormatSaverCSharpScript::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { - if (Object::cast_to<CSharpScript>(p_resource.ptr())) { p_extensions->push_back("cs"); } } bool ResourceFormatSaverCSharpScript::recognize(const RES &p_resource) const { - return Object::cast_to<CSharpScript>(p_resource.ptr()) != nullptr; } CSharpLanguage::StringNameCache::StringNameCache() { - _signal_callback = StaticCString::create("_signal_callback"); _set = StaticCString::create("_set"); _get = StaticCString::create("_get"); diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 280c981a47..52b0783a6e 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -66,7 +66,6 @@ TScriptInstance *cast_script_instance(ScriptInstance *p_inst) { #define CAST_CSHARP_INSTANCE(m_inst) (cast_script_instance<CSharpInstance, CSharpLanguage>(m_inst)) class CSharpScript : public Script { - GDCLASS(CSharpScript, Script); public: @@ -231,7 +230,6 @@ public: }; class CSharpInstance : public ScriptInstance { - friend class CSharpScript; friend class CSharpLanguage; @@ -340,7 +338,6 @@ class ManagedCallableMiddleman : public Object { }; class CSharpLanguage : public ScriptLanguage { - friend class CSharpScript; friend class CSharpInstance; @@ -367,7 +364,6 @@ class CSharpLanguage : public ScriptLanguage { ManagedCallableMiddleman *managed_callable_middleman = memnew(ManagedCallableMiddleman); struct StringNameCache { - StringName _signal_callback; StringName _set; StringName _get; diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 258b8ed3ed..0218773105 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -105,7 +105,6 @@ const char *BindingsGenerator::TypeInterface::DEFAULT_VARARG_C_IN("\t%0 %1_in = %1;\n"); static String fix_doc_description(const String &p_bbcode) { - // This seems to be the correct way to do this. It's the same EditorHelp does. return p_bbcode.dedent() @@ -115,7 +114,6 @@ static String fix_doc_description(const String &p_bbcode) { } static String snake_to_pascal_case(const String &p_identifier, bool p_input_is_upper = false) { - String ret; Vector<String> parts = p_identifier.split("_", true); @@ -148,7 +146,6 @@ static String snake_to_pascal_case(const String &p_identifier, bool p_input_is_u } static String snake_to_camel_case(const String &p_identifier, bool p_input_is_upper = false) { - String ret; Vector<String> parts = p_identifier.split("_", true); @@ -183,7 +180,6 @@ static String snake_to_camel_case(const String &p_identifier, bool p_input_is_up } String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterface *p_itype) { - // Based on the version in EditorHelp if (p_bbcode.empty()) @@ -638,7 +634,6 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf } int BindingsGenerator::_determine_enum_prefix(const EnumInterface &p_ienum) { - CRASH_COND(p_ienum.constants.empty()); const ConstantInterface &front_iconstant = p_ienum.constants.front()->get(); @@ -672,7 +667,6 @@ int BindingsGenerator::_determine_enum_prefix(const EnumInterface &p_ienum) { } void BindingsGenerator::_apply_prefix_to_enum_constants(BindingsGenerator::EnumInterface &p_ienum, int p_prefix_length) { - if (p_prefix_length > 0) { for (List<ConstantInterface>::Element *E = p_ienum.constants.front(); E; E = E->next()) { int curr_prefix_length = p_prefix_length; @@ -708,7 +702,6 @@ void BindingsGenerator::_apply_prefix_to_enum_constants(BindingsGenerator::EnumI } void BindingsGenerator::_generate_method_icalls(const TypeInterface &p_itype) { - for (const List<MethodInterface>::Element *E = p_itype.methods.front(); E; E = E->next()) { const MethodInterface &imethod = E->get(); @@ -773,7 +766,6 @@ void BindingsGenerator::_generate_method_icalls(const TypeInterface &p_itype) { } void BindingsGenerator::_generate_global_constants(StringBuilder &p_output) { - // Constants (in partial GD class) p_output.append("\n#pragma warning disable CS1591 // Disable warning: " @@ -882,7 +874,6 @@ void BindingsGenerator::_generate_global_constants(StringBuilder &p_output) { } Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir) { - ERR_FAIL_COND_V(!initialized, ERR_UNCONFIGURED); DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); @@ -997,7 +988,6 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_proj_dir) { } Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir) { - ERR_FAIL_COND_V(!initialized, ERR_UNCONFIGURED); DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); @@ -1099,7 +1089,6 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_proj_dir) { } Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { - ERR_FAIL_COND_V(!initialized, ERR_UNCONFIGURED); String output_dir = path::abspath(path::realpath(p_output_dir)); @@ -1147,7 +1136,6 @@ Error BindingsGenerator::generate_cs_api(const String &p_output_dir) { // - Csc warning e.g.: // ObjectType/LineEdit.cs(140,38): warning CS0108: 'LineEdit.FocusMode' hides inherited member 'Control.FocusMode'. Use the new keyword if hiding was intended. Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const String &p_output_file) { - CRASH_COND(!itype.is_object_type); bool is_derived_type = itype.base_name != StringName(); @@ -1223,7 +1211,6 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str output.append(INDENT1 "{"); if (class_doc) { - // Add constants for (const List<ConstantInterface>::Element *E = itype.constants.front(); E; E = E->next()) { @@ -1403,7 +1390,6 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str } Error BindingsGenerator::_generate_cs_property(const BindingsGenerator::TypeInterface &p_itype, const PropertyInterface &p_iprop, StringBuilder &p_output) { - const MethodInterface *setter = p_itype.find_method_by_name(p_iprop.setter); // Search it in base types too @@ -1546,7 +1532,6 @@ Error BindingsGenerator::_generate_cs_property(const BindingsGenerator::TypeInte } Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterface &p_itype, const BindingsGenerator::MethodInterface &p_imethod, int &p_method_bind_count, StringBuilder &p_output) { - const TypeInterface *return_type = _get_type_or_placeholder(p_imethod.return_type); String method_bind_field = "__method_bind_" + itos(p_method_bind_count); @@ -1856,7 +1841,6 @@ Error BindingsGenerator::_generate_cs_signal(const BindingsGenerator::TypeInterf } Error BindingsGenerator::generate_glue(const String &p_output_dir) { - ERR_FAIL_COND_V(!initialized, ERR_UNCONFIGURED); bool dir_exists = DirAccess::exists(p_output_dir); @@ -1961,7 +1945,6 @@ Error BindingsGenerator::generate_glue(const String &p_output_dir) { bool tools_sequence = false; for (const List<InternalCall>::Element *E = core_custom_icalls.front(); E; E = E->next()) { - if (tools_sequence) { if (!E->get().editor_only) { tools_sequence = false; @@ -2028,7 +2011,6 @@ uint32_t BindingsGenerator::get_version() { } Error BindingsGenerator::_save_file(const String &p_path, const StringBuilder &p_content) { - FileAccessRef file = FileAccess::open(p_path, FileAccess::WRITE); ERR_FAIL_COND_V_MSG(!file, ERR_FILE_CANT_WRITE, "Cannot open file: '" + p_path + "'."); @@ -2040,7 +2022,6 @@ Error BindingsGenerator::_save_file(const String &p_path, const StringBuilder &p } Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInterface &p_itype, const BindingsGenerator::MethodInterface &p_imethod, StringBuilder &p_output) { - if (p_imethod.is_virtual) return OK; // Ignore @@ -2230,7 +2211,6 @@ Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInte } const BindingsGenerator::TypeInterface *BindingsGenerator::_get_type_or_null(const TypeReference &p_typeref) { - const Map<StringName, TypeInterface>::Element *builtin_type_match = builtin_types.find(p_typeref.cname); if (builtin_type_match) @@ -2257,7 +2237,6 @@ const BindingsGenerator::TypeInterface *BindingsGenerator::_get_type_or_null(con } const BindingsGenerator::TypeInterface *BindingsGenerator::_get_type_or_placeholder(const TypeReference &p_typeref) { - const TypeInterface *found = _get_type_or_null(p_typeref); if (found) @@ -2277,7 +2256,6 @@ const BindingsGenerator::TypeInterface *BindingsGenerator::_get_type_or_placehol } StringName BindingsGenerator::_get_int_type_name_from_meta(GodotTypeInfo::Metadata p_meta) { - switch (p_meta) { case GodotTypeInfo::METADATA_INT_IS_INT8: return "sbyte"; @@ -2310,7 +2288,6 @@ StringName BindingsGenerator::_get_int_type_name_from_meta(GodotTypeInfo::Metada } StringName BindingsGenerator::_get_float_type_name_from_meta(GodotTypeInfo::Metadata p_meta) { - switch (p_meta) { case GodotTypeInfo::METADATA_REAL_IS_FLOAT: return "float"; @@ -2329,7 +2306,6 @@ StringName BindingsGenerator::_get_float_type_name_from_meta(GodotTypeInfo::Meta } bool BindingsGenerator::_populate_object_type_interfaces() { - obj_types.clear(); List<StringName> class_list; @@ -2775,7 +2751,6 @@ bool BindingsGenerator::_populate_object_type_interfaces() { } bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, ArgumentInterface &r_iarg) { - r_iarg.default_argument = p_val; switch (p_val.get_type()) { @@ -2883,7 +2858,6 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar } void BindingsGenerator::_populate_builtin_type_interfaces() { - builtin_types.clear(); TypeInterface itype; @@ -3259,7 +3233,6 @@ void BindingsGenerator::_populate_builtin_type_interfaces() { } void BindingsGenerator::_populate_global_constants() { - int global_constants_count = GlobalConstants::get_global_constant_count(); if (global_constants_count > 0) { @@ -3270,7 +3243,6 @@ void BindingsGenerator::_populate_global_constants() { const DocData::ClassDoc &global_scope_doc = match->value(); for (int i = 0; i < global_constants_count; i++) { - String constant_name = GlobalConstants::get_global_constant_name(i); const DocData::ConstantDoc *const_doc = nullptr; @@ -3349,14 +3321,12 @@ void BindingsGenerator::_populate_global_constants() { } void BindingsGenerator::_initialize_blacklisted_methods() { - blacklisted_methods["Object"].push_back("to_string"); // there is already ToString blacklisted_methods["Object"].push_back("_to_string"); // override ToString instead blacklisted_methods["Object"].push_back("_init"); // never called in C# (TODO: implement it) } void BindingsGenerator::_log(const char *p_format, ...) { - if (log_print_enabled) { va_list list; @@ -3367,7 +3337,6 @@ void BindingsGenerator::_log(const char *p_format, ...) { } void BindingsGenerator::_initialize() { - initialized = false; EditorHelp::generate_doc(); @@ -3395,7 +3364,6 @@ void BindingsGenerator::_initialize() { } void BindingsGenerator::handle_cmdline_args(const List<String> &p_cmdline_args) { - const int NUM_OPTIONS = 2; String generate_all_glue_option = "--generate-mono-glue"; String generate_cs_glue_option = "--generate-mono-cs-glue"; diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h index 9aad9622d9..aad109e03c 100644 --- a/modules/mono/editor/bindings_generator.h +++ b/modules/mono/editor/bindings_generator.h @@ -41,7 +41,6 @@ #include "core/ustring.h" class BindingsGenerator { - struct ConstantInterface { String name; String proxy_name; diff --git a/modules/mono/editor/csharp_project.cpp b/modules/mono/editor/csharp_project.cpp index e5c2d023d3..3a30f3106c 100644 --- a/modules/mono/editor/csharp_project.cpp +++ b/modules/mono/editor/csharp_project.cpp @@ -45,7 +45,6 @@ namespace CSharpProject { void add_item(const String &p_project_path, const String &p_item_type, const String &p_include) { - if (!GLOBAL_DEF("mono/project/auto_update_project", true)) return; diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp index c9117f1312..b183787618 100644 --- a/modules/mono/editor/editor_internal_calls.cpp +++ b/modules/mono/editor/editor_internal_calls.cpp @@ -399,7 +399,6 @@ MonoBoolean godot_icall_Utils_OS_UnixFileHasExecutableAccess(MonoString *p_file_ } void register_editor_internal_calls() { - // GodotSharpDirs mono_add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_ResDataDir", (void *)godot_icall_GodotSharpDirs_ResDataDir); mono_add_internal_call("GodotTools.Internals.GodotSharpDirs::internal_ResMetadataDir", (void *)godot_icall_GodotSharpDirs_ResMetadataDir); diff --git a/modules/mono/editor/script_class_parser.cpp b/modules/mono/editor/script_class_parser.cpp index 3ffbf8ba14..7276612230 100644 --- a/modules/mono/editor/script_class_parser.cpp +++ b/modules/mono/editor/script_class_parser.cpp @@ -54,13 +54,11 @@ const char *ScriptClassParser::token_names[ScriptClassParser::TK_MAX] = { }; String ScriptClassParser::get_token_name(ScriptClassParser::Token p_token) { - ERR_FAIL_INDEX_V(p_token, TK_MAX, "<error>"); return token_names[p_token]; } ScriptClassParser::Token ScriptClassParser::get_token() { - while (true) { switch (code[idx]) { case '\n': { @@ -268,7 +266,6 @@ ScriptClassParser::Token ScriptClassParser::get_token() { } Error ScriptClassParser::_skip_generic_type_params() { - Token tk; while (true) { @@ -337,7 +334,6 @@ Error ScriptClassParser::_skip_generic_type_params() { } Error ScriptClassParser::_parse_type_full_name(String &r_full_name) { - Token tk = get_token(); if (tk != TK_IDENTIFIER) { @@ -370,7 +366,6 @@ Error ScriptClassParser::_parse_type_full_name(String &r_full_name) { } Error ScriptClassParser::_parse_class_base(Vector<String> &r_base) { - String name; Error err = _parse_type_full_name(name); @@ -470,7 +465,6 @@ Error ScriptClassParser::_parse_type_constraints() { } Error ScriptClassParser::_parse_namespace_name(String &r_name, int &r_curly_stack) { - Token tk = get_token(); if (tk == TK_IDENTIFIER) { @@ -497,7 +491,6 @@ Error ScriptClassParser::_parse_namespace_name(String &r_name, int &r_curly_stac } Error ScriptClassParser::parse(const String &p_code) { - code = p_code; idx = 0; line = 0; @@ -653,7 +646,6 @@ static String get_preprocessor_directive(const String &p_line, int p_from) { } static void run_dummy_preprocessor(String &r_source, const String &p_filepath) { - Vector<String> lines = r_source.split("\n", /* p_allow_empty: */ true); bool *include_lines = memnew_arr(bool, lines.size()); @@ -720,7 +712,6 @@ static void run_dummy_preprocessor(String &r_source, const String &p_filepath) { } Error ScriptClassParser::parse_file(const String &p_filepath) { - String source; Error ferr = read_all_file_utf8(p_filepath, source); diff --git a/modules/mono/editor/script_class_parser.h b/modules/mono/editor/script_class_parser.h index a76a3a50a9..c194ed1422 100644 --- a/modules/mono/editor/script_class_parser.h +++ b/modules/mono/editor/script_class_parser.h @@ -36,7 +36,6 @@ #include "core/vector.h" class ScriptClassParser { - public: struct NameDecl { enum Type { diff --git a/modules/mono/glue/arguments_vector.h b/modules/mono/glue/arguments_vector.h index aeb466ba72..4ee553fc11 100644 --- a/modules/mono/glue/arguments_vector.h +++ b/modules/mono/glue/arguments_vector.h @@ -35,7 +35,6 @@ template <typename T, int POOL_SIZE = 5> struct ArgumentsVector { - private: T pool[POOL_SIZE]; T *_ptr; diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp index 2da39a916a..e43b06d18e 100644 --- a/modules/mono/glue/gd_glue.cpp +++ b/modules/mono/glue/gd_glue.cpp @@ -91,7 +91,6 @@ void godot_icall_GD_print(MonoArray *p_what) { } void godot_icall_GD_printerr(MonoArray *p_what) { - String str; int length = mono_array_length(p_what); diff --git a/modules/mono/godotsharp_dirs.cpp b/modules/mono/godotsharp_dirs.cpp index d596163926..692da991c7 100644 --- a/modules/mono/godotsharp_dirs.cpp +++ b/modules/mono/godotsharp_dirs.cpp @@ -86,7 +86,6 @@ String _get_mono_user_dir() { } class _GodotSharpDirs { - public: String res_data_dir; String res_metadata_dir; diff --git a/modules/mono/mono_gc_handle.cpp b/modules/mono/mono_gc_handle.cpp index e362d5affb..16a6875406 100644 --- a/modules/mono/mono_gc_handle.cpp +++ b/modules/mono/mono_gc_handle.cpp @@ -56,11 +56,9 @@ MonoGCHandleData MonoGCHandleData::new_weak_handle(MonoObject *p_object) { } Ref<MonoGCHandleRef> MonoGCHandleRef::create_strong(MonoObject *p_object) { - return memnew(MonoGCHandleRef(MonoGCHandleData::new_strong_handle(p_object))); } Ref<MonoGCHandleRef> MonoGCHandleRef::create_weak(MonoObject *p_object) { - return memnew(MonoGCHandleRef(MonoGCHandleData::new_weak_handle(p_object))); } diff --git a/modules/mono/mono_gc_handle.h b/modules/mono/mono_gc_handle.h index 005ee52b35..13cfad4654 100644 --- a/modules/mono/mono_gc_handle.h +++ b/modules/mono/mono_gc_handle.h @@ -81,7 +81,6 @@ struct MonoGCHandleData { }; class MonoGCHandleRef : public Reference { - GDCLASS(MonoGCHandleRef, Reference); MonoGCHandleData data; diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index fbaa81e83f..a9c6ec19e0 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -130,7 +130,6 @@ void gd_mono_profiler_init() { } void gd_mono_debug_init() { - CharString da_args = OS::get_singleton()->get_environment("GODOT_MONO_DEBUGGER_AGENT").utf8(); if (da_args.length()) { @@ -251,7 +250,6 @@ void GDMono::add_mono_shared_libs_dir_to_path() { } void GDMono::determine_mono_dirs(String &r_assembly_rootdir, String &r_config_dir) { - String bundled_assembly_rootdir = GodotSharpDirs::get_data_mono_lib_dir(); String bundled_config_dir = GodotSharpDirs::get_data_mono_etc_dir(); @@ -314,7 +312,6 @@ void GDMono::determine_mono_dirs(String &r_assembly_rootdir, String &r_config_di } void GDMono::initialize() { - ERR_FAIL_NULL(Engine::get_singleton()); print_verbose("Mono: Initializing module..."); @@ -413,7 +410,6 @@ void GDMono::initialize() { } void GDMono::initialize_load_assemblies() { - #ifndef MONO_GLUE_ENABLED CRASH_NOW_MSG("Mono: This binary was built with 'mono_glue=no'; cannot load assemblies."); #endif @@ -513,12 +509,10 @@ void GDMono::_init_exception_policy() { } void GDMono::add_assembly(uint32_t p_domain_id, GDMonoAssembly *p_assembly) { - assemblies[p_domain_id][p_assembly->get_name()] = p_assembly; } GDMonoAssembly *GDMono::get_loaded_assembly(const String &p_name) { - if (p_name == "mscorlib" && corlib_assembly) return corlib_assembly; @@ -529,7 +523,6 @@ GDMonoAssembly *GDMono::get_loaded_assembly(const String &p_name) { } bool GDMono::load_assembly(const String &p_name, GDMonoAssembly **r_assembly, bool p_refonly) { - #ifdef DEBUG_ENABLED CRASH_COND(!r_assembly); #endif @@ -543,7 +536,6 @@ bool GDMono::load_assembly(const String &p_name, GDMonoAssembly **r_assembly, bo } bool GDMono::load_assembly(const String &p_name, MonoAssemblyName *p_aname, GDMonoAssembly **r_assembly, bool p_refonly) { - #ifdef DEBUG_ENABLED CRASH_COND(!r_assembly); #endif @@ -552,7 +544,6 @@ bool GDMono::load_assembly(const String &p_name, MonoAssemblyName *p_aname, GDMo } bool GDMono::load_assembly(const String &p_name, MonoAssemblyName *p_aname, GDMonoAssembly **r_assembly, bool p_refonly, const Vector<String> &p_search_dirs) { - #ifdef DEBUG_ENABLED CRASH_COND(!r_assembly); #endif @@ -572,7 +563,6 @@ bool GDMono::load_assembly(const String &p_name, MonoAssemblyName *p_aname, GDMo } bool GDMono::load_assembly_from(const String &p_name, const String &p_path, GDMonoAssembly **r_assembly, bool p_refonly) { - CRASH_COND(!r_assembly); print_verbose("Mono: Loading assembly " + p_name + (p_refonly ? " (refonly)" : "") + "..."); @@ -620,7 +610,6 @@ String ApiAssemblyInfo::to_string(ApiAssemblyInfo::Type p_type) { } bool GDMono::_load_corlib_assembly() { - if (corlib_assembly) return true; @@ -634,7 +623,6 @@ bool GDMono::_load_corlib_assembly() { #ifdef TOOLS_ENABLED bool GDMono::copy_prebuilt_api_assembly(ApiAssemblyInfo::Type p_api_type, const String &p_config) { - String src_dir = GodotSharpDirs::get_data_editor_prebuilt_api_dir().plus_file(p_config); String dst_dir = GodotSharpDirs::get_res_assemblies_base_dir().plus_file(p_config); @@ -705,7 +693,6 @@ static bool try_get_cached_api_hash_for(const String &p_api_assemblies_dir, bool } static void create_cached_api_hash_for(const String &p_api_assemblies_dir) { - String core_api_assembly_path = p_api_assemblies_dir.plus_file(CORE_API_ASSEMBLY_NAME ".dll"); String editor_api_assembly_path = p_api_assemblies_dir.plus_file(EDITOR_API_ASSEMBLY_NAME ".dll"); String cached_api_hash_path = p_api_assemblies_dir.plus_file("api_hash_cache.cfg"); @@ -748,7 +735,6 @@ bool GDMono::_temp_domain_load_are_assemblies_out_of_sync(const String &p_config } String GDMono::update_api_assemblies_from_prebuilt(const String &p_config, const bool *p_core_api_out_of_sync, const bool *p_editor_api_out_of_sync) { - #define FAIL_REASON(m_out_of_sync, m_prebuilt_exists) \ ( \ (m_out_of_sync ? \ @@ -805,7 +791,6 @@ String GDMono::update_api_assemblies_from_prebuilt(const String &p_config, const #endif bool GDMono::_load_core_api_assembly(LoadedApiAssembly &r_loaded_api_assembly, const String &p_config, bool p_refonly) { - if (r_loaded_api_assembly.assembly) return true; @@ -839,7 +824,6 @@ bool GDMono::_load_core_api_assembly(LoadedApiAssembly &r_loaded_api_assembly, c #ifdef TOOLS_ENABLED bool GDMono::_load_editor_api_assembly(LoadedApiAssembly &r_loaded_api_assembly, const String &p_config, bool p_refonly) { - if (r_loaded_api_assembly.assembly) return true; @@ -916,7 +900,6 @@ bool GDMono::_try_load_api_assemblies_preset() { } void GDMono::_load_api_assemblies() { - bool api_assemblies_loaded = _try_load_api_assemblies_preset(); #if defined(TOOLS_ENABLED) && !defined(GD_MONO_SINGLE_APPDOMAIN) @@ -969,7 +952,6 @@ void GDMono::_load_api_assemblies() { #ifdef TOOLS_ENABLED bool GDMono::_load_tools_assemblies() { - if (tools_assembly && tools_project_editor_assembly) return true; @@ -981,7 +963,6 @@ bool GDMono::_load_tools_assemblies() { #endif bool GDMono::_load_project_assembly() { - if (project_assembly) return true; @@ -1001,7 +982,6 @@ bool GDMono::_load_project_assembly() { } void GDMono::_install_trace_listener() { - #ifdef DEBUG_ENABLED // Install the trace listener now before the project assembly is loaded GDMonoClass *debug_utils = get_core_api_assembly()->get_class(BINDINGS_NAMESPACE, "DebuggingUtils"); @@ -1018,7 +998,6 @@ void GDMono::_install_trace_listener() { #ifndef GD_MONO_SINGLE_APPDOMAIN Error GDMono::_load_scripts_domain() { - ERR_FAIL_COND_V(scripts_domain != nullptr, ERR_BUG); print_verbose("Mono: Loading scripts domain..."); @@ -1033,7 +1012,6 @@ Error GDMono::_load_scripts_domain() { } Error GDMono::_unload_scripts_domain() { - ERR_FAIL_NULL_V(scripts_domain, ERR_BUG); print_verbose("Mono: Finalizing scripts domain..."); @@ -1086,7 +1064,6 @@ Error GDMono::_unload_scripts_domain() { #ifdef GD_MONO_HOT_RELOAD Error GDMono::reload_scripts_domain() { - ERR_FAIL_COND_V(!runtime_initialized, ERR_BUG); if (scripts_domain) { @@ -1123,7 +1100,6 @@ Error GDMono::reload_scripts_domain() { #ifndef GD_MONO_SINGLE_APPDOMAIN Error GDMono::finalize_and_unload_domain(MonoDomain *p_domain) { - CRASH_COND(p_domain == nullptr); CRASH_COND(p_domain == GDMono::get_singleton()->get_scripts_domain()); // Should use _unload_scripts_domain() instead @@ -1156,7 +1132,6 @@ Error GDMono::finalize_and_unload_domain(MonoDomain *p_domain) { #endif GDMonoClass *GDMono::get_class(MonoClass *p_raw_class) { - MonoImage *image = mono_class_get_image(p_raw_class); if (image == corlib_assembly->get_image()) @@ -1180,7 +1155,6 @@ GDMonoClass *GDMono::get_class(MonoClass *p_raw_class) { } GDMonoClass *GDMono::get_class(const StringName &p_namespace, const StringName &p_name) { - GDMonoClass *klass = corlib_assembly->get_class(p_namespace, p_name); if (klass) return klass; @@ -1200,7 +1174,6 @@ GDMonoClass *GDMono::get_class(const StringName &p_namespace, const StringName & } void GDMono::_domain_assemblies_cleanup(uint32_t p_domain_id) { - HashMap<String, GDMonoAssembly *> &domain_assemblies = assemblies[p_domain_id]; const String *k = nullptr; @@ -1212,7 +1185,6 @@ void GDMono::_domain_assemblies_cleanup(uint32_t p_domain_id) { } void GDMono::unhandled_exception_hook(MonoObject *p_exc, void *) { - // This method will be called by the runtime when a thrown exception is not handled. // It won't be called when we manually treat a thrown exception as unhandled. // We assume the exception was already printed before calling this hook. @@ -1229,7 +1201,6 @@ void GDMono::unhandled_exception_hook(MonoObject *p_exc, void *) { } GDMono::GDMono() { - singleton = this; gdmono_log = memnew(GDMonoLog); @@ -1256,7 +1227,6 @@ GDMono::GDMono() { } GDMono::~GDMono() { - if (is_runtime_initialized()) { #ifndef GD_MONO_SINGLE_APPDOMAIN if (scripts_domain) { @@ -1330,51 +1300,42 @@ GDMono::~GDMono() { _GodotSharp *_GodotSharp::singleton = nullptr; void _GodotSharp::attach_thread() { - GDMonoUtils::attach_current_thread(); } void _GodotSharp::detach_thread() { - GDMonoUtils::detach_current_thread(); } int32_t _GodotSharp::get_domain_id() { - MonoDomain *domain = mono_domain_get(); CRASH_COND(!domain); // User must check if runtime is initialized before calling this method return mono_domain_get_id(domain); } int32_t _GodotSharp::get_scripts_domain_id() { - MonoDomain *domain = GDMono::get_singleton()->get_scripts_domain(); CRASH_COND(!domain); // User must check if scripts domain is loaded before calling this method return mono_domain_get_id(domain); } bool _GodotSharp::is_scripts_domain_loaded() { - return GDMono::get_singleton()->is_runtime_initialized() && GDMono::get_singleton()->get_scripts_domain() != nullptr; } bool _GodotSharp::_is_domain_finalizing_for_unload(int32_t p_domain_id) { - return is_domain_finalizing_for_unload(p_domain_id); } bool _GodotSharp::is_domain_finalizing_for_unload() { - return is_domain_finalizing_for_unload(mono_domain_get()); } bool _GodotSharp::is_domain_finalizing_for_unload(int32_t p_domain_id) { - return is_domain_finalizing_for_unload(mono_domain_get_by_id(p_domain_id)); } bool _GodotSharp::is_domain_finalizing_for_unload(MonoDomain *p_domain) { - if (!p_domain) return true; if (p_domain == GDMono::get_singleton()->get_scripts_domain() && GDMono::get_singleton()->is_finalizing_scripts_domain()) @@ -1383,12 +1344,10 @@ bool _GodotSharp::is_domain_finalizing_for_unload(MonoDomain *p_domain) { } bool _GodotSharp::is_runtime_shutting_down() { - return mono_runtime_is_shutting_down(); } bool _GodotSharp::is_runtime_initialized() { - return GDMono::get_singleton()->is_runtime_initialized(); } @@ -1402,7 +1361,6 @@ void _GodotSharp::_reload_assemblies(bool p_soft_reload) { } void _GodotSharp::_bind_methods() { - ClassDB::bind_method(D_METHOD("attach_thread"), &_GodotSharp::attach_thread); ClassDB::bind_method(D_METHOD("detach_thread"), &_GodotSharp::detach_thread); @@ -1417,11 +1375,9 @@ void _GodotSharp::_bind_methods() { } _GodotSharp::_GodotSharp() { - singleton = this; } _GodotSharp::~_GodotSharp() { - singleton = nullptr; } diff --git a/modules/mono/mono_gd/gd_mono.h b/modules/mono/mono_gd/gd_mono.h index 3b0be4c180..833855b371 100644 --- a/modules/mono/mono_gd/gd_mono.h +++ b/modules/mono/mono_gd/gd_mono.h @@ -75,7 +75,6 @@ String to_string(Type p_type); } // namespace ApiAssemblyInfo class GDMono { - public: enum UnhandledExceptionPolicy { POLICY_TERMINATE_APP, @@ -249,7 +248,6 @@ public: namespace gdmono { class ScopeDomain { - MonoDomain *prev_domain; public: diff --git a/modules/mono/mono_gd/gd_mono_assembly.cpp b/modules/mono/mono_gd/gd_mono_assembly.cpp index ca84338666..073c9a5214 100644 --- a/modules/mono/mono_gd/gd_mono_assembly.cpp +++ b/modules/mono/mono_gd/gd_mono_assembly.cpp @@ -46,7 +46,6 @@ Vector<String> GDMonoAssembly::search_dirs; void GDMonoAssembly::fill_search_dirs(Vector<String> &r_search_dirs, const String &p_custom_config, const String &p_custom_bcl_dir) { - String framework_dir; if (!p_custom_bcl_dir.empty()) { @@ -101,7 +100,6 @@ void GDMonoAssembly::fill_search_dirs(Vector<String> &r_search_dirs, const Strin // assembly to the list of loaded assemblies so that the 'search' hook can look it up. void GDMonoAssembly::assembly_load_hook(MonoAssembly *assembly, [[maybe_unused]] void *user_data) { - String name = String::utf8(mono_assembly_name_get_name(mono_assembly_get_name(assembly))); MonoImage *image = mono_assembly_get_image(assembly); @@ -135,7 +133,6 @@ MonoAssembly *GDMonoAssembly::assembly_refonly_preload_hook(MonoAssemblyName *an } MonoAssembly *GDMonoAssembly::_search_hook(MonoAssemblyName *aname, [[maybe_unused]] void *user_data, bool refonly) { - String name = String::utf8(mono_assembly_name_get_name(aname)); bool has_extension = name.ends_with(".dll") || name.ends_with(".exe"); @@ -147,13 +144,11 @@ MonoAssembly *GDMonoAssembly::_search_hook(MonoAssemblyName *aname, [[maybe_unus } MonoAssembly *GDMonoAssembly::_preload_hook(MonoAssemblyName *aname, char **, [[maybe_unused]] void *user_data, bool refonly) { - String name = String::utf8(mono_assembly_name_get_name(aname)); return _load_assembly_search(name, aname, refonly, search_dirs); } MonoAssembly *GDMonoAssembly::_load_assembly_search(const String &p_name, MonoAssemblyName *p_aname, bool p_refonly, const Vector<String> &p_search_dirs) { - MonoAssembly *res = nullptr; String path; @@ -190,7 +185,6 @@ MonoAssembly *GDMonoAssembly::_load_assembly_search(const String &p_name, MonoAs } String GDMonoAssembly::find_assembly(const String &p_name) { - String path; bool has_extension = p_name.ends_with(".dll") || p_name.ends_with(".exe"); @@ -217,7 +211,6 @@ String GDMonoAssembly::find_assembly(const String &p_name) { } void GDMonoAssembly::initialize() { - fill_search_dirs(search_dirs); mono_install_assembly_search_hook(&assembly_search_hook, nullptr); @@ -228,7 +221,6 @@ void GDMonoAssembly::initialize() { } MonoAssembly *GDMonoAssembly::_real_load_assembly_from(const String &p_path, bool p_refonly, MonoAssemblyName *p_aname) { - Vector<uint8_t> data = FileAccess::get_file_as_array(p_path); ERR_FAIL_COND_V_MSG(data.empty(), nullptr, "Could read the assembly in the specified location"); @@ -326,7 +318,6 @@ no_pdb: } void GDMonoAssembly::unload() { - ERR_FAIL_NULL(image); // Should not be called if already unloaded for (Map<MonoClass *, GDMonoClass *>::Element *E = cached_raw.front(); E; E = E->next()) { @@ -345,7 +336,6 @@ String GDMonoAssembly::get_path() const { } GDMonoClass *GDMonoAssembly::get_class(const StringName &p_namespace, const StringName &p_name) { - ERR_FAIL_NULL_V(image, nullptr); ClassKey key(p_namespace, p_name); @@ -369,7 +359,6 @@ GDMonoClass *GDMonoAssembly::get_class(const StringName &p_namespace, const Stri } GDMonoClass *GDMonoAssembly::get_class(MonoClass *p_mono_class) { - ERR_FAIL_NULL_V(image, nullptr); Map<MonoClass *, GDMonoClass *>::Element *match = cached_raw.find(p_mono_class); @@ -389,7 +378,6 @@ GDMonoClass *GDMonoAssembly::get_class(MonoClass *p_mono_class) { } GDMonoClass *GDMonoAssembly::get_object_derived_class(const StringName &p_class) { - GDMonoClass *match = nullptr; if (gdobject_class_cache_updated) { @@ -449,7 +437,6 @@ GDMonoClass *GDMonoAssembly::get_object_derived_class(const StringName &p_class) } GDMonoAssembly *GDMonoAssembly::load(const String &p_name, MonoAssemblyName *p_aname, bool p_refonly, const Vector<String> &p_search_dirs) { - if (GDMono::get_singleton()->get_corlib_assembly() && (p_name == "mscorlib" || p_name == "mscorlib.dll")) return GDMono::get_singleton()->get_corlib_assembly(); @@ -469,7 +456,6 @@ GDMonoAssembly *GDMonoAssembly::load(const String &p_name, MonoAssemblyName *p_a } GDMonoAssembly *GDMonoAssembly::load_from(const String &p_name, const String &p_path, bool p_refonly) { - if (p_name == "mscorlib" || p_name == "mscorlib.dll") return GDMono::get_singleton()->get_corlib_assembly(); diff --git a/modules/mono/mono_gd/gd_mono_assembly.h b/modules/mono/mono_gd/gd_mono_assembly.h index cc8d699558..63899dc9be 100644 --- a/modules/mono/mono_gd/gd_mono_assembly.h +++ b/modules/mono/mono_gd/gd_mono_assembly.h @@ -40,7 +40,6 @@ #include "gd_mono_utils.h" class GDMonoAssembly { - struct ClassKey { struct Hasher { static _FORCE_INLINE_ uint32_t hash(const ClassKey &p_key) { diff --git a/modules/mono/mono_gd/gd_mono_cache.cpp b/modules/mono/mono_gd/gd_mono_cache.cpp index 5ddf18d544..c002ad2139 100644 --- a/modules/mono/mono_gd/gd_mono_cache.cpp +++ b/modules/mono/mono_gd/gd_mono_cache.cpp @@ -65,7 +65,6 @@ CachedData cached_data; #define CACHE_METHOD_THUNK_AND_CHECK(m_class, m_method, m_val) CACHE_METHOD_THUNK_AND_CHECK_IMPL(cached_data.methodthunk_##m_class##_##m_method, m_val) void CachedData::clear_corlib_cache() { - corlib_cache_updated = false; class_MonoObject = nullptr; @@ -98,7 +97,6 @@ void CachedData::clear_corlib_cache() { } void CachedData::clear_godot_api_cache() { - godot_api_cache_updated = false; rawclass_Dictionary = nullptr; @@ -193,7 +191,6 @@ void CachedData::clear_godot_api_cache() { #define GODOT_API_NS_CLASS(m_ns, m_class) (GDMono::get_singleton()->get_core_api_assembly()->get_class(m_ns, #m_class)) void update_corlib_cache() { - CACHE_CLASS_AND_CHECK(MonoObject, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_object_class())); CACHE_CLASS_AND_CHECK(bool, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_boolean_class())); CACHE_CLASS_AND_CHECK(int8_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_sbyte_class())); @@ -228,7 +225,6 @@ void update_corlib_cache() { } void update_godot_api_cache() { - CACHE_CLASS_AND_CHECK(Vector2, GODOT_API_CLASS(Vector2)); CACHE_CLASS_AND_CHECK(Vector2i, GODOT_API_CLASS(Vector2i)); CACHE_CLASS_AND_CHECK(Rect2, GODOT_API_CLASS(Rect2)); diff --git a/modules/mono/mono_gd/gd_mono_cache.h b/modules/mono/mono_gd/gd_mono_cache.h index 3cf2bd6ce5..a7bbc763a7 100644 --- a/modules/mono/mono_gd/gd_mono_cache.h +++ b/modules/mono/mono_gd/gd_mono_cache.h @@ -37,7 +37,6 @@ namespace GDMonoCache { struct CachedData { - // ----------------------------------------------- // corlib classes diff --git a/modules/mono/mono_gd/gd_mono_class.cpp b/modules/mono/mono_gd/gd_mono_class.cpp index 9dabb4ec4c..691da55b10 100644 --- a/modules/mono/mono_gd/gd_mono_class.cpp +++ b/modules/mono/mono_gd/gd_mono_class.cpp @@ -105,7 +105,6 @@ GDMonoClass *GDMonoClass::get_nesting_class() const { #ifdef TOOLS_ENABLED Vector<MonoClassField *> GDMonoClass::get_enum_fields() { - bool class_is_enum = mono_class_is_enum(mono_class); ERR_FAIL_COND_V(!class_is_enum, Vector<MonoClassField *>()); @@ -128,7 +127,6 @@ Vector<MonoClassField *> GDMonoClass::get_enum_fields() { #endif bool GDMonoClass::has_attribute(GDMonoClass *p_attr_class) { - #ifdef DEBUG_ENABLED ERR_FAIL_NULL_V(p_attr_class, false); #endif @@ -143,7 +141,6 @@ bool GDMonoClass::has_attribute(GDMonoClass *p_attr_class) { } MonoObject *GDMonoClass::get_attribute(GDMonoClass *p_attr_class) { - #ifdef DEBUG_ENABLED ERR_FAIL_NULL_V(p_attr_class, nullptr); #endif @@ -158,7 +155,6 @@ MonoObject *GDMonoClass::get_attribute(GDMonoClass *p_attr_class) { } void GDMonoClass::fetch_attributes() { - ERR_FAIL_COND(attributes != nullptr); attributes = mono_custom_attrs_from_class(get_mono_ptr()); @@ -166,7 +162,6 @@ void GDMonoClass::fetch_attributes() { } void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base) { - CRASH_COND(!CACHED_CLASS(GodotObject)->is_assignable_from(this)); if (methods_fetched) @@ -182,7 +177,6 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base ERR_CONTINUE(!method); if (method->get_name() != name) { - #ifdef DEBUG_ENABLED String fullname = method->get_ret_type_full_name() + " " + name + "(" + method->get_signature_desc(true) + ")"; WARN_PRINT("Method '" + fullname + "' is hidden by Godot API method. Should be '" + @@ -196,7 +190,6 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base // This allows us to warn the user here if he is using snake_case by mistake. if (p_native_base != this) { - GDMonoClass *native_top = p_native_base; while (native_top) { GDMonoMethod *m = native_top->get_method(name, method->get_parameters_count()); @@ -260,7 +253,6 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base } GDMonoMethod *GDMonoClass::get_fetched_method_unknown_params(const StringName &p_name) { - ERR_FAIL_COND_V(!methods_fetched, nullptr); const MethodKey *k = nullptr; @@ -274,23 +266,19 @@ GDMonoMethod *GDMonoClass::get_fetched_method_unknown_params(const StringName &p } bool GDMonoClass::has_fetched_method_unknown_params(const StringName &p_name) { - return get_fetched_method_unknown_params(p_name) != nullptr; } bool GDMonoClass::implements_interface(GDMonoClass *p_interface) { - return mono_class_implements_interface(mono_class, p_interface->get_mono_ptr()); } bool GDMonoClass::has_public_parameterless_ctor() { - GDMonoMethod *ctor = get_method(".ctor", 0); return ctor && ctor->get_visibility() == IMonoClassMember::PUBLIC; } GDMonoMethod *GDMonoClass::get_method(const StringName &p_name, int p_params_count) { - MethodKey key = MethodKey(p_name, p_params_count); GDMonoMethod **match = methods.getptr(key); @@ -314,7 +302,6 @@ GDMonoMethod *GDMonoClass::get_method(const StringName &p_name, int p_params_cou } GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method) { - MonoMethodSignature *sig = mono_method_signature(p_raw_method); int params_count = mono_signature_get_param_count(sig); @@ -324,14 +311,12 @@ GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method) { } GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method, const StringName &p_name) { - MonoMethodSignature *sig = mono_method_signature(p_raw_method); int params_count = mono_signature_get_param_count(sig); return get_method(p_raw_method, p_name, params_count); } GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method, const StringName &p_name, int p_params_count) { - ERR_FAIL_NULL_V(p_raw_method, nullptr); MethodKey key = MethodKey(p_name, p_params_count); @@ -348,7 +333,6 @@ GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method, const StringName } GDMonoMethod *GDMonoClass::get_method_with_desc(const String &p_description, bool p_include_namespace) { - MonoMethodDesc *desc = mono_method_desc_new(p_description.utf8().get_data(), p_include_namespace); MonoMethod *method = mono_method_desc_search_in_class(desc, mono_class); mono_method_desc_free(desc); @@ -362,7 +346,6 @@ GDMonoMethod *GDMonoClass::get_method_with_desc(const String &p_description, boo } GDMonoField *GDMonoClass::get_field(const StringName &p_name) { - Map<StringName, GDMonoField *>::Element *result = fields.find(p_name); if (result) @@ -384,7 +367,6 @@ GDMonoField *GDMonoClass::get_field(const StringName &p_name) { } const Vector<GDMonoField *> &GDMonoClass::get_all_fields() { - if (fields_fetched) return fields_list; @@ -410,7 +392,6 @@ const Vector<GDMonoField *> &GDMonoClass::get_all_fields() { } GDMonoProperty *GDMonoClass::get_property(const StringName &p_name) { - Map<StringName, GDMonoProperty *>::Element *result = properties.find(p_name); if (result) @@ -432,7 +413,6 @@ GDMonoProperty *GDMonoClass::get_property(const StringName &p_name) { } const Vector<GDMonoProperty *> &GDMonoClass::get_all_properties() { - if (properties_fetched) return properties_list; @@ -485,7 +465,6 @@ const Vector<GDMonoClass *> &GDMonoClass::get_all_delegates() { } const Vector<GDMonoMethod *> &GDMonoClass::get_all_methods() { - if (!method_list_fetched) { void *iter = nullptr; MonoMethod *raw_method = nullptr; @@ -500,7 +479,6 @@ const Vector<GDMonoMethod *> &GDMonoClass::get_all_methods() { } GDMonoClass::GDMonoClass(const StringName &p_namespace, const StringName &p_name, MonoClass *p_class, GDMonoAssembly *p_assembly) { - namespace_name = p_namespace; class_name = p_name; mono_class = p_class; @@ -517,7 +495,6 @@ GDMonoClass::GDMonoClass(const StringName &p_namespace, const StringName &p_name } GDMonoClass::~GDMonoClass() { - if (attributes) { mono_custom_attrs_free(attributes); } diff --git a/modules/mono/mono_gd/gd_mono_field.h b/modules/mono/mono_gd/gd_mono_field.h index 61f2c8f071..5b40b439f9 100644 --- a/modules/mono/mono_gd/gd_mono_field.h +++ b/modules/mono/mono_gd/gd_mono_field.h @@ -36,7 +36,6 @@ #include "i_mono_class_member.h" class GDMonoField : public IMonoClassMember { - GDMonoClass *owner; MonoClassField *mono_field; diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index 1898785699..27e402d777 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -45,7 +45,6 @@ namespace GDMonoInternals { void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { - // This method should not fail CRASH_COND(!unmanaged); diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp index b56350ae1b..04728be725 100644 --- a/modules/mono/mono_gd/gd_mono_log.cpp +++ b/modules/mono/mono_gd/gd_mono_log.cpp @@ -51,7 +51,6 @@ GDMonoLog *GDMonoLog::singleton = nullptr; #ifdef GD_MONO_LOG_ENABLED static int get_log_level_id(const char *p_log_level) { - const char *valid_log_levels[] = { "error", "critical", "warning", "message", "info", "debug", nullptr }; int i = 0; @@ -65,7 +64,6 @@ static int get_log_level_id(const char *p_log_level) { } void GDMonoLog::mono_log_callback(const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *) { - FileAccess *f = GDMonoLog::get_singleton()->log_file; if (GDMonoLog::get_singleton()->log_level_id >= get_log_level_id(log_level)) { @@ -94,7 +92,6 @@ void GDMonoLog::mono_log_callback(const char *log_domain, const char *log_level, } bool GDMonoLog::_try_create_logs_dir(const String &p_logs_dir) { - if (!DirAccess::exists(p_logs_dir)) { DirAccessRef diraccess = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); ERR_FAIL_COND_V(!diraccess, false); @@ -106,7 +103,6 @@ bool GDMonoLog::_try_create_logs_dir(const String &p_logs_dir) { } void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) { - static const uint64_t MAX_SECS = 5 * 86400; // 5 days DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); @@ -135,7 +131,6 @@ void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) { } void GDMonoLog::initialize() { - CharString log_level = OS::get_singleton()->get_environment("GODOT_MONO_LOG_LEVEL").utf8(); if (log_level.length() != 0 && get_log_level_id(log_level.get_data()) == -1) { @@ -183,14 +178,12 @@ void GDMonoLog::initialize() { } GDMonoLog::GDMonoLog() { - singleton = this; log_level_id = -1; } GDMonoLog::~GDMonoLog() { - singleton = nullptr; if (log_file) { @@ -207,12 +200,10 @@ void GDMonoLog::initialize() { } GDMonoLog::GDMonoLog() { - singleton = this; } GDMonoLog::~GDMonoLog() { - singleton = nullptr; } diff --git a/modules/mono/mono_gd/gd_mono_log.h b/modules/mono/mono_gd/gd_mono_log.h index 1fc21f7df5..3a52316060 100644 --- a/modules/mono/mono_gd/gd_mono_log.h +++ b/modules/mono/mono_gd/gd_mono_log.h @@ -45,7 +45,6 @@ #endif class GDMonoLog { - #ifdef GD_MONO_LOG_ENABLED int log_level_id; diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 91ee07388b..085062261d 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -787,7 +787,6 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty } Variant mono_object_to_variant_impl(MonoObject *p_obj, const ManagedType &p_type, bool p_fail_with_err = true) { - ERR_FAIL_COND_V(!p_type.type_class, Variant()); switch (p_type.type_encoding) { diff --git a/modules/mono/mono_gd/gd_mono_method.cpp b/modules/mono/mono_gd/gd_mono_method.cpp index 432aa74a6f..e601bb12ad 100644 --- a/modules/mono/mono_gd/gd_mono_method.cpp +++ b/modules/mono/mono_gd/gd_mono_method.cpp @@ -245,7 +245,6 @@ void GDMonoMethod::get_parameter_types(Vector<ManagedType> &types) const { } const MethodInfo &GDMonoMethod::get_method_info() { - if (!method_info_fetched) { method_info.name = name; diff --git a/modules/mono/mono_gd/gd_mono_method.h b/modules/mono/mono_gd/gd_mono_method.h index 54b2eba3e8..f78f57dca0 100644 --- a/modules/mono/mono_gd/gd_mono_method.h +++ b/modules/mono/mono_gd/gd_mono_method.h @@ -36,7 +36,6 @@ #include "i_mono_class_member.h" class GDMonoMethod : public IMonoClassMember { - StringName name; int params_count; diff --git a/modules/mono/mono_gd/gd_mono_method_thunk.h b/modules/mono/mono_gd/gd_mono_method_thunk.h index 82c6f32c81..01f3ae342a 100644 --- a/modules/mono/mono_gd/gd_mono_method_thunk.h +++ b/modules/mono/mono_gd/gd_mono_method_thunk.h @@ -47,7 +47,6 @@ template <class... ParamTypes> struct GDMonoMethodThunk { - typedef void(GD_MONO_STDCALL *M)(ParamTypes... p_args, MonoException **); M mono_method_thunk = nullptr; @@ -90,7 +89,6 @@ public: template <class R, class... ParamTypes> struct GDMonoMethodThunkR { - typedef R(GD_MONO_STDCALL *M)(ParamTypes... p_args, MonoException **); M mono_method_thunk = nullptr; @@ -243,7 +241,6 @@ struct VariadicInvokeMonoMethodR<1, R, P1> { template <class... ParamTypes> struct GDMonoMethodThunk { - GDMonoMethod *mono_method = nullptr; public: @@ -282,7 +279,6 @@ public: template <class R, class... ParamTypes> struct GDMonoMethodThunkR { - GDMonoMethod *mono_method = nullptr; public: diff --git a/modules/mono/mono_gd/gd_mono_property.h b/modules/mono/mono_gd/gd_mono_property.h index 4653758a86..611ac293e4 100644 --- a/modules/mono/mono_gd/gd_mono_property.h +++ b/modules/mono/mono_gd/gd_mono_property.h @@ -36,7 +36,6 @@ #include "i_mono_class_member.h" class GDMonoProperty : public IMonoClassMember { - GDMonoClass *owner; MonoProperty *mono_property; diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index a2ae42ae9f..332744ae6e 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -56,7 +56,6 @@ namespace GDMonoUtils { MonoObject *unmanaged_get_managed(Object *unmanaged) { - if (!unmanaged) return nullptr; diff --git a/modules/mono/signal_awaiter_utils.cpp b/modules/mono/signal_awaiter_utils.cpp index e77a2e98f2..ed0dc5cc28 100644 --- a/modules/mono/signal_awaiter_utils.cpp +++ b/modules/mono/signal_awaiter_utils.cpp @@ -77,7 +77,6 @@ String SignalAwaiterCallable::get_as_text() const { String class_name = base->get_class(); Ref<Script> script = base->get_script(); if (script.is_valid() && script->get_path().is_resource_file()) { - class_name += "(" + script->get_path().get_file() + ")"; } return class_name + "::SignalAwaiterMiddleman::" + String(signal); diff --git a/modules/mono/utils/mono_reg_utils.cpp b/modules/mono/utils/mono_reg_utils.cpp index 8f0ad8ba5e..eff2c7335d 100644 --- a/modules/mono/utils/mono_reg_utils.cpp +++ b/modules/mono/utils/mono_reg_utils.cpp @@ -58,7 +58,6 @@ REGSAM _get_bitness_sam() { } LONG _RegOpenKey(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult) { - LONG res = RegOpenKeyExW(hKey, lpSubKey, 0, KEY_READ, phkResult); if (res != ERROR_SUCCESS) @@ -68,7 +67,6 @@ LONG _RegOpenKey(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult) { } LONG _RegKeyQueryString(HKEY hKey, const String &p_value_name, String &r_value) { - Vector<WCHAR> buffer; buffer.resize(512); DWORD dwBufferSize = buffer.size(); @@ -92,7 +90,6 @@ LONG _RegKeyQueryString(HKEY hKey, const String &p_value_name, String &r_value) } LONG _find_mono_in_reg(const String &p_subkey, MonoRegInfo &r_info, bool p_old_reg = false) { - HKEY hKey; LONG res = _RegOpenKey(HKEY_LOCAL_MACHINE, p_subkey.c_str(), &hKey); @@ -128,7 +125,6 @@ cleanup: } LONG _find_mono_in_reg_old(const String &p_subkey, MonoRegInfo &r_info) { - String default_clr; HKEY hKey; @@ -150,7 +146,6 @@ cleanup: } MonoRegInfo find_mono() { - MonoRegInfo info; if (_find_mono_in_reg("Software\\Mono", info) == ERROR_SUCCESS) @@ -163,7 +158,6 @@ MonoRegInfo find_mono() { } String find_msbuild_tools_path() { - String msbuild_tools_path; // Try to find 15.0 with vswhere diff --git a/modules/mono/utils/mono_reg_utils.h b/modules/mono/utils/mono_reg_utils.h index f844a7233a..4ef876f2b6 100644 --- a/modules/mono/utils/mono_reg_utils.h +++ b/modules/mono/utils/mono_reg_utils.h @@ -36,7 +36,6 @@ #include "core/ustring.h" struct MonoRegInfo { - String version; String install_root_dir; String assembly_dir; diff --git a/modules/mono/utils/osx_utils.cpp b/modules/mono/utils/osx_utils.cpp index 8fadf3c109..8e3e51e688 100644 --- a/modules/mono/utils/osx_utils.cpp +++ b/modules/mono/utils/osx_utils.cpp @@ -38,7 +38,6 @@ #include <CoreServices/CoreServices.h> bool osx_is_app_bundle_installed(const String &p_bundle_id) { - CFURLRef app_url = nullptr; CFStringRef bundle_id = CFStringCreateWithCString(nullptr, p_bundle_id.utf8(), kCFStringEncodingUTF8); OSStatus result = LSFindApplicationForInfo(kLSUnknownCreator, bundle_id, nullptr, nullptr, &app_url); diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index 67b264d803..76d0b9bc9b 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -132,7 +132,6 @@ String sformat(const String &p_text, const Variant &p1, const Variant &p2, const #ifdef TOOLS_ENABLED bool is_csharp_keyword(const String &p_name) { - // Reserved keywords return p_name == "abstract" || p_name == "as" || p_name == "base" || p_name == "bool" || diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp index 16cd04b044..2ded998b60 100644 --- a/modules/opensimplex/noise_texture.cpp +++ b/modules/opensimplex/noise_texture.cpp @@ -59,7 +59,6 @@ NoiseTexture::~NoiseTexture() { } void NoiseTexture::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_width", "width"), &NoiseTexture::set_width); ClassDB::bind_method(D_METHOD("set_height", "height"), &NoiseTexture::set_height); @@ -88,7 +87,6 @@ void NoiseTexture::_bind_methods() { } void NoiseTexture::_validate_property(PropertyInfo &property) const { - if (property.name == "bump_strength") { if (!as_normalmap) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -110,7 +108,6 @@ void NoiseTexture::_set_texture_data(const Ref<Image> &p_image) { } void NoiseTexture::_thread_done(const Ref<Image> &p_image) { - _set_texture_data(p_image); Thread::wait_to_finish(noise_thread); memdelete(noise_thread); @@ -127,7 +124,6 @@ void NoiseTexture::_thread_function(void *p_ud) { } void NoiseTexture::_queue_update() { - if (update_queued) return; @@ -136,7 +132,6 @@ void NoiseTexture::_queue_update() { } Ref<Image> NoiseTexture::_generate_texture() { - // Prevent memdelete due to unref() on other thread. Ref<OpenSimplexNoise> ref_noise = noise; @@ -169,7 +164,6 @@ void NoiseTexture::_update_texture() { use_thread = false; #endif if (use_thread) { - if (!noise_thread) { noise_thread = Thread::create(_thread_function, this); regen_queued = false; @@ -239,7 +233,6 @@ bool NoiseTexture::is_normalmap() { } void NoiseTexture::set_bump_strength(float p_bump_strength) { - if (p_bump_strength == bump_strength) return; bump_strength = p_bump_strength; @@ -248,17 +241,14 @@ void NoiseTexture::set_bump_strength(float p_bump_strength) { } float NoiseTexture::get_bump_strength() { - return bump_strength; } int NoiseTexture::get_width() const { - return size.x; } int NoiseTexture::get_height() const { - return size.y; } @@ -271,6 +261,5 @@ RID NoiseTexture::get_rid() const { } Ref<Image> NoiseTexture::get_data() const { - return data; } diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp index 205c033614..97b66f2c07 100644 --- a/modules/opensimplex/open_simplex_noise.cpp +++ b/modules/opensimplex/open_simplex_noise.cpp @@ -33,7 +33,6 @@ #include "core/core_string_names.h" OpenSimplexNoise::OpenSimplexNoise() { - seed = 0; persistence = 0.5; octaves = 3; @@ -53,7 +52,6 @@ void OpenSimplexNoise::_init_seeds() { } void OpenSimplexNoise::set_seed(int p_seed) { - if (seed == p_seed) return; @@ -65,7 +63,6 @@ void OpenSimplexNoise::set_seed(int p_seed) { } int OpenSimplexNoise::get_seed() { - return seed; } @@ -101,7 +98,6 @@ void OpenSimplexNoise::set_lacunarity(float p_lacunarity) { } Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height) { - Vector<uint8_t> data; data.resize(p_width * p_height * 4); @@ -124,7 +120,6 @@ Ref<Image> OpenSimplexNoise::get_image(int p_width, int p_height) { } Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) { - Vector<uint8_t> data; data.resize(p_size * p_size * 4); @@ -132,7 +127,6 @@ Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) { for (int i = 0; i < p_size; i++) { for (int j = 0; j < p_size; j++) { - float ii = (float)i / (float)p_size; float jj = (float)j / (float)p_size; @@ -161,7 +155,6 @@ Ref<Image> OpenSimplexNoise::get_seamless_image(int p_size) { } void OpenSimplexNoise::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_seed"), &OpenSimplexNoise::get_seed); ClassDB::bind_method(D_METHOD("set_seed", "seed"), &OpenSimplexNoise::set_seed); @@ -196,12 +189,10 @@ void OpenSimplexNoise::_bind_methods() { } float OpenSimplexNoise::get_noise_1d(float x) { - return get_noise_2d(x, 1.0); } float OpenSimplexNoise::get_noise_2d(float x, float y) { - x /= period; y /= period; @@ -222,7 +213,6 @@ float OpenSimplexNoise::get_noise_2d(float x, float y) { } float OpenSimplexNoise::get_noise_3d(float x, float y, float z) { - x /= period; y /= period; z /= period; @@ -245,7 +235,6 @@ float OpenSimplexNoise::get_noise_3d(float x, float y, float z) { } float OpenSimplexNoise::get_noise_4d(float x, float y, float z, float w) { - x /= period; y /= period; z /= period; diff --git a/modules/opensimplex/register_types.cpp b/modules/opensimplex/register_types.cpp index 6fae1fe415..fef90cdce3 100644 --- a/modules/opensimplex/register_types.cpp +++ b/modules/opensimplex/register_types.cpp @@ -33,7 +33,6 @@ #include "open_simplex_noise.h" void register_opensimplex_types() { - ClassDB::register_class<OpenSimplexNoise>(); ClassDB::register_class<NoiseTexture>(); } diff --git a/modules/pvr/register_types.cpp b/modules/pvr/register_types.cpp index 5f900a0256..1eb697bba3 100644 --- a/modules/pvr/register_types.cpp +++ b/modules/pvr/register_types.cpp @@ -35,13 +35,11 @@ static Ref<ResourceFormatPVR> resource_loader_pvr; void register_pvr_types() { - resource_loader_pvr.instance(); ResourceLoader::add_resource_format_loader(resource_loader_pvr); } void unregister_pvr_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_pvr); resource_loader_pvr.unref(); } diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index d498c6d858..6e5cc04f6d 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -52,7 +52,6 @@ enum PVRFLags { }; RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) *r_error = ERR_CANT_OPEN; @@ -109,7 +108,6 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Image::Format format = Image::FORMAT_MAX; switch (flags & 0xFF) { - case 0x18: case 0xC: format = (flags & PVR_HAS_ALPHA) ? Image::FORMAT_PVRTC2A : Image::FORMAT_PVRTC2; @@ -169,22 +167,18 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, } void ResourceFormatPVR::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("pvr"); } bool ResourceFormatPVR::handles_type(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "Texture2D"); } String ResourceFormatPVR::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "pvr") return "Texture2D"; return ""; } static void _compress_pvrtc4(Image *p_img) { - Ref<Image> img = p_img->duplicate(); bool make_mipmaps = false; @@ -208,7 +202,6 @@ static void _compress_pvrtc4(Image *p_img) { const uint8_t *r = img->get_data().ptr(); for (int i = 0; i <= new_img->get_mipmap_count(); i++) { - int ofs, size, w, h; img->get_mipmap_offset_size_and_dimensions(i, ofs, size, w, h); Javelin::RgbaBitmap bm(w, h); @@ -226,7 +219,6 @@ static void _compress_pvrtc4(Image *p_img) { } ResourceFormatPVR::ResourceFormatPVR() { - Image::_image_decompress_pvrtc = _pvrtc_decompress; Image::_image_compress_pvrtc4_func = _compress_pvrtc4; Image::_image_compress_pvrtc2_func = _compress_pvrtc4; @@ -259,7 +251,6 @@ struct PVRTCBlock { }; _FORCE_INLINE_ bool is_po2(uint32_t p_input) { - if (p_input == 0) return false; uint32_t minus1 = p_input - 1; @@ -267,15 +258,12 @@ _FORCE_INLINE_ bool is_po2(uint32_t p_input) { } static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { - uint32_t raw_bits[2]; raw_bits[0] = p_block->data[1] & (0xFFFE); raw_bits[1] = p_block->data[1] >> 16; for (int i = 0; i < 2; i++) { - if (raw_bits[i] & (1 << 15)) { - p_ab_colors[i][0] = (raw_bits[i] >> 10) & 0x1F; p_ab_colors[i][1] = (raw_bits[i] >> 5) & 0x1F; p_ab_colors[i][2] = raw_bits[i] & 0x1F; @@ -283,7 +271,6 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4; p_ab_colors[i][3] = 0xF; } else { - p_ab_colors[i][0] = (raw_bits[i] >> (8 - 1)) & 0x1E; p_ab_colors[i][1] = (raw_bits[i] >> (4 - 1)) & 0x1E; @@ -303,15 +290,12 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { } static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int p_modulation[8][16], int p_modulation_modes[8][16], int p_x, int p_y) { - int block_mod_mode = p_block->data[1] & 1; uint32_t modulation_bits = p_block->data[0]; if (p_2bit && block_mod_mode) { - for (int y = 0; y < BLK_Y_SIZE; y++) { for (int x = 0; x < BLK_X_2BPP; x++) { - p_modulation_modes[y + p_y][x + p_x] = block_mod_mode; if (((x ^ y) & 1) == 0) { @@ -322,7 +306,6 @@ static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int } } else if (p_2bit) { - for (int y = 0; y < BLK_Y_SIZE; y++) { for (int x = 0; x < BLK_X_2BPP; x++) { p_modulation_modes[y + p_y][x + p_x] = block_mod_mode; @@ -463,7 +446,6 @@ static void get_modulation_value(int x, int y, const int p_2bit, const int p_mod static int disable_twiddling = 0; static uint32_t twiddle_uv(uint32_t p_height, uint32_t p_width, uint32_t p_y, uint32_t p_x) { - uint32_t twiddled; uint32_t min_dimension; @@ -559,7 +541,6 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int for (y = 0; y < p_height; y++) { for (x = 0; x < p_width; x++) { - block_x = (x - x_block_size / 2); blk_y = (y - BLK_Y_SIZE / 2); @@ -637,7 +618,6 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int } static void _pvrtc_decompress(Image *p_img) { - ERR_FAIL_COND(p_img->get_format() != Image::FORMAT_PVRTC2 && p_img->get_format() != Image::FORMAT_PVRTC2A && p_img->get_format() != Image::FORMAT_PVRTC4 && p_img->get_format() != Image::FORMAT_PVRTC4A); bool _2bit = (p_img->get_format() == Image::FORMAT_PVRTC2 || p_img->get_format() == Image::FORMAT_PVRTC2A); diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index 25cc580591..c0627b8f25 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -36,26 +36,21 @@ extern "C" { } static void *_regex_malloc(PCRE2_SIZE size, void *user) { - return memalloc(size); } static void _regex_free(void *ptr, void *user) { - memfree(ptr); } int RegExMatch::_find(const Variant &p_name) const { - if (p_name.is_num()) { - int i = (int)p_name; if (i >= data.size()) return -1; return i; } else if (p_name.get_type() == Variant::STRING) { - const Map<String, int>::Element *found = names.find((String)p_name); if (found) return found->value(); @@ -65,19 +60,16 @@ int RegExMatch::_find(const Variant &p_name) const { } String RegExMatch::get_subject() const { - return subject; } int RegExMatch::get_group_count() const { - if (data.size() == 0) return 0; return data.size() - 1; } Dictionary RegExMatch::get_names() const { - Dictionary result; for (const Map<String, int>::Element *i = names.front(); i != nullptr; i = i->next()) { @@ -88,13 +80,11 @@ Dictionary RegExMatch::get_names() const { } Array RegExMatch::get_strings() const { - Array result; int size = data.size(); for (int i = 0; i < size; i++) { - int start = data[i].start; if (start == -1) { @@ -111,7 +101,6 @@ Array RegExMatch::get_strings() const { } String RegExMatch::get_string(const Variant &p_name) const { - int id = _find(p_name); if (id < 0) @@ -128,7 +117,6 @@ String RegExMatch::get_string(const Variant &p_name) const { } int RegExMatch::get_start(const Variant &p_name) const { - int id = _find(p_name); if (id < 0) @@ -138,7 +126,6 @@ int RegExMatch::get_start(const Variant &p_name) const { } int RegExMatch::get_end(const Variant &p_name) const { - int id = _find(p_name); if (id < 0) @@ -148,7 +135,6 @@ int RegExMatch::get_end(const Variant &p_name) const { } void RegExMatch::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_subject"), &RegExMatch::get_subject); ClassDB::bind_method(D_METHOD("get_group_count"), &RegExMatch::get_group_count); ClassDB::bind_method(D_METHOD("get_names"), &RegExMatch::get_names); @@ -163,28 +149,22 @@ void RegExMatch::_bind_methods() { } void RegEx::_pattern_info(uint32_t what, void *where) const { - if (sizeof(CharType) == 2) { - pcre2_pattern_info_16((pcre2_code_16 *)code, what, where); } else { - pcre2_pattern_info_32((pcre2_code_32 *)code, what, where); } } void RegEx::clear() { - if (sizeof(CharType) == 2) { - if (code) { pcre2_code_free_16((pcre2_code_16 *)code); code = nullptr; } } else { - if (code) { pcre2_code_free_32((pcre2_code_32 *)code); code = nullptr; @@ -193,7 +173,6 @@ void RegEx::clear() { } Error RegEx::compile(const String &p_pattern) { - pattern = p_pattern; clear(); @@ -202,7 +181,6 @@ Error RegEx::compile(const String &p_pattern) { uint32_t flags = PCRE2_DUPNAMES; if (sizeof(CharType) == 2) { - pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx; pcre2_compile_context_16 *cctx = pcre2_compile_context_create_16(gctx); PCRE2_SPTR16 p = (PCRE2_SPTR16)pattern.c_str(); @@ -220,7 +198,6 @@ Error RegEx::compile(const String &p_pattern) { } } else { - pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; pcre2_compile_context_32 *cctx = pcre2_compile_context_create_32(gctx); PCRE2_SPTR32 p = (PCRE2_SPTR32)pattern.c_str(); @@ -241,7 +218,6 @@ Error RegEx::compile(const String &p_pattern) { } Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) const { - ERR_FAIL_COND_V(!is_valid(), nullptr); Ref<RegExMatch> result = memnew(RegExMatch); @@ -251,7 +227,6 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) length = p_end; if (sizeof(CharType) == 2) { - pcre2_code_16 *c = (pcre2_code_16 *)code; pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx; pcre2_match_context_16 *mctx = pcre2_match_context_create_16(gctx); @@ -272,7 +247,6 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) result->data.resize(size); for (uint32_t i = 0; i < size; i++) { - result->data.write[i].start = ovector[i * 2]; result->data.write[i].end = ovector[i * 2 + 1]; } @@ -281,7 +255,6 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) pcre2_match_context_free_16(mctx); } else { - pcre2_code_32 *c = (pcre2_code_32 *)code; pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; pcre2_match_context_32 *mctx = pcre2_match_context_create_32(gctx); @@ -304,7 +277,6 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) result->data.resize(size); for (uint32_t i = 0; i < size; i++) { - result->data.write[i].start = ovector[i * 2]; result->data.write[i].end = ovector[i * 2 + 1]; } @@ -324,7 +296,6 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) _pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &entry_size); for (uint32_t i = 0; i < count; i++) { - CharType id = table[i * entry_size]; if (result->data[id].start == -1) continue; @@ -339,7 +310,6 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) } Array RegEx::search_all(const String &p_subject, int p_offset, int p_end) const { - int last_end = -1; Array result; Ref<RegExMatch> match = search(p_subject, p_offset, p_end); @@ -354,7 +324,6 @@ Array RegEx::search_all(const String &p_subject, int p_offset, int p_end) const } String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_all, int p_offset, int p_end) const { - ERR_FAIL_COND_V(!is_valid(), String()); // safety_zone is the number of chars we allocate in addition to the number of chars expected in order to @@ -376,7 +345,6 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a length = p_end; if (sizeof(CharType) == 2) { - pcre2_code_16 *c = (pcre2_code_16 *)code; pcre2_general_context_16 *gctx = (pcre2_general_context_16 *)general_ctx; pcre2_match_context_16 *mctx = pcre2_match_context_create_16(gctx); @@ -401,7 +369,6 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a return String(); } else { - pcre2_code_32 *c = (pcre2_code_32 *)code; pcre2_general_context_32 *gctx = (pcre2_general_context_32 *)general_ctx; pcre2_match_context_32 *mctx = pcre2_match_context_create_32(gctx); @@ -430,17 +397,14 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a } bool RegEx::is_valid() const { - return (code != nullptr); } String RegEx::get_pattern() const { - return pattern; } int RegEx::get_group_count() const { - ERR_FAIL_COND_V(!is_valid(), 0); uint32_t count; @@ -451,7 +415,6 @@ int RegEx::get_group_count() const { } Array RegEx::get_names() const { - Array result; ERR_FAIL_COND_V(!is_valid(), result); @@ -465,7 +428,6 @@ Array RegEx::get_names() const { _pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &entry_size); for (uint32_t i = 0; i < count; i++) { - String name = &table[i * entry_size + 1]; if (result.find(name) < 0) { result.append(name); @@ -476,26 +438,20 @@ Array RegEx::get_names() const { } RegEx::RegEx() { - if (sizeof(CharType) == 2) { - general_ctx = pcre2_general_context_create_16(&_regex_malloc, &_regex_free, nullptr); } else { - general_ctx = pcre2_general_context_create_32(&_regex_malloc, &_regex_free, nullptr); } code = nullptr; } RegEx::RegEx(const String &p_pattern) { - if (sizeof(CharType) == 2) { - general_ctx = pcre2_general_context_create_16(&_regex_malloc, &_regex_free, nullptr); } else { - general_ctx = pcre2_general_context_create_32(&_regex_malloc, &_regex_free, nullptr); } code = nullptr; @@ -503,15 +459,12 @@ RegEx::RegEx(const String &p_pattern) { } RegEx::~RegEx() { - if (sizeof(CharType) == 2) { - if (code) pcre2_code_free_16((pcre2_code_16 *)code); pcre2_general_context_free_16((pcre2_general_context_16 *)general_ctx); } else { - if (code) pcre2_code_free_32((pcre2_code_32 *)code); pcre2_general_context_free_32((pcre2_general_context_32 *)general_ctx); @@ -519,7 +472,6 @@ RegEx::~RegEx() { } void RegEx::_bind_methods() { - ClassDB::bind_method(D_METHOD("clear"), &RegEx::clear); ClassDB::bind_method(D_METHOD("compile", "pattern"), &RegEx::compile); ClassDB::bind_method(D_METHOD("search", "subject", "offset", "end"), &RegEx::search, DEFVAL(0), DEFVAL(-1)); diff --git a/modules/regex/regex.h b/modules/regex/regex.h index a342c17c78..52b49c783e 100644 --- a/modules/regex/regex.h +++ b/modules/regex/regex.h @@ -39,7 +39,6 @@ #include "core/vector.h" class RegExMatch : public Reference { - GDCLASS(RegExMatch, Reference); struct Range { @@ -70,7 +69,6 @@ public: }; class RegEx : public Reference { - GDCLASS(RegEx, Reference); void *general_ctx; diff --git a/modules/regex/register_types.cpp b/modules/regex/register_types.cpp index 77b19fa8f0..5d4aeba2d7 100644 --- a/modules/regex/register_types.cpp +++ b/modules/regex/register_types.cpp @@ -33,7 +33,6 @@ #include "regex.h" void register_regex_types() { - ClassDB::register_class<RegExMatch>(); ClassDB::register_class<RegEx>(); } diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index bb77f68590..a19f3158c4 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -78,7 +78,6 @@ void image_decompress_squish(Image *p_image) { } void image_compress_squish(Image *p_image, float p_lossy_quality, Image::UsedChannels p_channels) { - if (p_image->get_format() >= Image::FORMAT_DXT1) return; //do not compress, already compressed @@ -86,7 +85,6 @@ void image_compress_squish(Image *p_image, float p_lossy_quality, Image::UsedCha int h = p_image->get_height(); if (p_image->get_format() <= Image::FORMAT_RGBA8) { - int squish_comp = squish::kColourRangeFit; if (p_lossy_quality > 0.85) @@ -100,32 +98,26 @@ void image_compress_squish(Image *p_image, float p_lossy_quality, Image::UsedCha switch (p_channels) { case Image::USED_CHANNELS_L: { - target_format = Image::FORMAT_DXT1; squish_comp |= squish::kDxt1; } break; case Image::USED_CHANNELS_LA: { - target_format = Image::FORMAT_DXT5; squish_comp |= squish::kDxt5; } break; case Image::USED_CHANNELS_R: { - target_format = Image::FORMAT_RGTC_R; squish_comp |= squish::kBc4; } break; case Image::USED_CHANNELS_RG: { - target_format = Image::FORMAT_RGTC_RG; squish_comp |= squish::kBc5; } break; case Image::USED_CHANNELS_RGB: { - target_format = Image::FORMAT_DXT1; squish_comp |= squish::kDxt1; } break; case Image::USED_CHANNELS_RGBA: { - //TODO, should convert both, then measure which one does a better job target_format = Image::FORMAT_DXT5; squish_comp |= squish::kDxt5; @@ -149,7 +141,6 @@ void image_compress_squish(Image *p_image, float p_lossy_quality, Image::UsedCha int dst_ofs = 0; for (int i = 0; i <= mm_count; i++) { - int bw = w % 4 != 0 ? w + (4 - w % 4) : w; int bh = h % 4 != 0 ? h + (4 - h % 4) : h; diff --git a/modules/squish/register_types.cpp b/modules/squish/register_types.cpp index 2a0cf82b56..ad28aff058 100644 --- a/modules/squish/register_types.cpp +++ b/modules/squish/register_types.cpp @@ -32,7 +32,6 @@ #include "image_compress_squish.h" void register_squish_types() { - Image::set_compress_bc_func(image_compress_squish); Image::_image_decompress_bc = image_decompress_squish; } diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 9609c234ec..40dc24e317 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -33,7 +33,6 @@ #include "core/os/file_access.h" void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_frames) { - ERR_FAIL_COND(!active); int todo = p_frames; @@ -76,12 +75,10 @@ void AudioStreamPlaybackOGGVorbis::_mix_internal(AudioFrame *p_buffer, int p_fra } float AudioStreamPlaybackOGGVorbis::get_stream_sampling_rate() { - return vorbis_stream->sample_rate; } void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { - active = true; seek(p_from_pos); loops = 0; @@ -89,25 +86,20 @@ void AudioStreamPlaybackOGGVorbis::start(float p_from_pos) { } void AudioStreamPlaybackOGGVorbis::stop() { - active = false; } bool AudioStreamPlaybackOGGVorbis::is_playing() const { - return active; } int AudioStreamPlaybackOGGVorbis::get_loop_count() const { - return loops; } float AudioStreamPlaybackOGGVorbis::get_playback_position() const { - return float(frames_mixed) / vorbis_stream->sample_rate; } void AudioStreamPlaybackOGGVorbis::seek(float p_time) { - if (!active) return; @@ -127,7 +119,6 @@ AudioStreamPlaybackOGGVorbis::~AudioStreamPlaybackOGGVorbis() { } Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { - Ref<AudioStreamPlaybackOGGVorbis> ovs; ERR_FAIL_COND_V(data == nullptr, ovs); @@ -142,7 +133,6 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { int error; ovs->ogg_stream = stb_vorbis_open_memory((const unsigned char *)data, data_len, &error, &ovs->ogg_alloc); if (!ovs->ogg_stream) { - memfree(ovs->ogg_alloc.alloc_buffer); ovs->ogg_alloc.alloc_buffer = nullptr; ERR_FAIL_COND_V(!ovs->ogg_stream, Ref<AudioStreamPlaybackOGGVorbis>()); @@ -152,7 +142,6 @@ Ref<AudioStreamPlayback> AudioStreamOGGVorbis::instance_playback() { } String AudioStreamOGGVorbis::get_stream_name() const { - return ""; //return stream_name; } @@ -165,7 +154,6 @@ void AudioStreamOGGVorbis::clear_data() { } void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) { - int src_data_len = p_data.size(); #define MAX_TEST_MEM (1 << 20) @@ -176,7 +164,6 @@ void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) { stb_vorbis_alloc ogg_alloc; while (alloc_try < MAX_TEST_MEM) { - alloc_mem.resize(alloc_try); w = alloc_mem.ptrw(); @@ -189,10 +176,8 @@ void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) { ogg_stream = stb_vorbis_open_memory((const unsigned char *)src_datar, src_data_len, &error, &ogg_alloc); if (!ogg_stream && error == VORBIS_outofmem) { - alloc_try *= 2; } else { - ERR_FAIL_COND(alloc_try == MAX_TEST_MEM); ERR_FAIL_COND(ogg_stream == nullptr); @@ -220,7 +205,6 @@ void AudioStreamOGGVorbis::set_data(const Vector<uint8_t> &p_data) { } Vector<uint8_t> AudioStreamOGGVorbis::get_data() const { - Vector<uint8_t> vdata; if (data_len && data) { @@ -239,7 +223,6 @@ void AudioStreamOGGVorbis::set_loop(bool p_enable) { } bool AudioStreamOGGVorbis::has_loop() const { - return loop; } @@ -252,12 +235,10 @@ float AudioStreamOGGVorbis::get_loop_offset() const { } float AudioStreamOGGVorbis::get_length() const { - return length; } void AudioStreamOGGVorbis::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamOGGVorbis::set_data); ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamOGGVorbis::get_data); @@ -273,7 +254,6 @@ void AudioStreamOGGVorbis::_bind_methods() { } AudioStreamOGGVorbis::AudioStreamOGGVorbis() { - data = nullptr; data_len = 0; length = 0; diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index f296e8c19f..3002134651 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -39,7 +39,6 @@ class AudioStreamOGGVorbis; class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { - GDCLASS(AudioStreamPlaybackOGGVorbis, AudioStreamPlaybackResampled); stb_vorbis *ogg_stream; @@ -71,7 +70,6 @@ public: }; class AudioStreamOGGVorbis : public AudioStream { - GDCLASS(AudioStreamOGGVorbis, AudioStream); OBJ_SAVE_TYPE(AudioStream); // Saves derived classes with common type so they can be interchanged. RES_BASE_EXTENSION("oggstr"); diff --git a/modules/stb_vorbis/register_types.cpp b/modules/stb_vorbis/register_types.cpp index ac2612bd6a..6669d30278 100644 --- a/modules/stb_vorbis/register_types.cpp +++ b/modules/stb_vorbis/register_types.cpp @@ -38,7 +38,6 @@ #endif void register_stb_vorbis_types() { - #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { Ref<ResourceImporterOGGVorbis> ogg_import; diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp index 13d96541e3..269b7a9d33 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.cpp @@ -35,16 +35,13 @@ #include "scene/resources/texture.h" String ResourceImporterOGGVorbis::get_importer_name() const { - return "ogg_vorbis"; } String ResourceImporterOGGVorbis::get_visible_name() const { - return "OGGVorbis"; } void ResourceImporterOGGVorbis::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("ogg"); } @@ -53,12 +50,10 @@ String ResourceImporterOGGVorbis::get_save_extension() const { } String ResourceImporterOGGVorbis::get_resource_type() const { - return "AudioStreamOGGVorbis"; } bool ResourceImporterOGGVorbis::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { - return true; } @@ -66,18 +61,15 @@ int ResourceImporterOGGVorbis::get_preset_count() const { return 0; } String ResourceImporterOGGVorbis::get_preset_name(int p_idx) const { - return String(); } void ResourceImporterOGGVorbis::get_import_options(List<ImportOption> *r_options, int p_preset) const { - r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "loop_offset"), 0)); } Error ResourceImporterOGGVorbis::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { - bool loop = p_options["loop"]; float loop_offset = p_options["loop_offset"]; diff --git a/modules/svg/image_loader_svg.cpp b/modules/svg/image_loader_svg.cpp index 3c2784f8de..db3622ef96 100644 --- a/modules/svg/image_loader_svg.cpp +++ b/modules/svg/image_loader_svg.cpp @@ -47,7 +47,6 @@ SVGRasterizer::~SVGRasterizer() { SVGRasterizer ImageLoaderSVG::rasterizer; inline void change_nsvg_paint_color(NSVGpaint *p_paint, const uint32_t p_old, const uint32_t p_new) { - if (p_paint->type == NSVG_PAINT_COLOR) { if (p_paint->color << 8 == p_old << 8) { p_paint->color = (p_paint->color & 0xFF000000) | (p_new & 0x00FFFFFF); @@ -64,9 +63,7 @@ inline void change_nsvg_paint_color(NSVGpaint *p_paint, const uint32_t p_old, co } void ImageLoaderSVG::_convert_colors(NSVGimage *p_svg_image) { - for (NSVGshape *shape = p_svg_image->shapes; shape != nullptr; shape = shape->next) { - for (int i = 0; i < replace_colors.old_colors.size(); i++) { change_nsvg_paint_color(&(shape->stroke), replace_colors.old_colors[i], replace_colors.new_colors[i]); change_nsvg_paint_color(&(shape->fill), replace_colors.old_colors[i], replace_colors.new_colors[i]); @@ -75,7 +72,6 @@ void ImageLoaderSVG::_convert_colors(NSVGimage *p_svg_image) { } void ImageLoaderSVG::set_convert_colors(Dictionary *p_replace_color) { - if (p_replace_color) { Dictionary replace_color = *p_replace_color; for (int i = 0; i < replace_color.keys().size(); i++) { @@ -133,7 +129,6 @@ Error ImageLoaderSVG::_create_image(Ref<Image> p_image, const Vector<uint8_t> *p } Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, const char *p_svg_str, float p_scale, bool upsample, bool convert_colors) { - size_t str_len = strlen(p_svg_str); Vector<uint8_t> src_data; src_data.resize(str_len + 1); @@ -144,7 +139,6 @@ Error ImageLoaderSVG::create_image_from_string(Ref<Image> p_image, const char *p } Error ImageLoaderSVG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { - uint32_t size = f->get_len(); Vector<uint8_t> src_image; src_image.resize(size + 1); @@ -156,7 +150,6 @@ Error ImageLoaderSVG::load_image(Ref<Image> p_image, FileAccess *f, bool p_force } void ImageLoaderSVG::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("svg"); p_extensions->push_back("svgz"); } diff --git a/modules/svg/image_loader_svg.h b/modules/svg/image_loader_svg.h index 0fa4a0fdf4..ecaba5052b 100644 --- a/modules/svg/image_loader_svg.h +++ b/modules/svg/image_loader_svg.h @@ -43,7 +43,6 @@ struct NSVGrasterizer; struct NSVGimage; class SVGRasterizer { - NSVGrasterizer *rasterizer; public: diff --git a/modules/svg/register_types.cpp b/modules/svg/register_types.cpp index 37875313aa..9fbefd2cfe 100644 --- a/modules/svg/register_types.cpp +++ b/modules/svg/register_types.cpp @@ -35,12 +35,10 @@ static ImageLoaderSVG *image_loader_svg = nullptr; void register_svg_types() { - image_loader_svg = memnew(ImageLoaderSVG); ImageLoader::add_image_format_loader(image_loader_svg); } void unregister_svg_types() { - memdelete(image_loader_svg); } diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp index eb9f23d894..53c6a8c269 100644 --- a/modules/tga/image_loader_tga.cpp +++ b/modules/tga/image_loader_tga.cpp @@ -77,7 +77,6 @@ Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t } Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buffer, const tga_header_s &p_header, const uint8_t *p_palette, const bool p_is_monochrome) { - #define TGA_PUT_PIXEL(r, g, b, a) \ int image_data_ofs = ((y * width) + x); \ image_data_w[image_data_ofs * 4 + 0] = r; \ @@ -205,7 +204,6 @@ Error ImageLoaderTGA::convert_to_image(Ref<Image> p_image, const uint8_t *p_buff } Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { - Vector<uint8_t> src_image; int src_image_len = f->get_len(); ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); @@ -286,7 +284,6 @@ Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force const uint8_t *buffer = nullptr; if (is_encoded) { - err = decode_tga_rle(src_image_r, pixel_size, uncompressed_buffer_w, buffer_size); if (err == OK) { @@ -308,7 +305,6 @@ Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force } void ImageLoaderTGA::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("tga"); } diff --git a/modules/tga/register_types.cpp b/modules/tga/register_types.cpp index 0d9268ebbf..320f748083 100644 --- a/modules/tga/register_types.cpp +++ b/modules/tga/register_types.cpp @@ -35,12 +35,10 @@ static ImageLoaderTGA *image_loader_tga = nullptr; void register_tga_types() { - image_loader_tga = memnew(ImageLoaderTGA); ImageLoader::add_image_format_loader(image_loader_tga); } void unregister_tga_types() { - memdelete(image_loader_tga); } diff --git a/modules/theora/register_types.cpp b/modules/theora/register_types.cpp index f58e27c855..0676cab5c5 100644 --- a/modules/theora/register_types.cpp +++ b/modules/theora/register_types.cpp @@ -35,7 +35,6 @@ static Ref<ResourceFormatLoaderTheora> resource_loader_theora; void register_theora_types() { - resource_loader_theora.instance(); ResourceLoader::add_resource_format_loader(resource_loader_theora, true); @@ -43,7 +42,6 @@ void register_theora_types() { } void unregister_theora_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_theora); resource_loader_theora.unref(); } diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 3163b60bb8..7df204ff51 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -36,7 +36,6 @@ #include "thirdparty/misc/yuv2rgb.h" int VideoStreamPlaybackTheora::buffer_data() { - char *buffer = ogg_sync_buffer(&oy, 4096); #ifdef THEORA_USE_THREAD_STREAMING @@ -93,15 +92,12 @@ void VideoStreamPlaybackTheora::video_write() { //uv_offset=(ti.pic_x/2)+(yuv[1].stride)*(ti.pic_y/2); if (px_fmt == TH_PF_444) { - yuv444_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); } else if (px_fmt == TH_PF_422) { - yuv422_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); } else if (px_fmt == TH_PF_420) { - yuv420_2_rgb8888((uint8_t *)dst, (uint8_t *)yuv[0].data, (uint8_t *)yuv[1].data, (uint8_t *)yuv[2].data, size.x, size.y, yuv[0].stride, yuv[1].stride, size.x << 2); }; @@ -116,7 +112,6 @@ void VideoStreamPlaybackTheora::video_write() { } void VideoStreamPlaybackTheora::clear() { - if (!file) return; @@ -164,7 +159,6 @@ void VideoStreamPlaybackTheora::clear() { }; void VideoStreamPlaybackTheora::set_file(const String &p_file) { - ERR_FAIL_COND(playing); ogg_packet op; th_setup_info *ts = nullptr; @@ -232,7 +226,6 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { copymem(&to, &test, sizeof(test)); theora_p = 1; } else if (!vorbis_p && vorbis_synthesis_headerin(&vi, &vc, &op) >= 0) { - /* it is vorbis */ if (audio_track_skip) { vorbis_info_clear(&vi); @@ -374,12 +367,10 @@ float VideoStreamPlaybackTheora::get_time() const { }; Ref<Texture2D> VideoStreamPlaybackTheora::get_texture() const { - return texture; } void VideoStreamPlaybackTheora::update(float p_delta) { - if (!file) return; @@ -415,13 +406,11 @@ void VideoStreamPlaybackTheora::update(float p_delta) { /* if there's pending, decoded audio, grab it */ ret = vorbis_synthesis_pcmout(&vd, &pcm); if (ret > 0) { - const int AUXBUF_LEN = 4096; int to_read = ret; float aux_buffer[AUXBUF_LEN]; while (to_read) { - int m = MIN(AUXBUF_LEN / vi.channels, to_read); int count = 0; @@ -449,7 +438,6 @@ void VideoStreamPlaybackTheora::update(float p_delta) { audio_frames_wrote += ret - to_read; } else { - /* no pending audio; is there a pending packet to decode? */ if (ogg_stream_packetout(&vo, &op) > 0) { if (vorbis_synthesis(&vb, &op) == 0) { /* test for success! */ @@ -469,7 +457,6 @@ void VideoStreamPlaybackTheora::update(float p_delta) { while (theora_p && !frame_done) { /* theora is one in, one out... */ if (ogg_stream_packetout(&to, &op) > 0) { - if (false && pp_inc) { pp_level += pp_inc; th_decode_ctl(td, TH_DECCTL_SET_PPLEVEL, &pp_level, @@ -536,7 +523,6 @@ void VideoStreamPlaybackTheora::update(float p_delta) { /* are we at or past time for this video frame? */ if (videobuf_ready && videobuf_time <= get_time()) { - //video_write(); //videobuf_ready=0; } else { @@ -556,7 +542,6 @@ void VideoStreamPlaybackTheora::update(float p_delta) { }; void VideoStreamPlaybackTheora::play() { - if (!playing) time = 0; else { @@ -569,9 +554,7 @@ void VideoStreamPlaybackTheora::play() { }; void VideoStreamPlaybackTheora::stop() { - if (playing) { - clear(); set_file(file_name); //reset } @@ -580,17 +563,14 @@ void VideoStreamPlaybackTheora::stop() { }; bool VideoStreamPlaybackTheora::is_playing() const { - return playing; }; void VideoStreamPlaybackTheora::set_paused(bool p_paused) { - paused = p_paused; }; bool VideoStreamPlaybackTheora::is_paused() const { - return paused; }; @@ -599,27 +579,22 @@ void VideoStreamPlaybackTheora::set_loop(bool p_enable){ }; bool VideoStreamPlaybackTheora::has_loop() const { - return false; }; float VideoStreamPlaybackTheora::get_length() const { - return 0; }; String VideoStreamPlaybackTheora::get_stream_name() const { - return ""; }; int VideoStreamPlaybackTheora::get_loop_count() const { - return 0; }; float VideoStreamPlaybackTheora::get_playback_position() const { - return get_time(); }; @@ -629,37 +604,30 @@ void VideoStreamPlaybackTheora::seek(float p_time){ }; void VideoStreamPlaybackTheora::set_mix_callback(AudioMixCallback p_callback, void *p_userdata) { - mix_callback = p_callback; mix_udata = p_userdata; } int VideoStreamPlaybackTheora::get_channels() const { - return vi.channels; } void VideoStreamPlaybackTheora::set_audio_track(int p_idx) { - audio_track = p_idx; } int VideoStreamPlaybackTheora::get_mix_rate() const { - return vi.rate; } #ifdef THEORA_USE_THREAD_STREAMING void VideoStreamPlaybackTheora::_streaming_thread(void *ud) { - VideoStreamPlaybackTheora *vs = (VideoStreamPlaybackTheora *)ud; while (!vs->thread_exit) { - //just fill back the buffer if (!vs->thread_eof) { - int to_read = vs->ring_buffer.space_left(); if (to_read) { int read = vs->file->get_buffer(vs->read_buffer.ptr(), to_read); @@ -675,7 +643,6 @@ void VideoStreamPlaybackTheora::_streaming_thread(void *ud) { #endif VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { - file = nullptr; theora_p = 0; vorbis_p = 0; @@ -706,7 +673,6 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() { }; VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { - #ifdef THEORA_USE_THREAD_STREAMING memdelete(thread_sem); @@ -718,7 +684,6 @@ VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { }; void VideoStreamTheora::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamTheora::set_file); ClassDB::bind_method(D_METHOD("get_file"), &VideoStreamTheora::get_file); @@ -728,7 +693,6 @@ void VideoStreamTheora::_bind_methods() { //////////// RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { @@ -752,17 +716,14 @@ RES ResourceFormatLoaderTheora::load(const String &p_path, const String &p_origi } void ResourceFormatLoaderTheora::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("ogv"); } bool ResourceFormatLoaderTheora::handles_type(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "VideoStream"); } String ResourceFormatLoaderTheora::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "ogv") return "VideoStreamTheora"; diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h index d5a2640794..f90c2465b4 100644 --- a/modules/theora/video_stream_theora.h +++ b/modules/theora/video_stream_theora.h @@ -45,7 +45,6 @@ //#define THEORA_USE_THREAD_STREAMING class VideoStreamPlaybackTheora : public VideoStreamPlayback { - GDCLASS(VideoStreamPlaybackTheora, VideoStreamPlayback); enum { @@ -161,7 +160,6 @@ public: }; class VideoStreamTheora : public VideoStream { - GDCLASS(VideoStreamTheora, VideoStream); String file; diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp index 1c0f3cd03e..dc34fe3003 100644 --- a/modules/tinyexr/image_loader_tinyexr.cpp +++ b/modules/tinyexr/image_loader_tinyexr.cpp @@ -36,7 +36,6 @@ #include "thirdparty/tinyexr/tinyexr.h" Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { - Vector<uint8_t> src_image; int src_image_len = f->get_len(); ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); @@ -62,7 +61,6 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_f int ret = ParseEXRVersionFromMemory(&exr_version, w, src_image_len); if (ret != TINYEXR_SUCCESS) { - return ERR_FILE_CORRUPT; } @@ -141,12 +139,10 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_f int output_channels = 0; if (idxA != -1) { - imgdata.resize(exr_image.width * exr_image.height * 8); //RGBA16 format = Image::FORMAT_RGBAH; output_channels = 4; } else { - imgdata.resize(exr_image.width * exr_image.height * 6); //RGB16 format = Image::FORMAT_RGBH; output_channels = 3; @@ -185,7 +181,6 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_f // Assume `out_rgba` have enough memory allocated. for (int tile_index = 0; tile_index < num_tiles; tile_index++) { - const EXRTile &tile = exr_tiles[tile_index]; int tw = tile.width; @@ -215,7 +210,6 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_f uint16_t *row_w = first_row_w + (y * exr_image.width * output_channels); for (int x = 0; x < tw; x++) { - Color color(*r_channel++, *g_channel++, *b_channel++); if (p_force_linear) @@ -242,7 +236,6 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_f } void ImageLoaderTinyEXR::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("exr"); } diff --git a/modules/tinyexr/image_loader_tinyexr.h b/modules/tinyexr/image_loader_tinyexr.h index af95989254..ff040b0915 100644 --- a/modules/tinyexr/image_loader_tinyexr.h +++ b/modules/tinyexr/image_loader_tinyexr.h @@ -34,7 +34,6 @@ #include "core/io/image_loader.h" class ImageLoaderTinyEXR : public ImageFormatLoader { - public: virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale); virtual void get_recognized_extensions(List<String> *p_extensions) const; diff --git a/modules/tinyexr/image_saver_tinyexr.cpp b/modules/tinyexr/image_saver_tinyexr.cpp index bc30f4e4fd..420619bd5f 100644 --- a/modules/tinyexr/image_saver_tinyexr.cpp +++ b/modules/tinyexr/image_saver_tinyexr.cpp @@ -140,7 +140,6 @@ static int get_channel_count(Image::Format p_format) { } Error save_exr(const String &p_path, const Ref<Image> &p_img, bool p_grayscale) { - Image::Format format = p_img->get_format(); if (!is_supported_format(format)) { @@ -192,7 +191,6 @@ Error save_exr(const String &p_path, const Ref<Image> &p_img, bool p_grayscale) const uint8_t *src_r = src_data.ptr(); for (int channel_index = 0; channel_index < channel_count; ++channel_index) { - // De-interleave channels PackedByteArray &dst = channels[channel_index]; @@ -201,7 +199,6 @@ Error save_exr(const String &p_path, const Ref<Image> &p_img, bool p_grayscale) uint8_t *dst_w = dst.ptrw(); if (src_pixel_type == SRC_FLOAT && target_pixel_type == TINYEXR_PIXELTYPE_FLOAT) { - // Note: we don't save mipmaps CRASH_COND(src_data.size() < pixel_count * channel_count * target_pixel_type_size); @@ -213,7 +210,6 @@ Error save_exr(const String &p_path, const Ref<Image> &p_img, bool p_grayscale) } } else if (src_pixel_type == SRC_HALF && target_pixel_type == TINYEXR_PIXELTYPE_HALF) { - CRASH_COND(src_data.size() < pixel_count * channel_count * target_pixel_type_size); const uint16_t *src_rp = (uint16_t *)src_r; @@ -224,7 +220,6 @@ Error save_exr(const String &p_path, const Ref<Image> &p_img, bool p_grayscale) } } else if (src_pixel_type == SRC_BYTE && target_pixel_type == TINYEXR_PIXELTYPE_HALF) { - CRASH_COND(src_data.size() < pixel_count * channel_count); const uint8_t *src_rp = (uint8_t *)src_r; diff --git a/modules/tinyexr/register_types.cpp b/modules/tinyexr/register_types.cpp index af05a411e1..9d0fb8729e 100644 --- a/modules/tinyexr/register_types.cpp +++ b/modules/tinyexr/register_types.cpp @@ -36,7 +36,6 @@ static ImageLoaderTinyEXR *image_loader_tinyexr = nullptr; void register_tinyexr_types() { - image_loader_tinyexr = memnew(ImageLoaderTinyEXR); ImageLoader::add_image_format_loader(image_loader_tinyexr); @@ -44,7 +43,6 @@ void register_tinyexr_types() { } void unregister_tinyexr_types() { - memdelete(image_loader_tinyexr); Image::save_exr_func = nullptr; diff --git a/modules/upnp/register_types.cpp b/modules/upnp/register_types.cpp index 270aa2d7e8..34900206de 100644 --- a/modules/upnp/register_types.cpp +++ b/modules/upnp/register_types.cpp @@ -36,7 +36,6 @@ #include "upnp_device.h" void register_upnp_types() { - ClassDB::register_class<UPNP>(); ClassDB::register_class<UPNPDevice>(); } diff --git a/modules/upnp/upnp.h b/modules/upnp/upnp.h index 46f44e04e5..1c4b5549f4 100644 --- a/modules/upnp/upnp.h +++ b/modules/upnp/upnp.h @@ -38,7 +38,6 @@ #include <miniupnpc/miniupnpc.h> class UPNP : public Reference { - GDCLASS(UPNP, Reference); private: diff --git a/modules/upnp/upnp_device.h b/modules/upnp/upnp_device.h index f25d3427fc..4b519fce32 100644 --- a/modules/upnp/upnp_device.h +++ b/modules/upnp/upnp_device.h @@ -34,7 +34,6 @@ #include "core/reference.h" class UPNPDevice : public Reference { - GDCLASS(UPNPDevice, Reference); public: diff --git a/modules/vhacd/register_types.cpp b/modules/vhacd/register_types.cpp index c006a9deec..40c5e47440 100644 --- a/modules/vhacd/register_types.cpp +++ b/modules/vhacd/register_types.cpp @@ -33,7 +33,6 @@ #include "thirdparty/vhacd/public/VHACD.h" static Vector<Vector<Face3>> convex_decompose(const Vector<Face3> &p_faces) { - Vector<float> vertices; vertices.resize(p_faces.size() * 9); Vector<uint32_t> indices; diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 5ea84a32c4..42d0fb37fe 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -47,7 +47,6 @@ static _VisualScriptEditor *vs_editor_singleton = nullptr; #endif void register_visual_script_types() { - visual_script_language = memnew(VisualScriptLanguage); //script_language_gd->init(); ScriptServer::register_language(visual_script_language); @@ -125,7 +124,6 @@ void register_visual_script_types() { } void unregister_visual_script_types() { - unregister_visual_script_nodes(); ScriptServer::unregister_language(visual_script_language); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index fe1d82f977..79516fa1ba 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -44,7 +44,6 @@ void VisualScriptNode::set_breakpoint(bool p_breakpoint) { } bool VisualScriptNode::is_breakpoint() const { - return breakpoint; } @@ -53,7 +52,6 @@ void VisualScriptNode::ports_changed_notify() { } void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_value) { - ERR_FAIL_INDEX(p_port, default_input_values.size()); default_input_values[p_port] = p_value; @@ -66,13 +64,11 @@ void VisualScriptNode::set_default_input_value(int p_port, const Variant &p_valu } Variant VisualScriptNode::get_default_input_value(int p_port) const { - ERR_FAIL_INDEX_V(p_port, default_input_values.size(), Variant()); return default_input_values[p_port]; } void VisualScriptNode::_set_default_input_values(Array p_values) { - default_input_values = p_values; } @@ -81,7 +77,6 @@ void VisualScriptNode::validate_input_default_values() { //actually validate on save for (int i = 0; i < get_input_value_port_count(); i++) { - Variant::Type expected = get_input_value_port_info(i).type; if (expected == Variant::NIL || expected == default_input_values[i].get_type()) { @@ -101,7 +96,6 @@ void VisualScriptNode::validate_input_default_values() { } Array VisualScriptNode::_get_default_input_values() const { - //validate on save, since on load there is little info about this Array values = default_input_values; values.resize(get_input_value_port_count()); @@ -114,7 +108,6 @@ String VisualScriptNode::get_text() const { } void VisualScriptNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_visual_script"), &VisualScriptNode::get_visual_script); ClassDB::bind_method(D_METHOD("set_default_input_value", "port_idx", "value"), &VisualScriptNode::set_default_input_value); ClassDB::bind_method(D_METHOD("get_default_input_value", "port_idx"), &VisualScriptNode::get_default_input_value); @@ -127,7 +120,6 @@ void VisualScriptNode::_bind_methods() { } VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inputs, int p_output) const { - PropertyInfo pinfo = get_output_value_port_info(p_output); TypeGuess tg; @@ -141,7 +133,6 @@ VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inp } Ref<VisualScript> VisualScriptNode::get_visual_script() const { - if (scripts_used.size()) return Ref<VisualScript>(scripts_used.front()->get()); @@ -157,13 +148,11 @@ VisualScriptNode::VisualScriptNode() { ///////////////////// VisualScriptNodeInstance::VisualScriptNodeInstance() { - sequence_outputs = nullptr; input_ports = nullptr; } VisualScriptNodeInstance::~VisualScriptNodeInstance() { - if (sequence_outputs) { memdelete_arr(sequence_outputs); } @@ -178,7 +167,6 @@ VisualScriptNodeInstance::~VisualScriptNodeInstance() { } void VisualScript::add_function(const StringName &p_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(functions.has(p_name)); @@ -188,16 +176,13 @@ void VisualScript::add_function(const StringName &p_name) { } bool VisualScript::has_function(const StringName &p_name) const { - return functions.has(p_name); } void VisualScript::remove_function(const StringName &p_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_name)); for (Map<int, Function::NodeData>::Element *E = functions[p_name].nodes.front(); E; E = E->next()) { - E->get().node->disconnect("ports_changed", callable_mp(this, &VisualScript::_node_ports_changed)); E->get().node->scripts_used.erase(this); } @@ -206,7 +191,6 @@ void VisualScript::remove_function(const StringName &p_name) { } void VisualScript::rename_function(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_name)); if (p_new_name == p_name) @@ -223,19 +207,16 @@ void VisualScript::rename_function(const StringName &p_name, const StringName &p } void VisualScript::set_function_scroll(const StringName &p_name, const Vector2 &p_scroll) { - ERR_FAIL_COND(!functions.has(p_name)); functions[p_name].scroll = p_scroll; } Vector2 VisualScript::get_function_scroll(const StringName &p_name) const { - ERR_FAIL_COND_V(!functions.has(p_name), Vector2()); return functions[p_name].scroll; } void VisualScript::get_function_list(List<StringName> *r_functions) const { - for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { r_functions->push_back(E->key()); } @@ -244,18 +225,15 @@ void VisualScript::get_function_list(List<StringName> *r_functions) const { } int VisualScript::get_function_node_id(const StringName &p_name) const { - ERR_FAIL_COND_V(!functions.has(p_name), -1); return functions[p_name].function_id; } void VisualScript::_node_ports_changed(int p_id) { - StringName function; for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - if (E->get().nodes.has(p_id)) { function = E->key(); break; @@ -276,11 +254,9 @@ void VisualScript::_node_ports_changed(int p_id) { for (Set<SequenceConnection>::Element *E = func.sequence_connections.front(); E; E = E->next()) { if (E->get().from_node == p_id && E->get().from_output >= vsn->get_output_sequence_port_count()) { - to_remove.push_back(E->get()); } if (E->get().to_node == p_id && !vsn->has_input_sequence_port()) { - to_remove.push_back(E->get()); } } @@ -292,7 +268,6 @@ void VisualScript::_node_ports_changed(int p_id) { } { - List<DataConnection> to_remove; for (Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { @@ -317,12 +292,10 @@ void VisualScript::_node_ports_changed(int p_id) { } void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<VisualScriptNode> &p_node, const Point2 &p_pos) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - ERR_FAIL_COND(E->get().nodes.has(p_id)); //id can exist only one in script, even for different functions } @@ -348,7 +321,6 @@ void VisualScript::add_node(const StringName &p_func, int p_id, const Ref<Visual } void VisualScript::remove_node(const StringName &p_func, int p_id) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -370,7 +342,6 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) { } { - List<DataConnection> to_remove; for (Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { @@ -396,7 +367,6 @@ void VisualScript::remove_node(const StringName &p_func, int p_id) { } bool VisualScript::has_node(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -404,7 +374,6 @@ bool VisualScript::has_node(const StringName &p_func, int p_id) const { } Ref<VisualScriptNode> VisualScript::get_node(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), Ref<VisualScriptNode>()); const Function &func = functions[p_func]; @@ -414,7 +383,6 @@ Ref<VisualScriptNode> VisualScript::get_node(const StringName &p_func, int p_id) } void VisualScript::set_node_position(const StringName &p_func, int p_id, const Point2 &p_pos) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -424,7 +392,6 @@ void VisualScript::set_node_position(const StringName &p_func, int p_id, const P } Point2 VisualScript::get_node_position(const StringName &p_func, int p_id) const { - ERR_FAIL_COND_V(!functions.has(p_func), Point2()); const Function &func = functions[p_func]; @@ -433,7 +400,6 @@ Point2 VisualScript::get_node_position(const StringName &p_func, int p_id) const } void VisualScript::get_node_list(const StringName &p_func, List<int> *r_nodes) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -443,7 +409,6 @@ void VisualScript::get_node_list(const StringName &p_func, List<int> *r_nodes) c } void VisualScript::sequence_connect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -458,7 +423,6 @@ void VisualScript::sequence_connect(const StringName &p_func, int p_from_node, i } void VisualScript::sequence_disconnect(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) { - ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -472,7 +436,6 @@ void VisualScript::sequence_disconnect(const StringName &p_func, int p_from_node } bool VisualScript::has_sequence_connection(const StringName &p_func, int p_from_node, int p_from_output, int p_to_node) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -485,7 +448,6 @@ bool VisualScript::has_sequence_connection(const StringName &p_func, int p_from_ } void VisualScript::get_sequence_connection_list(const StringName &p_func, List<SequenceConnection> *r_connection) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -495,7 +457,6 @@ void VisualScript::get_sequence_connection_list(const StringName &p_func, List<S } void VisualScript::data_connect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -512,7 +473,6 @@ void VisualScript::data_connect(const StringName &p_func, int p_from_node, int p } void VisualScript::data_disconnect(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { - ERR_FAIL_COND(!functions.has(p_func)); Function &func = functions[p_func]; @@ -528,7 +488,6 @@ void VisualScript::data_disconnect(const StringName &p_func, int p_from_node, in } bool VisualScript::has_data_connection(const StringName &p_func, int p_from_node, int p_from_port, int p_to_node, int p_to_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -542,7 +501,6 @@ bool VisualScript::has_data_connection(const StringName &p_func, int p_from_node } bool VisualScript::is_input_value_port_connected(const StringName &p_func, int p_node, int p_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -555,7 +513,6 @@ bool VisualScript::is_input_value_port_connected(const StringName &p_func, int p } bool VisualScript::get_input_value_port_connection_source(const StringName &p_func, int p_node, int p_port, int *r_node, int *r_port) const { - ERR_FAIL_COND_V(!functions.has(p_func), false); const Function &func = functions[p_func]; @@ -571,7 +528,6 @@ bool VisualScript::get_input_value_port_connection_source(const StringName &p_fu } void VisualScript::get_data_connection_list(const StringName &p_func, List<DataConnection> *r_connection) const { - ERR_FAIL_COND(!functions.has(p_func)); const Function &func = functions[p_func]; @@ -585,7 +541,6 @@ void VisualScript::set_tool_enabled(bool p_enabled) { } void VisualScript::add_variable(const StringName &p_name, const Variant &p_default_value, bool p_export) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(variables.has(p_name)); @@ -605,12 +560,10 @@ void VisualScript::add_variable(const StringName &p_name, const Variant &p_defau } bool VisualScript::has_variable(const StringName &p_name) const { - return variables.has(p_name); } void VisualScript::remove_variable(const StringName &p_name) { - ERR_FAIL_COND(!variables.has(p_name)); variables.erase(p_name); @@ -620,7 +573,6 @@ void VisualScript::remove_variable(const StringName &p_name) { } void VisualScript::set_variable_default_value(const StringName &p_name, const Variant &p_value) { - ERR_FAIL_COND(!variables.has(p_name)); variables[p_name].default_value = p_value; @@ -630,12 +582,10 @@ void VisualScript::set_variable_default_value(const StringName &p_name, const Va #endif } Variant VisualScript::get_variable_default_value(const StringName &p_name) const { - ERR_FAIL_COND_V(!variables.has(p_name), Variant()); return variables[p_name].default_value; } void VisualScript::set_variable_info(const StringName &p_name, const PropertyInfo &p_info) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!variables.has(p_name)); variables[p_name].info = p_info; @@ -646,13 +596,11 @@ void VisualScript::set_variable_info(const StringName &p_name, const PropertyInf #endif } PropertyInfo VisualScript::get_variable_info(const StringName &p_name) const { - ERR_FAIL_COND_V(!variables.has(p_name), PropertyInfo()); return variables[p_name].info; } void VisualScript::set_variable_export(const StringName &p_name, bool p_export) { - ERR_FAIL_COND(!variables.has(p_name)); variables[p_name]._export = p_export; @@ -662,13 +610,11 @@ void VisualScript::set_variable_export(const StringName &p_name, bool p_export) } bool VisualScript::get_variable_export(const StringName &p_name) const { - ERR_FAIL_COND_V(!variables.has(p_name), false); return variables[p_name]._export; } void VisualScript::_set_variable_info(const StringName &p_name, const Dictionary &p_info) { - PropertyInfo pinfo; if (p_info.has("type")) pinfo.type = Variant::Type(int(p_info["type"])); @@ -685,7 +631,6 @@ void VisualScript::_set_variable_info(const StringName &p_name, const Dictionary } Dictionary VisualScript::_get_variable_info(const StringName &p_name) const { - PropertyInfo pinfo = get_variable_info(p_name); Dictionary d; d["type"] = pinfo.type; @@ -698,7 +643,6 @@ Dictionary VisualScript::_get_variable_info(const StringName &p_name) const { } void VisualScript::get_variable_list(List<StringName> *r_variables) const { - for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { r_variables->push_back(E->key()); } @@ -707,13 +651,11 @@ void VisualScript::get_variable_list(List<StringName> *r_variables) const { } void VisualScript::set_instance_base_type(const StringName &p_type) { - ERR_FAIL_COND(instances.size()); base_type = p_type; } void VisualScript::rename_variable(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!variables.has(p_name)); if (p_new_name == p_name) @@ -750,7 +692,6 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p } void VisualScript::add_custom_signal(const StringName &p_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!String(p_name).is_valid_identifier()); ERR_FAIL_COND(custom_signals.has(p_name)); @@ -759,11 +700,9 @@ void VisualScript::add_custom_signal(const StringName &p_name) { } bool VisualScript::has_custom_signal(const StringName &p_name) const { - return custom_signals.has(p_name); } void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant::Type p_type, const String &p_name, int p_index) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); Argument arg; @@ -775,14 +714,12 @@ void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant: custom_signals[p_func].insert(0, arg); } void VisualScript::custom_signal_set_argument_type(const StringName &p_func, int p_argidx, Variant::Type p_type) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); custom_signals[p_func].write[p_argidx].type = p_type; } Variant::Type VisualScript::custom_signal_get_argument_type(const StringName &p_func, int p_argidx) const { - ERR_FAIL_COND_V(!custom_signals.has(p_func), Variant::NIL); ERR_FAIL_INDEX_V(p_argidx, custom_signals[p_func].size(), Variant::NIL); return custom_signals[p_func][p_argidx].type; @@ -794,13 +731,11 @@ void VisualScript::custom_signal_set_argument_name(const StringName &p_func, int custom_signals[p_func].write[p_argidx].name = p_name; } String VisualScript::custom_signal_get_argument_name(const StringName &p_func, int p_argidx) const { - ERR_FAIL_COND_V(!custom_signals.has(p_func), String()); ERR_FAIL_INDEX_V(p_argidx, custom_signals[p_func].size(), String()); return custom_signals[p_func][p_argidx].name; } void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p_argidx) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); @@ -808,12 +743,10 @@ void VisualScript::custom_signal_remove_argument(const StringName &p_func, int p } int VisualScript::custom_signal_get_argument_count(const StringName &p_func) const { - ERR_FAIL_COND_V(!custom_signals.has(p_func), 0); return custom_signals[p_func].size(); } void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_argidx, int p_with_argidx) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_func)); ERR_FAIL_INDEX(p_argidx, custom_signals[p_func].size()); @@ -822,14 +755,12 @@ void VisualScript::custom_signal_swap_argument(const StringName &p_func, int p_a SWAP(custom_signals[p_func].write[p_argidx], custom_signals[p_func].write[p_with_argidx]); } void VisualScript::remove_custom_signal(const StringName &p_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_name)); custom_signals.erase(p_name); } void VisualScript::rename_custom_signal(const StringName &p_name, const StringName &p_new_name) { - ERR_FAIL_COND(instances.size()); ERR_FAIL_COND(!custom_signals.has(p_name)); if (p_new_name == p_name) @@ -846,7 +777,6 @@ void VisualScript::rename_custom_signal(const StringName &p_name, const StringNa } void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) const { - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { r_custom_signals->push_back(E->key()); } @@ -855,7 +785,6 @@ void VisualScript::get_custom_signal_list(List<StringName> *r_custom_signals) co } int VisualScript::get_available_id() const { - int max_id = 0; for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { if (E->get().nodes.empty()) @@ -871,12 +800,10 @@ int VisualScript::get_available_id() const { ///////////////////////////////// bool VisualScript::can_instance() const { - return true; //ScriptServer::is_scripting_enabled(); } StringName VisualScript::get_instance_base_type() const { - return base_type; } @@ -886,19 +813,16 @@ Ref<Script> VisualScript::get_base_script() const { #ifdef TOOLS_ENABLED void VisualScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { - placeholders.erase(p_placeholder); } void VisualScript::_update_placeholders() { - if (placeholders.size() == 0) return; //no bother if no placeholders List<PropertyInfo> pinfo; Map<StringName, Variant> values; for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - if (!E->get()._export) continue; @@ -909,7 +833,6 @@ void VisualScript::_update_placeholders() { } for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) { - E->get()->update(pinfo, values); } } @@ -917,11 +840,9 @@ void VisualScript::_update_placeholders() { #endif ScriptInstance *VisualScript::instance_create(Object *p_this) { - #ifdef TOOLS_ENABLED if (!ScriptServer::is_scripting_enabled() && !is_tool_script) { - PlaceHolderScriptInstance *sins = memnew(PlaceHolderScriptInstance(VisualScriptLanguage::singleton, Ref<Script>((Script *)this), p_this)); placeholders.insert(sins); @@ -929,7 +850,6 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) { Map<StringName, Variant> values; for (Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - if (!E->get()._export) continue; @@ -958,17 +878,14 @@ ScriptInstance *VisualScript::instance_create(Object *p_this) { } bool VisualScript::instance_has(const Object *p_this) const { - return instances.has((Object *)p_this); } bool VisualScript::has_source_code() const { - return false; } String VisualScript::get_source_code() const { - return String(); } @@ -976,12 +893,10 @@ void VisualScript::set_source_code(const String &p_code) { } Error VisualScript::reload(bool p_keep_state) { - return OK; } bool VisualScript::is_tool() const { - return is_tool_script; } @@ -990,19 +905,15 @@ bool VisualScript::is_valid() const { } ScriptLanguage *VisualScript::get_language() const { - return VisualScriptLanguage::singleton; } bool VisualScript::has_script_signal(const StringName &p_signal) const { - return custom_signals.has(p_signal); } void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const { - for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { - MethodInfo mi; mi.name = E->key(); for (int i = 0; i < E->get().size(); i++) { @@ -1017,7 +928,6 @@ void VisualScript::get_script_signal_list(List<MethodInfo> *r_signals) const { } bool VisualScript::get_property_default_value(const StringName &p_property, Variant &r_value) const { - if (!variables.has(p_property)) return false; @@ -1025,13 +935,10 @@ bool VisualScript::get_property_default_value(const StringName &p_property, Vari return true; } void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const { - for (Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0) { - Ref<VisualScriptFunction> func = E->get().nodes[E->get().function_id].node; if (func.is_valid()) { for (int i = 0; i < func->get_argument_count(); i++) { @@ -1048,11 +955,9 @@ void VisualScript::get_script_method_list(List<MethodInfo> *p_list) const { } bool VisualScript::has_method(const StringName &p_method) const { - return functions.has(p_method); } MethodInfo VisualScript::get_method_info(const StringName &p_method) const { - const Map<StringName, Function>::Element *E = functions.find(p_method); if (!E) return MethodInfo(); @@ -1060,10 +965,8 @@ MethodInfo VisualScript::get_method_info(const StringName &p_method) const { MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0) { - Ref<VisualScriptFunction> func = E->get().nodes[E->get().function_id].node; if (func.is_valid()) { - for (int i = 0; i < func->get_argument_count(); i++) { PropertyInfo arg; arg.name = func->get_argument_name(i); @@ -1081,7 +984,6 @@ MethodInfo VisualScript::get_method_info(const StringName &p_method) const { } void VisualScript::get_script_property_list(List<PropertyInfo> *p_list) const { - List<StringName> vars; get_variable_list(&vars); @@ -1108,9 +1010,7 @@ int VisualScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED bool VisualScript::are_subnodes_edited() const { - for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - for (const Map<int, Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { if (F->get().node->is_edited()) { return true; @@ -1177,7 +1077,6 @@ MultiplayerAPI::RPCMode VisualScript::get_rset_mode(const StringName &p_variable } void VisualScript::_set_data(const Dictionary &p_data) { - Dictionary d = p_data; if (d.has("base_type")) base_type = d["base_type"]; @@ -1185,7 +1084,6 @@ void VisualScript::_set_data(const Dictionary &p_data) { variables.clear(); Array vars = d["variables"]; for (int i = 0; i < vars.size(); i++) { - Dictionary v = vars[i]; StringName name = v["name"]; add_variable(name); @@ -1197,7 +1095,6 @@ void VisualScript::_set_data(const Dictionary &p_data) { custom_signals.clear(); Array sigs = d["signals"]; for (int i = 0; i < sigs.size(); i++) { - Dictionary cs = sigs[i]; add_custom_signal(cs["name"]); @@ -1214,7 +1111,6 @@ void VisualScript::_set_data(const Dictionary &p_data) { Vector2 last_size = Vector2(0.0, 0.0); for (int i = 0; i < funcs.size(); i++) { - Dictionary func = funcs[i]; StringName name = func["name"]; @@ -1264,14 +1160,12 @@ void VisualScript::_set_data(const Dictionary &p_data) { Array sequence_connections = func["sequence_connections"]; for (int j = 0; j < sequence_connections.size(); j += 3) { - sequence_connect(name, sequence_connections[j + 0], sequence_connections[j + 1], sequence_connections[j + 2]); } Array data_connections = func["data_connections"]; for (int j = 0; j < data_connections.size(); j += 4) { - data_connect(name, data_connections[j + 0], data_connections[j + 1], data_connections[j + 2], data_connections[j + 3]); } } @@ -1307,12 +1201,10 @@ void VisualScript::_set_data(const Dictionary &p_data) { } Dictionary VisualScript::_get_data() const { - Dictionary d; d["base_type"] = base_type; Array vars; for (const Map<StringName, Variable>::Element *E = variables.front(); E; E = E->next()) { - Dictionary var = _get_variable_info(E->key()); var["name"] = E->key(); //make sure it's the right one var["default_value"] = E->get().default_value; @@ -1323,7 +1215,6 @@ Dictionary VisualScript::_get_data() const { Array sigs; for (const Map<StringName, Vector<Argument>>::Element *E = custom_signals.front(); E; E = E->next()) { - Dictionary cs; cs["name"] = E->key(); Array args; @@ -1341,7 +1232,6 @@ Dictionary VisualScript::_get_data() const { Array funcs; for (const Map<StringName, Function>::Element *E = functions.front(); E; E = E->next()) { - Dictionary func; func["name"] = E->key(); func["function_id"] = E->get().function_id; @@ -1350,7 +1240,6 @@ Dictionary VisualScript::_get_data() const { Array nodes; for (const Map<int, Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - nodes.push_back(F->key()); nodes.push_back(F->get().pos); nodes.push_back(F->get().node); @@ -1361,7 +1250,6 @@ Dictionary VisualScript::_get_data() const { Array sequence_connections; for (const Set<SequenceConnection>::Element *F = E->get().sequence_connections.front(); F; F = F->next()) { - sequence_connections.push_back(F->get().from_node); sequence_connections.push_back(F->get().from_output); sequence_connections.push_back(F->get().to_node); @@ -1372,7 +1260,6 @@ Dictionary VisualScript::_get_data() const { Array data_connections; for (const Set<DataConnection>::Element *F = E->get().data_connections.front(); F; F = F->next()) { - data_connections.push_back(F->get().from_node); data_connections.push_back(F->get().from_port); data_connections.push_back(F->get().to_node); @@ -1392,7 +1279,6 @@ Dictionary VisualScript::_get_data() const { } void VisualScript::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_function", "name"), &VisualScript::add_function); ClassDB::bind_method(D_METHOD("has_function", "name"), &VisualScript::has_function); ClassDB::bind_method(D_METHOD("remove_function", "name"), &VisualScript::remove_function); @@ -1455,7 +1341,6 @@ void VisualScript::_bind_methods() { } VisualScript::VisualScript() { - base_type = "Object"; is_tool_script = false; } @@ -1482,7 +1367,6 @@ Set<int> VisualScript::get_output_sequence_ports_connected(const String &edited_ } VisualScript::~VisualScript() { - while (!functions.empty()) { remove_function(functions.front()->key()); } @@ -1491,7 +1375,6 @@ VisualScript::~VisualScript() { //////////////////////////////////////////// bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) { - Map<StringName, Variant>::Element *E = variables.find(p_name); if (!E) return false; @@ -1502,7 +1385,6 @@ bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) } bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const { - const Map<StringName, Variant>::Element *E = variables.find(p_name); if (!E) return false; @@ -1511,9 +1393,7 @@ bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const { return true; } void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { - for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) { - if (!E->get()._export) continue; PropertyInfo p = E->get().info; @@ -1523,7 +1403,6 @@ void VisualScriptInstance::get_property_list(List<PropertyInfo> *p_properties) c } } Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { - const Map<StringName, VisualScript::Variable>::Element *E = script->variables.find(p_name); if (!E) { if (r_is_valid) @@ -1538,9 +1417,7 @@ Variant::Type VisualScriptInstance::get_property_type(const StringName &p_name, } void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { - for (const Map<StringName, VisualScript::Function>::Element *E = script->functions.front(); E; E = E->next()) { - if (E->key() == script->get_default_func()) { continue; } @@ -1548,10 +1425,8 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { MethodInfo mi; mi.name = E->key(); if (E->get().function_id >= 0 && E->get().nodes.has(E->get().function_id)) { - Ref<VisualScriptFunction> vsf = E->get().nodes[E->get().function_id].node; if (vsf.is_valid()) { - for (int i = 0; i < vsf->get_argument_count(); i++) { PropertyInfo arg; arg.name = vsf->get_argument_name(i); @@ -1570,7 +1445,6 @@ void VisualScriptInstance::get_method_list(List<MethodInfo> *p_list) const { } } bool VisualScriptInstance::has_method(const StringName &p_method) const { - if (p_method == script->get_default_func()) return false; @@ -1581,7 +1455,6 @@ bool VisualScriptInstance::has_method(const StringName &p_method) const { #define VSDEBUG(m_text) void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int p_pass, int *pass_stack, const Variant **input_args, Variant **output_args, Variant *variant_stack, Callable::CallError &r_error, String &error_str, VisualScriptNodeInstance **r_error_node) { - ERR_FAIL_COND(node->pass_idx == -1); if (pass_stack[node->pass_idx] == p_pass) @@ -1590,12 +1463,10 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int pass_stack[node->pass_idx] = p_pass; if (!node->dependencies.empty()) { - int dc = node->dependencies.size(); VisualScriptNodeInstance **deps = node->dependencies.ptrw(); for (int i = 0; i < dc; i++) { - _dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, r_error_node); if (r_error.error != Callable::CallError::CALL_OK) return; @@ -1603,7 +1474,6 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int } for (int i = 0; i < node->input_port_count; i++) { - int index = node->input_ports[i] & VisualScriptNodeInstance::INPUT_MASK; if (node->input_ports[i] & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) { @@ -1628,7 +1498,6 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int } Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p_stack, int p_stack_size, VisualScriptNodeInstance *p_node, int p_flow_stack_pos, int p_pass, bool p_resuming_yield, Callable::CallError &r_error) { - Map<StringName, Function>::Element *F = functions.find(p_method); ERR_FAIL_COND_V(!F, Variant()); Function *f = &F->get(); @@ -1659,7 +1528,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p #endif while (true) { - p_pass++; //increment pass current_node_id = node->get_id(); @@ -1678,16 +1546,13 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p input_args[i] = &variant_stack[i]; } } else { - //run dependencies first if (!node->dependencies.empty()) { - int dc = node->dependencies.size(); VisualScriptNodeInstance **deps = node->dependencies.ptrw(); for (int i = 0; i < dc; i++) { - _dependency_step(deps[i], p_pass, pass_stack, input_args, output_args, variant_stack, r_error, error_str, &node); if (r_error.error != Callable::CallError::CALL_OK) { error = true; @@ -1698,12 +1563,10 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } if (!error) { - //setup input pointers normally VSDEBUG("INPUT PORTS: " + itos(node->input_port_count)); for (int i = 0; i < node->input_port_count; i++) { - int index = node->input_ports[i] & VisualScriptNodeInstance::INPUT_MASK; if (node->input_ports[i] & VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT) { @@ -1766,7 +1629,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } else { Ref<VisualScriptFunctionState> state = *working_mem; if (!state.is_valid()) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; error_str = RTR("Node yielded, but did not return a function state in the first working memory."); error = true; @@ -1805,7 +1667,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool do_break = false; if (EngineDebugger::get_script_debugger()->get_lines_left() > 0) { - if (EngineDebugger::get_script_debugger()->get_depth() <= 0) EngineDebugger::get_script_debugger()->set_lines_left(EngineDebugger::get_script_debugger()->get_lines_left() - 1); if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) @@ -1828,7 +1689,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p if (ret & VisualScriptNodeInstance::STEP_EXIT_FUNCTION_BIT) { if (node->get_working_memory_size() == 0) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; error_str = RTR("Return value must be assigned to first element of node working memory! Fix your node please."); error = true; @@ -1861,13 +1721,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } if (flow_stack) { - //update flow stack pos (may have changed) flow_stack[flow_stack_pos] = current_node_id; //add stack push bit if requested if (ret & VisualScriptNodeInstance::STEP_FLAG_PUSH_STACK_BIT) { - flow_stack[flow_stack_pos] |= VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT; sequence_bits[node->sequence_index] = true; //remember sequence bit VSDEBUG("NEXT SEQ - FLAG BIT"); @@ -1888,7 +1746,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p break; //simply exit without value or error } } else if (next) { - if (sequence_bits[next->sequence_index]) { // what happened here is that we are entering a node that is in the middle of doing a sequence (pushed stack) from the front // because each node has a working memory, we can't really do a sub-sequence @@ -1898,7 +1755,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool found = false; for (int i = flow_stack_pos; i >= 0; i--) { - if ((flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK) == next->get_id()) { flow_stack_pos = i; //roll back and remove bit flow_stack[i] = next->get_id(); @@ -1940,10 +1796,8 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p bool found = false; for (int i = flow_stack_pos; i >= 0; i--) { - VSDEBUG("FS " + itos(i) + " - " + itos(flow_stack[i])); if (flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_PUSHED_BIT) { - node = instances[flow_stack[i] & VisualScriptNodeInstance::FLOW_STACK_MASK]; flow_stack_pos = i; found = true; @@ -1959,13 +1813,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p VSDEBUG("NO NEXT NODE, GO BACK TO: " + itos(flow_stack_pos)); } } else { - node = next; //stackless mode, simply assign next node } } if (error) { - //error // function, file, line, error, explanation String err_file = script->get_path(); @@ -1973,7 +1825,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p int err_line = current_node_id; //not a line but it works as one if (node && (r_error.error != Callable::CallError::CALL_ERROR_INVALID_METHOD || error_str == String())) { - if (error_str != String()) { error_str += " "; } @@ -1996,13 +1847,11 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p // debugger break did not happen if (!VisualScriptLanguage::singleton->debug_break(error_str, false)) { - _err_print_error(err_func.utf8().get_data(), err_file.utf8().get_data(), err_line, error_str.utf8().get_data(), ERR_HANDLER_SCRIPT); } //} } else { - //return_value= } @@ -2021,7 +1870,6 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - r_error.error = Callable::CallError::CALL_OK; //ok by default Map<StringName, Function>::Element *F = functions.find(p_method); @@ -2109,7 +1957,6 @@ Variant VisualScriptInstance::call(const StringName &p_method, const Variant **p } void VisualScriptInstance::notification(int p_notification) { - //do nothing as this is called using virtual Variant what = p_notification; @@ -2139,7 +1986,6 @@ String VisualScriptInstance::to_string(bool *r_valid) { } Ref<Script> VisualScriptInstance::get_script() const { - return script; } @@ -2184,7 +2030,6 @@ MultiplayerAPI::RPCMode VisualScriptInstance::get_rset_mode(const StringName &p_ } void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_owner) { - script = p_script; owner = p_owner; source = p_script->get_path(); @@ -2212,7 +2057,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o } for (const Map<StringName, VisualScript::Function>::Element *E = script->functions.front(); E; E = E->next()) { - if (E->key() == script->get_default_func()) { continue; } @@ -2251,7 +2095,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //first create the nodes for (const Map<int, VisualScript::Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - Ref<VisualScriptNode> node = F->get().node; VisualScriptNodeInstance *instance = node->instance(this); //create instance @@ -2272,7 +2115,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o if (instance->input_port_count) { instance->input_ports = memnew_arr(int, instance->input_port_count); for (int i = 0; i < instance->input_port_count; i++) { - instance->input_ports[i] = -1; //if not assigned, will become default value } } @@ -2327,7 +2169,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //second pass, do data connections for (const Set<VisualScript::DataConnection>::Element *F = E->get().data_connections.front(); F; F = F->next()) { - VisualScript::DataConnection dc = F->get(); ERR_CONTINUE(!instances.has(dc.from_node)); VisualScriptNodeInstance *from = instances[dc.from_node]; @@ -2337,7 +2178,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o ERR_CONTINUE(dc.to_port >= to->input_port_count); if (from->output_ports[dc.from_port] == -1) { - int stack_pos = function.max_stack++; from->output_ports[dc.from_port] = stack_pos; } @@ -2357,7 +2197,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o //third pass, do sequence connections for (const Set<VisualScript::SequenceConnection>::Element *F = E->get().sequence_connections.front(); F; F = F->next()) { - VisualScript::SequenceConnection sc = F->get(); ERR_CONTINUE(!instances.has(sc.from_node)); VisualScriptNodeInstance *from = instances[sc.from_node]; @@ -2373,7 +2212,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o // 2) connect unassigned output ports to trash for (const Map<int, VisualScript::Function::NodeData>::Element *F = E->get().nodes.front(); F; F = F->next()) { - ERR_CONTINUE(!instances.has(F->key())); Ref<VisualScriptNode> node = F->get().node; @@ -2382,7 +2220,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o // connect to default values for (int i = 0; i < instance->input_port_count; i++) { if (instance->input_ports[i] == -1) { - //unassigned, connect to default val instance->input_ports[i] = default_values.size() | VisualScriptNodeInstance::INPUT_DEFAULT_VALUE_BIT; default_values.push_back(node->get_default_input_value(i)); @@ -2402,7 +2239,6 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o } ScriptLanguage *VisualScriptInstance::get_language() { - return VisualScriptLanguage::singleton; } @@ -2410,7 +2246,6 @@ VisualScriptInstance::VisualScriptInstance() { } VisualScriptInstance::~VisualScriptInstance() { - { MutexLock lock(VisualScriptLanguage::singleton->lock); @@ -2427,7 +2262,6 @@ VisualScriptInstance::~VisualScriptInstance() { ///////////////////// Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { - ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED @@ -2448,7 +2282,6 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int } else if (p_argcount == 1) { //noooneee, reserved for me, me and only me. } else { - for (int i = 0; i < p_argcount - 1; i++) { args.push_back(*p_args[i]); } @@ -2475,7 +2308,6 @@ Variant VisualScriptFunctionState::_signal_callback(const Variant **p_args, int } void VisualScriptFunctionState::connect_to_signal(Object *p_obj, const String &p_signal, Array p_binds) { - Vector<Variant> binds; for (int i = 0; i < p_binds.size(); i++) { binds.push_back(p_binds[i]); @@ -2485,12 +2317,10 @@ void VisualScriptFunctionState::connect_to_signal(Object *p_obj, const String &p } bool VisualScriptFunctionState::is_valid() const { - return function != StringName(); } Variant VisualScriptFunctionState::resume(Array p_args) { - ERR_FAIL_COND_V(function == StringName(), Variant()); #ifdef DEBUG_ENABLED @@ -2512,7 +2342,6 @@ Variant VisualScriptFunctionState::resume(Array p_args) { } void VisualScriptFunctionState::_bind_methods() { - ClassDB::bind_method(D_METHOD("connect_to_signal", "obj", "signals", "args"), &VisualScriptFunctionState::connect_to_signal); ClassDB::bind_method(D_METHOD("resume", "args"), &VisualScriptFunctionState::resume, DEFVAL(Variant())); ClassDB::bind_method(D_METHOD("is_valid"), &VisualScriptFunctionState::is_valid); @@ -2523,7 +2352,6 @@ VisualScriptFunctionState::VisualScriptFunctionState() { } VisualScriptFunctionState::~VisualScriptFunctionState() { - if (function != StringName()) { Variant *s = ((Variant *)stack.ptr()); for (int i = 0; i < variant_stack_size; i++) { @@ -2535,7 +2363,6 @@ VisualScriptFunctionState::~VisualScriptFunctionState() { /////////////////////////////////////////////// String VisualScriptLanguage::get_name() const { - return "VisualScript"; } @@ -2543,15 +2370,12 @@ String VisualScriptLanguage::get_name() const { void VisualScriptLanguage::init() { } String VisualScriptLanguage::get_type() const { - return "VisualScript"; } String VisualScriptLanguage::get_extension() const { - return "vs"; } Error VisualScriptLanguage::execute_file(const String &p_path) { - return OK; } void VisualScriptLanguage::finish() { @@ -2565,7 +2389,6 @@ void VisualScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) co void VisualScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { } Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { - Ref<VisualScript> script; script.instance(); script->set_instance_base_type(p_base_class_name); @@ -2573,7 +2396,6 @@ Ref<Script> VisualScriptLanguage::get_template(const String &p_class_name, const } bool VisualScriptLanguage::is_using_templates() { - return true; } @@ -2583,27 +2405,21 @@ void VisualScriptLanguage::make_template(const String &p_class_name, const Strin } bool VisualScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings, Set<int> *r_safe_lines) const { - return false; } Script *VisualScriptLanguage::create_script() const { - return memnew(VisualScript); } bool VisualScriptLanguage::has_named_classes() const { - return false; } bool VisualScriptLanguage::supports_builtin_mode() const { - return true; } int VisualScriptLanguage::find_function(const String &p_function, const String &p_code) const { - return -1; } String VisualScriptLanguage::make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const { - return String(); } @@ -2618,7 +2434,6 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c //break because of parse error if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { - _debug_parse_err_node = p_node; _debug_parse_err_file = p_file; _debug_error = p_error; @@ -2630,9 +2445,7 @@ bool VisualScriptLanguage::debug_break_parse(const String &p_file, int p_node, c } bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_continue) { - if (EngineDebugger::is_active() && Thread::get_caller_id() == Thread::get_main_id()) { - _debug_parse_err_node = -1; _debug_parse_err_file = ""; _debug_error = p_error; @@ -2644,19 +2457,16 @@ bool VisualScriptLanguage::debug_break(const String &p_error, bool p_allow_conti } String VisualScriptLanguage::debug_get_error() const { - return _debug_error; } int VisualScriptLanguage::debug_get_stack_level_count() const { - if (_debug_parse_err_node >= 0) return 1; return _debug_call_stack_pos; } int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { - if (_debug_parse_err_node >= 0) return _debug_parse_err_node; @@ -2667,7 +2477,6 @@ int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { return *(_call_stack[l].current_id); } String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_node >= 0) return ""; @@ -2676,7 +2485,6 @@ String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { return *_call_stack[l].function; } String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_node >= 0) return _debug_parse_err_file; @@ -2685,7 +2493,6 @@ String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { return _call_stack[l].instance->get_script_ptr()->get_path(); } void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_node >= 0) return; @@ -2724,7 +2531,6 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String } for (int i = 0; i < node->output_port_count; i++) { - String name = node->get_base_node()->get_output_value_port_info(i).name; if (name == String()) { name = "out_" + itos(i); @@ -2760,7 +2566,6 @@ void VisualScriptLanguage::debug_get_stack_level_locals(int p_level, List<String */ } void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - if (_debug_parse_err_node >= 0) return; @@ -2783,11 +2588,9 @@ void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List<Strin } void VisualScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - //no globals are really reachable in gdscript } String VisualScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { - return ""; } @@ -2798,7 +2601,6 @@ void VisualScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool /* LOADER FUNCTIONS */ void VisualScriptLanguage::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("vs"); } void VisualScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { @@ -2812,19 +2614,16 @@ void VisualScriptLanguage::profiling_stop() { } int VisualScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { - return 0; } int VisualScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { - return 0; } VisualScriptLanguage *VisualScriptLanguage::singleton = nullptr; void VisualScriptLanguage::add_register_func(const String &p_name, VisualScriptNodeRegisterFunc p_func) { - ERR_FAIL_COND(register_funcs.has(p_name)); register_funcs[p_name] = p_func; } @@ -2835,21 +2634,18 @@ void VisualScriptLanguage::remove_register_func(const String &p_name) { } Ref<VisualScriptNode> VisualScriptLanguage::create_node_from_name(const String &p_name) { - ERR_FAIL_COND_V(!register_funcs.has(p_name), Ref<VisualScriptNode>()); return register_funcs[p_name](p_name); } void VisualScriptLanguage::get_registered_node_names(List<String> *r_names) { - for (Map<String, VisualScriptNodeRegisterFunc>::Element *E = register_funcs.front(); E; E = E->next()) { r_names->push_back(E->key()); } } VisualScriptLanguage::VisualScriptLanguage() { - notification = "_notification"; _step = "_step"; _subcall = "_subcall"; @@ -2873,7 +2669,6 @@ VisualScriptLanguage::VisualScriptLanguage() { } VisualScriptLanguage::~VisualScriptLanguage() { - if (_call_stack) { memdelete_arr(_call_stack); } diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index c154e56703..d47f7f2a4b 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -89,7 +89,6 @@ public: virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) = 0; struct TypeGuess { - Variant::Type type; StringName gdclass; Ref<Script> script; @@ -166,16 +165,13 @@ public: }; class VisualScript : public Script { - GDCLASS(VisualScript, Script); RES_BASE_EXTENSION("vs"); public: struct SequenceConnection { - union { - struct { uint64_t from_node : 24; uint64_t from_output : 16; @@ -185,15 +181,12 @@ public: }; bool operator<(const SequenceConnection &p_connection) const { - return id < p_connection.id; } }; struct DataConnection { - union { - struct { uint64_t from_node : 24; uint64_t from_port : 8; @@ -204,7 +197,6 @@ public: }; bool operator<(const DataConnection &p_connection) const { - return id < p_connection.id; } }; @@ -431,7 +423,6 @@ public: String to_string(bool *r_valid); bool set_variable(const StringName &p_variable, const Variant &p_value) { - Map<StringName, Variant>::Element *E = variables.find(p_variable); if (!E) return false; @@ -441,7 +432,6 @@ public: } bool get_variable(const StringName &p_variable, Variant *r_variable) const { - const Map<StringName, Variant>::Element *E = variables.find(p_variable); if (!E) return false; @@ -476,7 +466,6 @@ public: }; class VisualScriptFunctionState : public Reference { - GDCLASS(VisualScriptFunctionState, Reference); friend class VisualScriptInstance; @@ -507,11 +496,9 @@ public: typedef Ref<VisualScriptNode> (*VisualScriptNodeRegisterFunc)(const String &p_type); class VisualScriptLanguage : public ScriptLanguage { - Map<String, VisualScriptNodeRegisterFunc> register_funcs; struct CallLevel { - Variant *stack; Variant **work_mem; const StringName *function; @@ -540,7 +527,6 @@ public: bool debug_break_parse(const String &p_file, int p_node, const String &p_error); _FORCE_INLINE_ void enter_function(VisualScriptInstance *p_instance, const StringName *p_function, Variant *p_stack, Variant **p_work_mem, int *current_id) { - if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now @@ -563,7 +549,6 @@ public: } _FORCE_INLINE_ void exit_function() { - if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now @@ -571,7 +556,6 @@ public: EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1); if (_debug_call_stack_pos == 0) { - _debug_error = "Stack Underflow (Engine Bug)"; EngineDebugger::get_script_debugger()->debug(this); return; @@ -645,7 +629,6 @@ public: //aid for registering template <class T> static Ref<VisualScriptNode> create_node_generic(const String &p_name) { - Ref<T> node; node.instance(); return node; diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index bb291b1cb6..d4218318d3 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -110,7 +110,6 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX }; VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String &p_string) { - for (int i = 0; i < FUNC_MAX; i++) { if (p_string == func_name[i]) return BuiltinFunc(i); @@ -120,20 +119,16 @@ VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(cons } String VisualScriptBuiltinFunc::get_func_name(BuiltinFunc p_func) { - ERR_FAIL_INDEX_V(p_func, FUNC_MAX, String()); return func_name[p_func]; } int VisualScriptBuiltinFunc::get_output_sequence_port_count() const { - return has_input_sequence_port() ? 1 : 0; } bool VisualScriptBuiltinFunc::has_input_sequence_port() const { - switch (func) { - case MATH_RANDOMIZE: case TEXT_PRINT: case TEXT_PRINTERR: @@ -145,9 +140,7 @@ bool VisualScriptBuiltinFunc::has_input_sequence_port() const { } int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { - switch (p_func) { - case MATH_RANDOMIZE: case MATH_RAND: case MATH_RANDF: @@ -228,11 +221,9 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { } int VisualScriptBuiltinFunc::get_input_value_port_count() const { - return get_func_argument_count(func); } int VisualScriptBuiltinFunc::get_output_value_port_count() const { - switch (func) { case MATH_RANDOMIZE: case TEXT_PRINT: @@ -250,14 +241,11 @@ int VisualScriptBuiltinFunc::get_output_value_port_count() const { } String VisualScriptBuiltinFunc::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const { - switch (func) { - case MATH_SIN: case MATH_COS: case MATH_TAN: @@ -363,7 +351,6 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const case MATH_RANDOMIZE: case MATH_RAND: case MATH_RANDF: { - } break; case MATH_RANDOM: { if (p_idx == 0) @@ -453,7 +440,6 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::NIL, "value"); } break; case STR_TO_VAR: { - return PropertyInfo(Variant::STRING, "string"); } break; case VAR_TO_STR: @@ -465,7 +451,6 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const } break; case BYTES_TO_VAR: { - if (p_idx == 0) return PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytes"); else @@ -485,10 +470,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) const { - Variant::Type t = Variant::NIL; switch (func) { - case MATH_SIN: case MATH_COS: case MATH_TAN: @@ -545,10 +528,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons } break; case MATH_RANDOMIZE: { - } break; case MATH_RAND: { - t = Variant::INT; } break; case MATH_RANDF: @@ -556,10 +537,8 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons t = Variant::FLOAT; } break; case MATH_SEED: { - } break; case MATH_RANDSEED: { - if (p_idx == 0) return PropertyInfo(Variant::INT, "rnd"); else @@ -582,24 +561,20 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case LOGIC_MAX: case LOGIC_MIN: case LOGIC_CLAMP: { - } break; case LOGIC_NEAREST_PO2: { t = Variant::NIL; } break; case OBJ_WEAKREF: { - t = Variant::OBJECT; } break; case FUNC_FUNCREF: { - t = Variant::OBJECT; } break; case TYPE_CONVERT: { - } break; case TEXT_ORD: case TYPE_OF: { @@ -607,30 +582,24 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons } break; case TYPE_EXISTS: { - t = Variant::BOOL; } break; case TEXT_CHAR: case TEXT_STR: { - t = Variant::STRING; } break; case TEXT_PRINT: { - } break; case TEXT_PRINTERR: { - } break; case TEXT_PRINTRAW: { - } break; case VAR_TO_STR: { t = Variant::STRING; } break; case STR_TO_VAR: { - } break; case VAR_TO_BYTES: { if (p_idx == 0) @@ -661,12 +630,10 @@ String VisualScriptBuiltinFunc::get_caption() const { */ String VisualScriptBuiltinFunc::get_caption() const { - return func_name[func]; } void VisualScriptBuiltinFunc::set_func(BuiltinFunc p_which) { - ERR_FAIL_INDEX(p_which, FUNC_MAX); func = p_which; _change_notify(); @@ -686,197 +653,159 @@ VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::get_func() { } void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant *r_return, Callable::CallError &r_error, String &r_error_str) { - switch (p_func) { case VisualScriptBuiltinFunc::MATH_SIN: { - VALIDATE_ARG_NUM(0); *r_return = Math::sin((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_COS: { - VALIDATE_ARG_NUM(0); *r_return = Math::cos((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_TAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::tan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_SINH: { - VALIDATE_ARG_NUM(0); *r_return = Math::sinh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_COSH: { - VALIDATE_ARG_NUM(0); *r_return = Math::cosh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_TANH: { - VALIDATE_ARG_NUM(0); *r_return = Math::tanh((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ASIN: { - VALIDATE_ARG_NUM(0); *r_return = Math::asin((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ACOS: { - VALIDATE_ARG_NUM(0); *r_return = Math::acos((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ATAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::atan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ATAN2: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::atan2((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_SQRT: { - VALIDATE_ARG_NUM(0); *r_return = Math::sqrt((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_FMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::fmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_FPOSMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::fposmod((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_POSMOD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::posmod((int)*p_inputs[0], (int)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_FLOOR: { - VALIDATE_ARG_NUM(0); *r_return = Math::floor((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_CEIL: { - VALIDATE_ARG_NUM(0); *r_return = Math::ceil((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ROUND: { - VALIDATE_ARG_NUM(0); *r_return = Math::round((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ABS: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; *r_return = ABS(i); } else if (p_inputs[0]->get_type() == Variant::FLOAT) { - real_t r = *p_inputs[0]; *r_return = Math::abs(r); } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::FLOAT; } } break; case VisualScriptBuiltinFunc::MATH_SIGN: { - if (p_inputs[0]->get_type() == Variant::INT) { - int64_t i = *p_inputs[0]; *r_return = i < 0 ? -1 : (i > 0 ? +1 : 0); } else if (p_inputs[0]->get_type() == Variant::FLOAT) { - real_t r = *p_inputs[0]; *r_return = r < 0.0 ? -1.0 : (r > 0.0 ? +1.0 : 0.0); } else { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::FLOAT; } } break; case VisualScriptBuiltinFunc::MATH_POW: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::pow((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_LOG: { - VALIDATE_ARG_NUM(0); *r_return = Math::log((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_EXP: { - VALIDATE_ARG_NUM(0); *r_return = Math::exp((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ISNAN: { - VALIDATE_ARG_NUM(0); *r_return = Math::is_nan((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_ISINF: { - VALIDATE_ARG_NUM(0); *r_return = Math::is_inf((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_EASE: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::ease((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_STEP_DECIMALS: { - VALIDATE_ARG_NUM(0); *r_return = Math::step_decimals((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_STEPIFY: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::stepify((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_LERP_ANGLE: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::lerp_angle((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_INVERSE_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::inverse_lerp((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_RANGE_LERP: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -891,14 +820,12 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = Math::smoothstep((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_MOVE_TOWARD: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); *r_return = Math::move_toward((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::MATH_DECTIME: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); VALIDATE_ARG_NUM(2); @@ -915,20 +842,17 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = Math::randf(); } break; case VisualScriptBuiltinFunc::MATH_RANDOM: { - VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); *r_return = Math::random((double)*p_inputs[0], (double)*p_inputs[1]); } break; case VisualScriptBuiltinFunc::MATH_SEED: { - VALIDATE_ARG_NUM(0); uint64_t seed = *p_inputs[0]; Math::seed(seed); } break; case VisualScriptBuiltinFunc::MATH_RANDSEED: { - VALIDATE_ARG_NUM(0); uint64_t seed = *p_inputs[0]; int ret = Math::rand_from_seed(&seed); @@ -939,22 +863,18 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::MATH_DEG2RAD: { - VALIDATE_ARG_NUM(0); *r_return = Math::deg2rad((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_RAD2DEG: { - VALIDATE_ARG_NUM(0); *r_return = Math::rad2deg((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_LINEAR2DB: { - VALIDATE_ARG_NUM(0); *r_return = Math::linear2db((double)*p_inputs[0]); } break; case VisualScriptBuiltinFunc::MATH_DB2LINEAR: { - VALIDATE_ARG_NUM(0); *r_return = Math::db2linear((double)*p_inputs[0]); } break; @@ -985,9 +905,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = Math::wrapf((double)*p_inputs[0], (double)*p_inputs[1], (double)*p_inputs[2]); } break; case VisualScriptBuiltinFunc::LOGIC_MAX: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; *r_return = MAX(a, b); @@ -1003,9 +921,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::LOGIC_MIN: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; *r_return = MIN(a, b); @@ -1020,9 +936,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } } break; case VisualScriptBuiltinFunc::LOGIC_CLAMP: { - if (p_inputs[0]->get_type() == Variant::INT && p_inputs[1]->get_type() == Variant::INT && p_inputs[2]->get_type() == Variant::INT) { - int64_t a = *p_inputs[0]; int64_t b = *p_inputs[1]; int64_t c = *p_inputs[2]; @@ -1040,15 +954,12 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } } break; case VisualScriptBuiltinFunc::LOGIC_NEAREST_PO2: { - VALIDATE_ARG_NUM(0); int64_t num = *p_inputs[0]; *r_return = next_power_of_2(num); } break; case VisualScriptBuiltinFunc::OBJ_WEAKREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -1057,10 +968,8 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } if (p_inputs[0]->is_ref()) { - REF r = *p_inputs[0]; if (!r.is_valid()) { - return; } @@ -1070,7 +979,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } else { Object *obj = *p_inputs[0]; if (!obj) { - return; } Ref<WeakRef> wref = memnew(WeakRef); @@ -1080,9 +988,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::FUNC_FUNCREF: { - if (p_inputs[0]->get_type() != Variant::OBJECT) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; r_error.expected = Variant::OBJECT; @@ -1090,7 +996,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in return; } if (p_inputs[1]->get_type() != Variant::STRING && p_inputs[1]->get_type() != Variant::NODE_PATH) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; r_error.expected = Variant::STRING; @@ -1107,11 +1012,9 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::TYPE_CONVERT: { - VALIDATE_ARG_NUM(1); int type = *p_inputs[1]; if (type < 0 || type >= Variant::VARIANT_MAX) { - r_error_str = RTR("Invalid type argument to convert(), use TYPE_* constants."); r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -1119,29 +1022,24 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in return; } else { - *r_return = Variant::construct(Variant::Type(type), p_inputs, 1, r_error); } } break; case VisualScriptBuiltinFunc::TYPE_OF: { - *r_return = p_inputs[0]->get_type(); } break; case VisualScriptBuiltinFunc::TYPE_EXISTS: { - *r_return = ClassDB::class_exists(*p_inputs[0]); } break; case VisualScriptBuiltinFunc::TEXT_CHAR: { - CharType result[2] = { *p_inputs[0], 0 }; *r_return = String(result); } break; case VisualScriptBuiltinFunc::TEXT_ORD: { - if (p_inputs[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -1165,39 +1063,33 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::TEXT_STR: { - String str = *p_inputs[0]; *r_return = str; } break; case VisualScriptBuiltinFunc::TEXT_PRINT: { - String str = *p_inputs[0]; print_line(str); } break; case VisualScriptBuiltinFunc::TEXT_PRINTERR: { - String str = *p_inputs[0]; print_error(str); } break; case VisualScriptBuiltinFunc::TEXT_PRINTRAW: { - String str = *p_inputs[0]; OS::get_singleton()->print("%s", str.utf8().get_data()); } break; case VisualScriptBuiltinFunc::VAR_TO_STR: { - String vars; VariantWriter::write_to_string(*p_inputs[0], vars); *r_return = vars; } break; case VisualScriptBuiltinFunc::STR_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::STRING) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -1223,7 +1115,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::VAR_TO_BYTES: { - if (p_inputs[1]->get_type() != Variant::BOOL) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 1; @@ -1250,7 +1141,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in *r_return = barr; } break; case VisualScriptBuiltinFunc::BYTES_TO_VAR: { - if (p_inputs[0]->get_type() != Variant::PACKED_BYTE_ARRAY) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; @@ -1283,7 +1173,6 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in } break; case VisualScriptBuiltinFunc::COLORN: { - VALIDATE_ARG_NUM(1); Color color = Color::named(*p_inputs[0]); @@ -1309,14 +1198,12 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - VisualScriptBuiltinFunc::exec_func(func, p_inputs, p_outputs[0], r_error, r_error_str); return 0; } }; VisualScriptNodeInstance *VisualScriptBuiltinFunc::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceBuiltinFunc *instance = memnew(VisualScriptNodeInstanceBuiltinFunc); instance->node = this; instance->instance = p_instance; @@ -1325,14 +1212,12 @@ VisualScriptNodeInstance *VisualScriptBuiltinFunc::instance(VisualScriptInstance } void VisualScriptBuiltinFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_func", "which"), &VisualScriptBuiltinFunc::set_func); ClassDB::bind_method(D_METHOD("get_func"), &VisualScriptBuiltinFunc::get_func); String cc; for (int i = 0; i < FUNC_MAX; i++) { - if (i > 0) cc += ","; cc += func_name[i]; @@ -1411,24 +1296,20 @@ void VisualScriptBuiltinFunc::_bind_methods() { } VisualScriptBuiltinFunc::VisualScriptBuiltinFunc(VisualScriptBuiltinFunc::BuiltinFunc func) { - this->func = func; } VisualScriptBuiltinFunc::VisualScriptBuiltinFunc() { - func = MATH_SIN; } template <VisualScriptBuiltinFunc::BuiltinFunc func> static Ref<VisualScriptNode> create_builtin_func_node(const String &p_name) { - Ref<VisualScriptBuiltinFunc> node = memnew(VisualScriptBuiltinFunc(func)); return node; } void register_visual_script_builtin_func_node() { - VisualScriptLanguage::singleton->add_register_func("functions/built_in/sin", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_SIN>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/cos", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_COS>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/tan", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_TAN>); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index d950f858d4..1b186353f1 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptBuiltinFunc : public VisualScriptNode { - GDCLASS(VisualScriptBuiltinFunc, VisualScriptNode); public: diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 3649486724..f7e9e30ed6 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -46,7 +46,6 @@ #ifdef TOOLS_ENABLED class VisualScriptEditorSignalEdit : public Object { - GDCLASS(VisualScriptEditorSignalEdit, Object); StringName sig; @@ -62,18 +61,15 @@ protected: } void _sig_changed() { - _change_notify(); emit_signal("changed"); } bool _set(const StringName &p_name, const Variant &p_value) { - if (sig == StringName()) return false; if (p_name == "argument_count") { - int new_argc = p_value; int argc = script->custom_signal_get_argument_count(sig); if (argc == new_argc) @@ -87,9 +83,7 @@ protected: undo_redo->add_undo_method(script.ptr(), "custom_signal_add_argument", sig, script->custom_signal_get_argument_name(sig, i), script->custom_signal_get_argument_type(sig, i), -1); } } else if (new_argc > argc) { - for (int i = argc; i < new_argc; i++) { - undo_redo->add_do_method(script.ptr(), "custom_signal_add_argument", sig, Variant::NIL, "arg" + itos(i + 1), -1); undo_redo->add_undo_method(script.ptr(), "custom_signal_remove_argument", sig, argc); } @@ -107,7 +101,6 @@ protected: ERR_FAIL_INDEX_V(idx, script->custom_signal_get_argument_count(sig), false); String what = String(p_name).get_slice("/", 2); if (what == "type") { - int old_type = script->custom_signal_get_argument_type(sig, idx); int new_type = p_value; undo_redo->create_action(TTR("Change Argument Type")); @@ -119,7 +112,6 @@ protected: } if (what == "name") { - String old_name = script->custom_signal_get_argument_name(sig, idx); String new_name = p_value; undo_redo->create_action(TTR("Change Argument name")); @@ -134,7 +126,6 @@ protected: } bool _get(const StringName &p_name, Variant &r_ret) const { - if (sig == StringName()) return false; @@ -159,7 +150,6 @@ protected: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - if (sig == StringName()) return; @@ -177,7 +167,6 @@ protected: public: void edit(const StringName &p_sig) { - sig = p_sig; _change_notify(); } @@ -186,7 +175,6 @@ public: }; class VisualScriptEditorVariableEdit : public Object { - GDCLASS(VisualScriptEditorVariableEdit, Object); StringName var; @@ -203,18 +191,15 @@ protected: } void _var_changed() { - _change_notify(); emit_signal("changed"); } void _var_value_changed() { - _change_notify("value"); //so the whole tree is not redrawn, makes editing smoother in general emit_signal("changed"); } bool _set(const StringName &p_name, const Variant &p_value) { - if (var == StringName()) return false; @@ -232,7 +217,6 @@ protected: Dictionary d = script->call("get_variable_info", var); if (String(p_name) == "type") { - Dictionary dc = d.duplicate(); dc["type"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -245,7 +229,6 @@ protected: } if (String(p_name) == "hint") { - Dictionary dc = d.duplicate(); dc["hint"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -258,7 +241,6 @@ protected: } if (String(p_name) == "hint_string") { - Dictionary dc = d.duplicate(); dc["hint_string"] = p_value; undo_redo->create_action(TTR("Set Variable Type")); @@ -280,7 +262,6 @@ protected: } bool _get(const StringName &p_name, Variant &r_ret) const { - if (var == StringName()) return false; @@ -312,7 +293,6 @@ protected: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - if (var == StringName()) return; @@ -330,7 +310,6 @@ protected: public: void edit(const StringName &p_var) { - var = p_var; _change_notify(); } @@ -557,7 +536,6 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { } void VisualScriptEditor::_update_graph_connections() { - graph->clear_connections(); List<StringName> funcs; @@ -569,12 +547,10 @@ void VisualScriptEditor::_update_graph_connections() { } for (List<StringName>::Element *F = funcs.front(); F; F = F->next()) { - List<VisualScript::SequenceConnection> sequence_conns; script->get_sequence_connection_list(F->get(), &sequence_conns); for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) { - graph->connect_node(itos(E->get().from_node), E->get().from_output, itos(E->get().to_node), 0); } @@ -582,7 +558,6 @@ void VisualScriptEditor::_update_graph_connections() { script->get_data_connection_list(F->get(), &data_conns); for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) { - VisualScript::DataConnection dc = E->get(); Ref<VisualScriptNode> from_node = script->get_node(F->get(), E->get().from_node); @@ -600,7 +575,6 @@ void VisualScriptEditor::_update_graph_connections() { } void VisualScriptEditor::_update_graph(int p_only_id) { - if (updating_graph) return; @@ -614,9 +588,7 @@ void VisualScriptEditor::_update_graph(int p_only_id) { memdelete(gid); } } else { - for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to<GraphNode>(graph->get_child(i))) { memdelete(graph->get_child(i)); i--; @@ -681,7 +653,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { StringName editor_icons = "EditorIcons"; for (List<int>::Element *E = ids.front(); E; E = E->next()) { - if (p_only_id >= 0 && p_only_id != E->get()) continue; @@ -807,12 +778,10 @@ void VisualScriptEditor::_update_graph(int p_only_id) { int mixed_seq_ports = 0; if (!single_seq_output) { - if (node->has_mixed_input_and_sequence_ports()) { mixed_seq_ports = node->get_output_sequence_port_count(); } else { for (int i = 0; i < node->get_output_sequence_port_count(); i++) { - Label *text2 = memnew(Label); text2->set_text(node->get_output_sequence_port_text(i)); text2->set_align(Label::ALIGN_RIGHT); @@ -824,7 +793,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } for (int i = 0; i < MAX(node->get_output_value_port_count(), MAX(mixed_seq_ports, node->get_input_value_port_count())); i++) { - bool left_ok = false; Variant::Type left_type = Variant::NIL; String left_name; @@ -852,7 +820,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { vbc->add_child(hbc); vbc->add_child(hbc2); if (left_ok) { - Ref<Texture2D> t; if (left_type >= 0 && left_type < Variant::VARIANT_MAX) { t = type_icons[left_type]; @@ -897,7 +864,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } if (left_type != Variant::NIL && !script->is_input_value_port_connected(F->get(), E->get(), i)) { - PropertyInfo pi = node->get_input_value_port_info(i); Button *button = memnew(Button); Variant value = node->get_default_input_value(i); @@ -913,7 +879,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { button->set_custom_minimum_size(Size2(30, 0) * EDSCALE); button->connect("draw", callable_mp(this, &VisualScriptEditor::_draw_color_over_button), varray(button, value)); } else if (left_type == Variant::OBJECT && Ref<Resource>(value).is_valid()) { - Ref<Resource> res = value; Array arr; arr.push_back(button->get_instance_id()); @@ -921,10 +886,8 @@ void VisualScriptEditor::_update_graph(int p_only_id) { EditorResourcePreview::get_singleton()->queue_edited_resource_preview(res, this, "_button_resource_previewed", arr); } else if (pi.type == Variant::INT && pi.hint == PROPERTY_HINT_ENUM) { - button->set_text(pi.hint_string.get_slice(",", value)); } else { - button->set_text(value); } button->connect("pressed", callable_mp(this, &VisualScriptEditor::_default_value_edited), varray(button, E->get(), i)); @@ -940,7 +903,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { hbc2->add_spacer(); if (i < mixed_seq_ports) { - Label *text2 = memnew(Label); text2->set_text(node->get_output_sequence_port_text(i)); text2->set_align(Label::ALIGN_RIGHT); @@ -948,7 +910,6 @@ 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")); @@ -1019,7 +980,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, bool is_input) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); @@ -1038,7 +998,6 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b } void VisualScriptEditor::_update_node_size(int p_id) { - Node *node = graph->get_node(itos(p_id)); if (Object::cast_to<Control>(node)) Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller @@ -1086,7 +1045,6 @@ void VisualScriptEditor::_update_members() { List<StringName> func_names; script->get_function_list(&func_names); for (List<StringName>::Element *E = func_names.front(); E; E = E->next()) { - if (E->get() == default_func) { continue; } @@ -1189,7 +1147,6 @@ void VisualScriptEditor::_update_members() { } void VisualScriptEditor::_member_selected() { - if (updating_members) return; @@ -1199,7 +1156,6 @@ void VisualScriptEditor::_member_selected() { selected = ti->get_metadata(0); if (ti->get_parent() == members->get_root()->get_children()) { - #ifdef OSX_ENABLED bool held_ctrl = Input::get_singleton()->is_key_pressed(KEY_META); #else @@ -1213,7 +1169,6 @@ void VisualScriptEditor::_member_selected() { } void VisualScriptEditor::_member_edited() { - if (updating_members) return; @@ -1227,7 +1182,6 @@ void VisualScriptEditor::_member_edited() { return; if (!new_name.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); updating_members = true; ti->set_text(0, name); @@ -1236,7 +1190,6 @@ void VisualScriptEditor::_member_edited() { } if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) { - EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name); updating_members = true; ti->set_text(0, name); @@ -1247,7 +1200,6 @@ void VisualScriptEditor::_member_edited() { TreeItem *root = members->get_root(); if (ti->get_parent() == root->get_children()) { - selected = new_name; int node_id = script->get_function_node_id(name); @@ -1292,7 +1244,6 @@ void VisualScriptEditor::_member_edited() { } if (ti->get_parent() == root->get_children()->get_next()) { - selected = new_name; undo_redo->create_action(TTR("Rename Variable")); undo_redo->add_do_method(script.ptr(), "rename_variable", name, new_name); @@ -1309,7 +1260,6 @@ void VisualScriptEditor::_member_edited() { } if (ti->get_parent() == root->get_children()->get_next()->get_next()) { - selected = new_name; undo_redo->create_action(TTR("Rename Signal")); undo_redo->add_do_method(script.ptr(), "rename_custom_signal", name, new_name); @@ -1431,7 +1381,6 @@ void VisualScriptEditor::_deselect_input_names() { } void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_button) { - TreeItem *ti = Object::cast_to<TreeItem>(p_item); TreeItem *root = members->get_root(); @@ -1446,7 +1395,6 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt return; } else if (p_button == 0) { - String name = _validate_name("new_function"); selected = name; Vector2 ofs = _get_available_pos(); @@ -1514,7 +1462,6 @@ void VisualScriptEditor::_member_button(Object *p_item, int p_column, int p_butt } void VisualScriptEditor::_add_input_port(int p_id) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); @@ -1536,7 +1483,6 @@ void VisualScriptEditor::_add_input_port(int p_id) { } void VisualScriptEditor::_add_output_port(int p_id) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); @@ -1558,7 +1504,6 @@ void VisualScriptEditor::_add_output_port(int p_id) { } void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); @@ -1590,7 +1535,6 @@ void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { } void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); @@ -1634,7 +1578,6 @@ void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { } void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id) { - StringName func = _get_function_of_node(p_id); Ref<VisualScriptExpression> vse = script->get_node(func, p_id); @@ -1694,12 +1637,10 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const } String VisualScriptEditor::_validate_name(const String &p_name) const { - String valid = p_name; int counter = 1; while (true) { - bool exists = script->has_function(valid) || script->has_variable(valid) || script->has_custom_signal(valid); if (exists) { @@ -1715,7 +1656,6 @@ String VisualScriptEditor::_validate_name(const String &p_name) const { } void VisualScriptEditor::_on_nodes_delete() { - // delete all the selected nodes List<int> to_erase; @@ -1735,7 +1675,6 @@ void VisualScriptEditor::_on_nodes_delete() { undo_redo->create_action(TTR("Remove VisualScript Nodes")); for (List<int>::Element *F = to_erase.front(); F; F = F->next()) { - int cr_node = F->get(); StringName func = _get_function_of_node(cr_node); @@ -1747,7 +1686,6 @@ void VisualScriptEditor::_on_nodes_delete() { script->get_sequence_connection_list(func, &sequence_conns); for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) { - if (E->get().from_node == cr_node || E->get().to_node == cr_node) { undo_redo->add_undo_method(script.ptr(), "sequence_connect", func, E->get().from_node, E->get().from_output, E->get().to_node); } @@ -1757,7 +1695,6 @@ void VisualScriptEditor::_on_nodes_delete() { script->get_data_connection_list(func, &data_conns); for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) { - if (E->get().from_node == F->get() || E->get().to_node == F->get()) { undo_redo->add_undo_method(script.ptr(), "data_connect", func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); } @@ -1770,7 +1707,6 @@ void VisualScriptEditor::_on_nodes_delete() { } void VisualScriptEditor::_on_nodes_duplicate() { - Set<int> to_duplicate; List<StringName> funcs; @@ -1795,7 +1731,6 @@ void VisualScriptEditor::_on_nodes_duplicate() { HashMap<int, int> remap; for (Set<int>::Element *F = to_duplicate.front(); F; F = F->next()) { - // duplicate from the specific function but place it into the default func as it would lack the connections StringName func = _get_function_of_node(F->get()); Ref<VisualScriptNode> node = script->get_node(func, F->get()); @@ -1884,7 +1819,6 @@ void VisualScriptEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { } void VisualScriptEditor::_members_gui_input(const Ref<InputEvent> &p_event) { - Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { if (members->has_focus()) { @@ -1920,15 +1854,12 @@ void VisualScriptEditor::_members_gui_input(const Ref<InputEvent> &p_event) { } void VisualScriptEditor::_rename_function(const String &name, const String &new_name) { - if (!new_name.is_valid_identifier()) { - EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); return; } if (script->has_function(new_name) || script->has_variable(new_name) || script->has_custom_signal(new_name)) { - EditorNode::get_singleton()->show_warning(TTR("Name already in use by another func/var/signal:") + " " + new_name); return; } @@ -1973,7 +1904,6 @@ void VisualScriptEditor::_rename_function(const String &name, const String &new_ } void VisualScriptEditor::_fn_name_box_input(const Ref<InputEvent> &p_event) { - if (!function_name_edit->is_visible()) return; @@ -1986,9 +1916,7 @@ void VisualScriptEditor::_fn_name_box_input(const Ref<InputEvent> &p_event) { } Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { - if (p_from == members) { - TreeItem *it = members->get_item_at_position(p_point); if (!it) return Variant(); @@ -2002,15 +1930,12 @@ Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f TreeItem *root = members->get_root(); if (it->get_parent() == root->get_children()) { - dd["type"] = "visual_script_function_drag"; dd["function"] = type; } else if (it->get_parent() == root->get_children()->get_next()) { - dd["type"] = "visual_script_variable_drag"; dd["variable"] = type; } else if (it->get_parent() == root->get_children()->get_next()->get_next()) { - dd["type"] = "visual_script_signal_drag"; dd["signal"] = type; @@ -2027,9 +1952,7 @@ Variant VisualScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_f } bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - if (p_from == graph) { - Dictionary d = p_data; if (d.has("type") && (String(d["type"]) == "visual_script_node_drag" || @@ -2040,9 +1963,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & String(d["type"]) == "resource" || String(d["type"]) == "files" || String(d["type"]) == "nodes")) { - if (String(d["type"]) == "obj_property") { - #ifdef OSX_ENABLED const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Getter. Hold Shift to drop a generic signature."), find_keycode_name(KEY_META))); #else @@ -2051,7 +1972,6 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } if (String(d["type"]) == "nodes") { - #ifdef OSX_ENABLED const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(KEY_META))); #else @@ -2060,7 +1980,6 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } if (String(d["type"]) == "visual_script_variable_drag") { - #ifdef OSX_ENABLED const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(KEY_META))); #else @@ -2076,7 +1995,6 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & } static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) return nullptr; @@ -2095,7 +2013,6 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const } void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { - if (p_from != graph) { return; } @@ -2130,7 +2047,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "visual_script_variable_drag") { - #ifdef OSX_ENABLED bool use_set = Input::get_singleton()->is_key_pressed(KEY_META); #else @@ -2151,7 +2067,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da vnodes->set_variable(d["variable"]); vnode = vnodes; } else { - Ref<VisualScriptVariableGet> vnodeg; vnodeg.instance(); vnodeg->set_variable(d["variable"]); @@ -2175,7 +2090,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "visual_script_function_drag") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -2208,7 +2122,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "visual_script_signal_drag") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -2238,7 +2151,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "resource") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -2268,7 +2180,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "files") { - Vector2 ofs = graph->get_scroll_ofs() + p_point; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -2286,7 +2197,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da undo_redo->create_action(TTR("Add Preload Node")); for (int i = 0; i < files.size(); i++) { - Ref<Resource> res = ResourceLoader::load(files[i]); if (!res.is_valid()) continue; @@ -2308,7 +2218,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } for (List<int>::Element *E = new_ids.front(); E; E = E->next()) { - Node *node = graph->get_node(itos(E->get())); if (node) { graph->set_selected(node); @@ -2318,7 +2227,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "nodes") { - Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); if (!sn) { @@ -2350,7 +2258,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } for (int i = 0; i < nodes.size(); i++) { - NodePath np = nodes[i]; Node *node = get_node(np); if (!node) { @@ -2388,7 +2295,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } if (String(d["type"]) == "obj_property") { - Node *sn = _find_script_node(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root(), script); if (!sn && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { @@ -2417,7 +2323,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da #endif if (!node || Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { - if (use_get) undo_redo->create_action(TTR("Add Getter Property")); else @@ -2428,7 +2333,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da Ref<VisualScriptNode> vnode; if (!use_get) { - Ref<VisualScriptPropertySet> pset; pset.instance(); pset->set_call_mode(VisualScriptPropertySet::CALL_MODE_INSTANCE); @@ -2439,7 +2343,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da }*/ vnode = pset; } else { - Ref<VisualScriptPropertyGet> pget; pget.instance(); pget->set_call_mode(VisualScriptPropertyGet::CALL_MODE_INSTANCE); @@ -2461,7 +2364,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da undo_redo->commit_action(); } else { - if (use_get) undo_redo->create_action(TTR("Add Getter Property")); else @@ -2472,7 +2374,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da Ref<VisualScriptNode> vnode; if (!use_get) { - Ref<VisualScriptPropertySet> pset; pset.instance(); if (sn == node) { @@ -2484,7 +2385,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da vnode = pset; } else { - Ref<VisualScriptPropertyGet> pget; pget.instance(); if (sn == node) { @@ -2510,7 +2410,6 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } void VisualScriptEditor::_selected_method(const String &p_method, const String &p_type, const bool p_connecting) { - Ref<VisualScriptFunctionCall> vsfc = script->get_node(default_func, selecting_method_id); if (!vsfc.is_valid()) return; @@ -2518,7 +2417,6 @@ void VisualScriptEditor::_selected_method(const String &p_method, const String & } void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) { - Button *button = Object::cast_to<Button>(obj); if (!button) return; @@ -2528,7 +2426,6 @@ void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) { } void VisualScriptEditor::_button_resource_previewed(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, Variant p_ud) { - Array ud = p_ud; ERR_FAIL_COND(ud.size() != 2); @@ -2544,7 +2441,6 @@ void VisualScriptEditor::_button_resource_previewed(const String &p_path, const if (p_preview.is_null()) { b->set_text(ud[1]); } else { - b->set_icon(p_preview); } } @@ -2559,7 +2455,6 @@ RES VisualScriptEditor::get_edited_resource() const { } void VisualScriptEditor::set_edited_resource(const RES &p_res) { - script = p_res; signal_editor->script = script; signal_editor->undo_redo = undo_redo; @@ -2581,7 +2476,6 @@ void VisualScriptEditor::set_edited_resource(const RES &p_res) { } Vector<String> VisualScriptEditor::get_functions() { - return Vector<String>(); } @@ -2589,7 +2483,6 @@ void VisualScriptEditor::reload_text() { } String VisualScriptEditor::get_name() { - String name; if (script->get_path().find("local://") == -1 && script->get_path().find("::") == -1) { @@ -2606,17 +2499,14 @@ String VisualScriptEditor::get_name() { } Ref<Texture2D> VisualScriptEditor::get_theme_icon() { - return Control::get_theme_icon("VisualScript", "EditorIcons"); } bool VisualScriptEditor::is_unsaved() { - return script->is_edited() || script->are_subnodes_edited(); } Variant VisualScriptEditor::get_edit_state() { - Dictionary d; d["function"] = default_func; d["scroll"] = graph->get_scroll_ofs(); @@ -2627,7 +2517,6 @@ Variant VisualScriptEditor::get_edit_state() { } void VisualScriptEditor::set_edit_state(const Variant &p_state) { - Dictionary d = p_state; if (d.has("function")) { selected = default_func; @@ -2651,7 +2540,6 @@ void VisualScriptEditor::set_edit_state(const Variant &p_state) { } void VisualScriptEditor::_center_on_node(const StringName &p_func, int p_id) { - Node *n = graph->get_node(itos(p_id)); GraphNode *gn = Object::cast_to<GraphNode>(n); @@ -2672,7 +2560,6 @@ void VisualScriptEditor::_center_on_node(const StringName &p_func, int p_id) { } void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { - p_line += 1; //add one because script lines begin from 0. if (p_with_error) @@ -2681,9 +2568,7 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { List<StringName> functions; script->get_function_list(&functions); for (List<StringName>::Element *E = functions.front(); E; E = E->next()) { - if (script->has_node(E->get(), p_line)) { - _update_graph(); _update_members(); @@ -2714,7 +2599,6 @@ void VisualScriptEditor::convert_indent_to_tabs() { } void VisualScriptEditor::ensure_focus() { - graph->grab_focus(); } @@ -2726,15 +2610,12 @@ void VisualScriptEditor::reload(bool p_soft) { } void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints) { - List<StringName> functions; script->get_function_list(&functions); for (List<StringName>::Element *E = functions.front(); E; E = E->next()) { - List<int> nodes; script->get_node_list(E->get(), &nodes); for (List<int>::Element *F = nodes.front(); F; F = F->next()) { - Ref<VisualScriptNode> vsn = script->get_node(E->get(), F->get()); if (vsn->is_breakpoint()) { p_breakpoints->push_back(F->get() - 1); //subtract 1 because breakpoints in text start from zero @@ -2744,7 +2625,6 @@ void VisualScriptEditor::get_breakpoints(List<int> *p_breakpoints) { } void VisualScriptEditor::add_callback(const String &p_function, PackedStringArray p_args) { - if (script->has_function(p_function)) { _update_members(); _update_graph(); @@ -2755,7 +2635,6 @@ void VisualScriptEditor::add_callback(const String &p_function, PackedStringArra Ref<VisualScriptFunction> func; func.instance(); for (int i = 0; i < p_args.size(); i++) { - String name = p_args[i]; Variant::Type type = Variant::NIL; @@ -2763,7 +2642,6 @@ void VisualScriptEditor::add_callback(const String &p_function, PackedStringArra String tt = name.get_slice(":", 1); name = name.get_slice(":", 0); for (int j = 0; j < Variant::VARIANT_MAX; j++) { - String tname = Variant::get_type_name(Variant::Type(j)); if (tname == tt) { type = Variant::Type(j); @@ -2790,7 +2668,6 @@ bool VisualScriptEditor::show_members_overview() { } void VisualScriptEditor::update_settings() { - _update_graph(); } @@ -2805,12 +2682,10 @@ void VisualScriptEditor::set_tooltip_request_func(String p_method, Object *p_obj } Control *VisualScriptEditor::get_edit_menu() { - return edit_menu; } void VisualScriptEditor::_change_base_type() { - select_base_type->popup_create(true, true); } @@ -2824,7 +2699,6 @@ void VisualScriptEditor::clear_edit_menu() { } void VisualScriptEditor::_change_base_type_callback() { - String bt = select_base_type->get_selected_type(); ERR_FAIL_COND(bt == String()); @@ -2837,7 +2711,6 @@ void VisualScriptEditor::_change_base_type_callback() { } void VisualScriptEditor::_node_selected(Node *p_node) { - Ref<VisualScriptNode> vnode = p_node->get_meta("__vnode"); if (vnode.is_null()) return; @@ -2846,7 +2719,6 @@ void VisualScriptEditor::_node_selected(Node *p_node) { } static bool _get_out_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r_real_slot, bool &r_sequence) { - if (p_slot < p_node->get_output_sequence_port_count()) { r_sequence = true; r_real_slot = p_slot; @@ -2861,7 +2733,6 @@ static bool _get_out_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int & } static bool _get_in_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r_real_slot, bool &r_sequence) { - if (p_slot == 0 && p_node->has_input_sequence_port()) { r_sequence = true; r_real_slot = 0; @@ -2875,17 +2746,14 @@ static bool _get_in_slot(const Ref<VisualScriptNode> &p_node, int p_slot, int &r } void VisualScriptEditor::_begin_node_move() { - undo_redo->create_action(TTR("Move Node(s)")); } void VisualScriptEditor::_end_node_move() { - undo_redo->commit_action(); } void VisualScriptEditor::_move_node(const StringName &p_func, int p_id, const Vector2 &p_to) { - if (!script->has_function(p_func)) return; @@ -2898,7 +2766,6 @@ void VisualScriptEditor::_move_node(const StringName &p_func, int p_id, const Ve } StringName VisualScriptEditor::_get_function_of_node(int p_id) const { - List<StringName> funcs; script->get_function_list(&funcs); for (List<StringName>::Element *E = funcs.front(); E; E = E->next()) { @@ -2911,7 +2778,6 @@ StringName VisualScriptEditor::_get_function_of_node(int p_id) const { } void VisualScriptEditor::_node_moved(Vector2 p_from, Vector2 p_to, int p_id) { - StringName func = _get_function_of_node(p_id); undo_redo->add_do_method(this, "_move_node", func, p_id, p_to); @@ -2919,7 +2785,6 @@ void VisualScriptEditor::_node_moved(Vector2 p_from, Vector2 p_to, int p_id) { } void VisualScriptEditor::_remove_node(int p_id) { - undo_redo->create_action(TTR("Remove VisualScript Node")); StringName func = _get_function_of_node(p_id); @@ -2931,7 +2796,6 @@ void VisualScriptEditor::_remove_node(int p_id) { script->get_sequence_connection_list(func, &sequence_conns); for (List<VisualScript::SequenceConnection>::Element *E = sequence_conns.front(); E; E = E->next()) { - if (E->get().from_node == p_id || E->get().to_node == p_id) { undo_redo->add_undo_method(script.ptr(), "sequence_connect", func, E->get().from_node, E->get().from_output, E->get().to_node); } @@ -2941,7 +2805,6 @@ void VisualScriptEditor::_remove_node(int p_id) { script->get_data_connection_list(func, &data_conns); for (List<VisualScript::DataConnection>::Element *E = data_conns.front(); E; E = E->next()) { - if (E->get().from_node == p_id || E->get().to_node == p_id) { undo_redo->add_undo_method(script.ptr(), "data_connect", func, E->get().from_node, E->get().from_port, E->get().to_node, E->get().to_port); } @@ -2954,7 +2817,6 @@ void VisualScriptEditor::_remove_node(int p_id) { } void VisualScriptEditor::_node_ports_changed(const String &p_func, int p_id) { - _update_graph(p_id); } @@ -2974,7 +2836,6 @@ bool VisualScriptEditor::node_has_sequence_connections(const StringName &p_func, } void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot) { - StringName from_func = _get_function_of_node(p_from.to_int()); Ref<VisualScriptNode> from_node = script->get_node(from_func, p_from.to_int()); @@ -3172,7 +3033,6 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, } void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_slot, const String &p_to, int p_to_slot) { - StringName func = _get_function_of_node(p_from.to_int()); ERR_FAIL_COND(func != _get_function_of_node(p_to.to_int())); @@ -3202,7 +3062,6 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl undo_redo->add_do_method(script.ptr(), "sequence_disconnect", func, p_from.to_int(), from_port, p_to.to_int()); undo_redo->add_undo_method(script.ptr(), "sequence_connect", func, p_from.to_int(), from_port, p_to.to_int()); } else { - can_swap = true; data_disconnect_node = p_to.to_int(); data_disconnect_port = to_port; @@ -3222,7 +3081,6 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl } void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, const StringName &p_func_to, int p_id) { - Set<int> nodes_to_move; HashMap<int, Map<int, int>> seqconns_to_move; // from => List(outp, to) HashMap<int, Map<int, Pair<int, int>>> dataconns_to_move; // to => List(inp_p => from, outp) @@ -3432,7 +3290,6 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, } void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_pos) { - Node *node = graph->get_node(p_from); GraphNode *gn = Object::cast_to<GraphNode>(node); if (!gn) @@ -3447,7 +3304,6 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro port_action_pos = p_release_pos; if (p_from_slot < vsn->get_output_sequence_port_count()) { - port_action_node = p_from.to_int(); port_action_output = p_from_slot; _port_action_menu(CREATE_ACTION, func); @@ -3459,7 +3315,6 @@ void VisualScriptEditor::_graph_connect_to_empty(const String &p_from, int p_fro } VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_action_node, int p_port_action_output, Set<int> &visited_nodes) { - VisualScriptNode::TypeGuess tg; tg.type = Variant::NIL; @@ -3473,7 +3328,6 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac Ref<VisualScriptNode> node = script->get_node(func, p_port_action_node); if (!node.is_valid()) { - return tg; } @@ -3490,16 +3344,13 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac int from_port; if (script->get_input_value_port_connection_source(func, p_port_action_node, i, &from_node, &from_port)) { - g = _guess_output_type(from_node, from_port, visited_nodes); } else { Variant defval = node->get_default_input_value(i); if (defval.get_type() == Variant::OBJECT) { - Object *obj = defval; if (obj) { - g.type = Variant::OBJECT; g.gdclass = obj->get_class(); g.script = obj->get_script(); @@ -3515,7 +3366,6 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac } void VisualScriptEditor::_port_action_menu(int p_option, const StringName &func) { - Vector2 ofs = graph->get_scroll_ofs() + port_action_pos; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -3526,7 +3376,6 @@ void VisualScriptEditor::_port_action_menu(int p_option, const StringName &func) Set<int> vn; switch (p_option) { - case CREATE_CALL_SET_GET: { Ref<VisualScriptFunctionCall> n; n.instance(); @@ -3590,7 +3439,6 @@ void VisualScriptEditor::_port_action_menu(int p_option, const StringName &func) } void VisualScriptEditor::connect_data(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode, int new_id) { - undo_redo->create_action(TTR("Connect Node Data")); VisualScriptReturn *vnode_return = Object::cast_to<VisualScriptReturn>(vnode.ptr()); if (vnode_return != nullptr && vnode_old->get_output_value_port_count() > 0) { @@ -3616,7 +3464,6 @@ void VisualScriptEditor::connect_data(Ref<VisualScriptNode> vnode_old, Ref<Visua } void VisualScriptEditor::_selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting) { - Vector2 ofs = graph->get_scroll_ofs() + port_action_pos; if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -3678,18 +3525,15 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri Ref<VisualScriptPropertySet> script_prop_set; if (p_category == String("method")) { - Ref<VisualScriptFunctionCall> n; n.instance(); vnode = n; } else if (p_category == String("set")) { - Ref<VisualScriptPropertySet> n; n.instance(); vnode = n; script_prop_set = n; } else if (p_category == String("get")) { - Ref<VisualScriptPropertyGet> n; n.instance(); n->set_property(p_text); @@ -3698,33 +3542,27 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri if (p_category == String("action")) { if (p_text == "VisualScriptCondition") { - Ref<VisualScriptCondition> n; n.instance(); vnode = n; } if (p_text == "VisualScriptSwitch") { - Ref<VisualScriptSwitch> n; n.instance(); vnode = n; } else if (p_text == "VisualScriptSequence") { - Ref<VisualScriptSequence> n; n.instance(); vnode = n; } else if (p_text == "VisualScriptIterator") { - Ref<VisualScriptIterator> n; n.instance(); vnode = n; } else if (p_text == "VisualScriptWhile") { - Ref<VisualScriptWhile> n; n.instance(); vnode = n; } else if (p_text == "VisualScriptReturn") { - Ref<VisualScriptReturn> n; n.instance(); vnode = n; @@ -3747,7 +3585,6 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri Ref<VisualScriptNode> vsn = script->get_node(func, port_action_new_node); if (Object::cast_to<VisualScriptFunctionCall>(vsn.ptr())) { - Ref<VisualScriptFunctionCall> vsfc = vsn; vsfc->set_function(p_text); @@ -3857,7 +3694,6 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri } void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id) { - VisualScriptOperator *vnode_operator = Object::cast_to<VisualScriptOperator>(vnode_new.ptr()); if (vnode_operator != nullptr && !vnode_operator->has_input_sequence_port()) { return; @@ -3905,7 +3741,6 @@ void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<Visual } void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, const String &p_category, const bool p_connecting) { - String name = p_text; if (script->has_function(name)) { EditorNode::get_singleton()->show_warning(vformat(TTR("Script already has function '%s'"), name)); @@ -3968,7 +3803,6 @@ void VisualScriptEditor::_cancel_connect_node() { } int VisualScriptEditor::_create_new_node_from_name(const String &p_text, const Vector2 &p_point, const StringName &p_func) { - StringName func = default_func; if (p_func != StringName()) func = p_func; @@ -3985,7 +3819,6 @@ int VisualScriptEditor::_create_new_node_from_name(const String &p_text, const V } void VisualScriptEditor::_default_value_changed() { - Ref<VisualScriptNode> vsn = script->get_node(_get_function_of_node(editing_id), editing_id); if (vsn.is_null()) return; @@ -4000,7 +3833,6 @@ void VisualScriptEditor::_default_value_changed() { } void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_input_port) { - Ref<VisualScriptNode> vsn = script->get_node(_get_function_of_node(p_id), p_id); if (vsn.is_null()) return; @@ -4008,7 +3840,6 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i PropertyInfo pinfo = vsn->get_input_value_port_info(p_input_port); Variant existing = vsn->get_default_input_value(p_input_port); if (pinfo.type != Variant::NIL && existing.get_type() != pinfo.type) { - Callable::CallError ce; const Variant *existingp = &existing; existing = Variant::construct(pinfo.type, &existingp, 1, ce, false); @@ -4018,7 +3849,6 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i default_value_edit->set_size(Size2(1, 1)); if (pinfo.type == Variant::NODE_PATH) { - Node *edited_scene = get_tree()->get_edited_scene_root(); if (edited_scene) { // Fixing an old crash bug ( Visual Script Crashes on editing NodePath with an empty scene open) Node *script_node = _find_script_node(edited_scene, edited_scene, script); @@ -4047,19 +3877,16 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i } void VisualScriptEditor::_show_hint(const String &p_hint) { - hint_text->set_text(p_hint); hint_text->show(); hint_text_timer->start(); } void VisualScriptEditor::_hide_timer() { - hint_text->hide(); } void VisualScriptEditor::_notification(int p_what) { - switch (p_what) { case NOTIFICATION_READY: { variable_editor->connect("changed", callable_mp(this, &VisualScriptEditor::_update_members)); @@ -4122,7 +3949,6 @@ void VisualScriptEditor::_notification(int p_what) { } void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) { - if (updating_graph || !script.is_valid()) return; @@ -4137,7 +3963,6 @@ void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) { } void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_node) { - if (updating_graph) return; @@ -4168,13 +3993,11 @@ void VisualScriptEditor::_comment_node_resized(const Vector2 &p_new_size, int p_ } void VisualScriptEditor::_menu_option(int p_what) { - switch (p_what) { case EDIT_DELETE_NODES: { _on_nodes_delete(); } break; case EDIT_TOGGLE_BREAKPOINT: { - List<String> reselect; for (int i = 0; i < graph->get_child_count(); i++) { GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); @@ -4216,7 +4039,6 @@ void VisualScriptEditor::_menu_option(int p_what) { GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); if (gn) { if (gn->is_selected()) { - int id = String(gn->get_name()).to_int(); StringName func = _get_function_of_node(id); Ref<VisualScriptNode> node = script->get_node(func, id); @@ -4242,9 +4064,7 @@ void VisualScriptEditor::_menu_option(int p_what) { script->get_sequence_connection_list(F->get(), &sequence_connections); for (List<VisualScript::SequenceConnection>::Element *E = sequence_connections.front(); E; E = E->next()) { - if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) { - clipboard->sequence_connections.insert(E->get()); } } @@ -4254,9 +4074,7 @@ void VisualScriptEditor::_menu_option(int p_what) { script->get_data_connection_list(F->get(), &data_connections); for (List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) { - if (clipboard->nodes.has(E->get().from_node) && clipboard->nodes.has(E->get().to_node)) { - clipboard->data_connections.insert(E->get()); } } @@ -4298,7 +4116,6 @@ void VisualScriptEditor::_menu_option(int p_what) { } for (Map<int, Ref<VisualScriptNode>>::Element *E = clipboard->nodes.front(); E; E = E->next()) { - Ref<VisualScriptNode> node = E->get()->duplicate(); int new_id = idc++; @@ -4317,13 +4134,11 @@ void VisualScriptEditor::_menu_option(int p_what) { } for (Set<VisualScript::SequenceConnection>::Element *E = clipboard->sequence_connections.front(); E; E = E->next()) { - undo_redo->add_do_method(script.ptr(), "sequence_connect", default_func, remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]); undo_redo->add_undo_method(script.ptr(), "sequence_disconnect", default_func, remap[E->get().from_node], E->get().from_output, remap[E->get().to_node]); } for (Set<VisualScript::DataConnection>::Element *E = clipboard->data_connections.front(); E; E = E->next()) { - undo_redo->add_do_method(script.ptr(), "data_connect", default_func, remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port); undo_redo->add_undo_method(script.ptr(), "data_disconnect", default_func, remap[E->get().from_node], E->get().from_port, remap[E->get().to_node], E->get().to_port); } @@ -4342,7 +4157,6 @@ void VisualScriptEditor::_menu_option(int p_what) { } } break; case EDIT_CREATE_FUNCTION: { - StringName function = ""; Map<int, Ref<VisualScriptNode>> nodes; Set<int> selections; @@ -4614,7 +4428,6 @@ void VisualScriptEditor::_get_ends(int p_node, const List<VisualScript::Sequence } void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { - TreeItem *ti = members->get_selected(); ERR_FAIL_COND(!ti); @@ -4632,7 +4445,6 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { Ref<Texture2D> edit_icon = Control::get_theme_icon("Edit", "EditorIcons"); if (ti->get_parent() == root->get_children()) { - member_type = MEMBER_FUNCTION; member_name = ti->get_text(0); member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT); @@ -4643,7 +4455,6 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { } if (ti->get_parent() == root->get_children()->get_next()) { - member_type = MEMBER_VARIABLE; member_name = ti->get_text(0); member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT); @@ -4654,7 +4465,6 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { } if (ti->get_parent() == root->get_children()->get_next()->get_next()) { - member_type = MEMBER_SIGNAL; member_name = ti->get_text(0); member_popup->add_icon_shortcut(edit_icon, ED_GET_SHORTCUT("visual_script_editor/edit_member"), MEMBER_EDIT); @@ -4666,10 +4476,8 @@ void VisualScriptEditor::_member_rmb_selected(const Vector2 &p_pos) { } void VisualScriptEditor::_member_option(int p_option) { - switch (member_type) { case MEMBER_FUNCTION: { - if (p_option == MEMBER_REMOVE) { //delete the function String name = member_name; @@ -4712,7 +4520,6 @@ void VisualScriptEditor::_member_option(int p_option) { } } break; case MEMBER_VARIABLE: { - String name = member_name; if (p_option == MEMBER_REMOVE) { @@ -4760,7 +4567,6 @@ void VisualScriptEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter } void VisualScriptEditor::_bind_methods() { - ClassDB::bind_method("_move_node", &VisualScriptEditor::_move_node); ClassDB::bind_method("_update_graph", &VisualScriptEditor::_update_graph, DEFVAL(-1)); @@ -4783,7 +4589,6 @@ void VisualScriptEditor::_bind_methods() { } VisualScriptEditor::VisualScriptEditor() { - if (!clipboard) { clipboard = memnew(Clipboard); } @@ -5015,14 +4820,12 @@ VisualScriptEditor::VisualScriptEditor() { } VisualScriptEditor::~VisualScriptEditor() { - undo_redo->clear_history(); // Avoid crashes. memdelete(signal_editor); memdelete(variable_editor); } static ScriptEditorBase *create_editor(const RES &p_resource) { - if (Object::cast_to<VisualScript>(*p_resource)) { return memnew(VisualScriptEditor); } @@ -5038,7 +4841,6 @@ void VisualScriptEditor::free_clipboard() { } static void register_editor_callback() { - ScriptEditor::register_create_script_editor_function(create_editor); ED_SHORTCUT("visual_script_editor/delete_selected", TTR("Delete Selected"), KEY_DELETE); @@ -5053,13 +4855,11 @@ static void register_editor_callback() { } void VisualScriptEditor::register_editor() { - // Too early to register stuff here, request a callback. EditorNode::add_plugin_init_callback(register_editor_callback); } Ref<VisualScriptNode> _VisualScriptEditor::create_node_custom(const String &p_name) { - Ref<VisualScriptCustomNode> node; node.instance(); node->set_script(singleton->custom_nodes[p_name]); diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index d9494e4d04..37063b2da1 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -152,7 +152,6 @@ class VisualScriptEditor : public ScriptEditorBase { String _validate_name(const String &p_name) const; struct Clipboard { - Map<int, Ref<VisualScriptNode>> nodes; Map<int, Vector2> nodes_positions; diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index 616a621845..e8fd3ef681 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -31,7 +31,6 @@ #include "visual_script_expression.h" bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_value) { - if (String(p_name) == "expression") { expression = p_value; expression_dirty = true; @@ -52,7 +51,6 @@ bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_val } if (String(p_name) == "input_count") { - int from = inputs.size(); inputs.resize(int(p_value)); for (int i = from; i < inputs.size(); i++) { @@ -70,17 +68,14 @@ bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_val } if (String(p_name).begins_with("input_")) { - int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int(); ERR_FAIL_INDEX_V(idx, inputs.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - inputs.write[idx].type = Variant::Type(int(p_value)); } else if (what == "name") { - inputs.write[idx].name = p_value; } else { return false; @@ -95,7 +90,6 @@ bool VisualScriptExpression::_set(const StringName &p_name, const Variant &p_val } bool VisualScriptExpression::_get(const StringName &p_name, Variant &r_ret) const { - if (String(p_name) == "expression") { r_ret = expression; return true; @@ -117,17 +111,14 @@ bool VisualScriptExpression::_get(const StringName &p_name, Variant &r_ret) cons } if (String(p_name).begins_with("input_")) { - int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int(); ERR_FAIL_INDEX_V(idx, inputs.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - r_ret = inputs[idx].type; } else if (what == "name") { - r_ret = inputs[idx].name; } else { return false; @@ -139,7 +130,6 @@ bool VisualScriptExpression::_get(const StringName &p_name, Variant &r_ret) cons return false; } void VisualScriptExpression::_get_property_list(List<PropertyInfo> *p_list) const { - String argt = "Any"; for (int i = 1; i < Variant::VARIANT_MAX; i++) { argt += "," + Variant::get_type_name(Variant::Type(i)); @@ -151,55 +141,44 @@ void VisualScriptExpression::_get_property_list(List<PropertyInfo> *p_list) cons p_list->push_back(PropertyInfo(Variant::BOOL, "sequenced")); for (int i = 0; i < inputs.size(); i++) { - p_list->push_back(PropertyInfo(Variant::INT, "input_" + itos(i) + "/type", PROPERTY_HINT_ENUM, argt)); p_list->push_back(PropertyInfo(Variant::STRING, "input_" + itos(i) + "/name")); } } int VisualScriptExpression::get_output_sequence_port_count() const { - return sequenced ? 1 : 0; } bool VisualScriptExpression::has_input_sequence_port() const { - return sequenced; } String VisualScriptExpression::get_output_sequence_port_text(int p_port) const { - return String(); } int VisualScriptExpression::get_input_value_port_count() const { - return inputs.size(); } int VisualScriptExpression::get_output_value_port_count() const { - return 1; } PropertyInfo VisualScriptExpression::get_input_value_port_info(int p_idx) const { - return PropertyInfo(inputs[p_idx].type, inputs[p_idx].name); } PropertyInfo VisualScriptExpression::get_output_value_port_info(int p_idx) const { - return PropertyInfo(output_type, "result"); } String VisualScriptExpression::get_caption() const { - return "Expression"; } String VisualScriptExpression::get_text() const { - return expression; } Error VisualScriptExpression::_get_token(Token &r_token) { - while (true) { #define GET_CHAR() (str_ofs >= expression.length() ? 0 : expression[str_ofs++]) @@ -210,58 +189,47 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } switch (cchar) { - case 0: { r_token.type = TK_EOF; return OK; } break; case '{': { - r_token.type = TK_CURLY_BRACKET_OPEN; return OK; }; case '}': { - r_token.type = TK_CURLY_BRACKET_CLOSE; return OK; }; case '[': { - r_token.type = TK_BRACKET_OPEN; return OK; }; case ']': { - r_token.type = TK_BRACKET_CLOSE; return OK; }; case '(': { - r_token.type = TK_PARENTHESIS_OPEN; return OK; }; case ')': { - r_token.type = TK_PARENTHESIS_CLOSE; return OK; }; case ',': { - r_token.type = TK_COMMA; return OK; }; case ':': { - r_token.type = TK_COLON; return OK; }; case '.': { - r_token.type = TK_PERIOD; return OK; }; case '=': { - cchar = GET_CHAR(); if (cchar == '=') { r_token.type = TK_OP_EQUAL; @@ -273,7 +241,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '!': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_NOT_EQUAL; str_ofs++; @@ -283,7 +250,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '>': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_GREATER_EQUAL; str_ofs++; @@ -296,7 +262,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '<': { - if (expression[str_ofs] == '=') { r_token.type = TK_OP_LESS_EQUAL; str_ofs++; @@ -329,7 +294,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '&': { - if (expression[str_ofs] == '&') { r_token.type = TK_OP_AND; str_ofs++; @@ -339,7 +303,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '|': { - if (expression[str_ofs] == '|') { r_token.type = TK_OP_OR; str_ofs++; @@ -349,22 +312,18 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; }; case '^': { - r_token.type = TK_OP_BIT_XOR; return OK; }; case '~': { - r_token.type = TK_OP_BIT_INVERT; return OK; }; case '"': { - String str; while (true) { - CharType ch = GET_CHAR(); if (ch == 0) { @@ -385,7 +344,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { CharType res = 0; switch (next) { - case 'b': res = 8; break; @@ -412,7 +370,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return ERR_PARSE_ERROR; } if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) { - _set_error("Malformed hex constant in string"); r_token.type = TK_ERROR; return ERR_PARSE_ERROR; @@ -454,7 +411,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } break; default: { - if (cchar <= 32) { break; } @@ -476,10 +432,8 @@ Error VisualScriptExpression::_get_token(Token &r_token) { bool is_float = false; while (true) { - switch (reading) { case READING_INT: { - if (c >= '0' && c <= '9') { //pass } else if (c == '.') { @@ -493,9 +447,7 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } break; case READING_DEC: { - if (c >= '0' && c <= '9') { - } else if (c == 'e') { reading = READING_EXP; @@ -505,7 +457,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } break; case READING_EXP: { - if (c >= '0' && c <= '9') { exp_beg = true; @@ -537,12 +488,10 @@ Error VisualScriptExpression::_get_token(Token &r_token) { return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { - String id; bool first = true; while ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_' || (!first && cchar >= '0' && cchar <= '9')) { - id += String::chr(cchar); cchar = GET_CHAR(); first = false; @@ -582,7 +531,6 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } else if (id == "self") { r_token.type = TK_SELF; } else { - for (int i = 0; i < Variant::VARIANT_MAX; i++) { if (id == Variant::get_type_name(Variant::Type(i))) { r_token.type = TK_BASIC_TYPE; @@ -657,7 +605,6 @@ const char *VisualScriptExpression::token_name[TK_MAX] = { }; VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { - Vector<Expression> expression; while (true) { @@ -675,7 +622,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { DictionaryNode *dn = alloc_node<DictionaryNode>(); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_CURLY_BRACKET_CLOSE) { @@ -719,7 +665,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { ArrayNode *an = alloc_node<ArrayNode>(); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_BRACKET_CLOSE) { @@ -760,7 +705,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } break; case TK_IDENTIFIER: { - String what = tk.value; int index = -1; for (int i = 0; i < inputs.size(); i++) { @@ -780,7 +724,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } } break; case TK_SELF: { - SelfNode *self = alloc_node<SelfNode>(); expr = self; } break; @@ -803,7 +746,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { constructor->data_type = bt; while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -844,7 +786,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { bifunc->func = VisualScriptBuiltinFunc::BuiltinFunc(int(tk.value)); while (true) { - int cofs = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -878,7 +819,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } break; case TK_OP_SUB: { - Expression e; e.is_op = true; e.op = Variant::OP_NEGATE; @@ -886,7 +826,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { continue; } break; case TK_OP_NOT: { - Expression e; e.is_op = true; e.op = Variant::OP_NOT; @@ -950,7 +889,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { func_call->base = expr; while (true) { - int cofs3 = str_ofs; _get_token(tk); if (tk.type == TK_PARENTHESIS_CLOSE) { @@ -1099,15 +1037,12 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { /* Reduce the set set of expressions and place them in an operator tree, respecting precedence */ while (expression.size() > 1) { - int next_op = -1; int min_priority = 0xFFFFF; bool is_unary = false; for (int i = 0; i < expression.size(); i++) { - if (!expression[i].is_op) { - continue; } @@ -1116,7 +1051,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { bool unary = false; switch (expression[i].op) { - case Variant::OP_BIT_NEGATE: priority = 0; unary = true; @@ -1212,17 +1146,14 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } if (next_op == -1) { - _set_error("Yet another parser bug...."); ERR_FAIL_V(nullptr); } // OK! create operator.. if (is_unary) { - int expr_pos = next_op; while (expression[expr_pos].is_op) { - expr_pos++; if (expr_pos == expression.size()) { //can happen.. @@ -1233,7 +1164,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { //consecutively do unary operators for (int i = expr_pos - 1; i >= next_op; i--) { - OperatorNode *op = alloc_node<OperatorNode>(); op->op = expression[i].op; op->nodes[0] = expression[i + 1].node; @@ -1244,7 +1174,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } } else { - if (next_op < 1 || next_op >= (expression.size() - 1)) { _set_error("Parser bug..."); ERR_FAIL_V(nullptr); @@ -1254,7 +1183,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { op->op = expression[next_op].op; if (expression[next_op - 1].is_op) { - _set_error("Parser bug..."); ERR_FAIL_V(nullptr); } @@ -1283,7 +1211,6 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } bool VisualScriptExpression::_compile_expression() { - if (!expression_dirty) return error_set; @@ -1320,25 +1247,20 @@ public: //virtual int get_working_memory_size() const { return 0; } //execute by parsing the tree directly virtual bool _execute(const Variant **p_inputs, VisualScriptExpression::ENode *p_node, Variant &r_ret, String &r_error_str, Callable::CallError &ce) { - switch (p_node->type) { case VisualScriptExpression::ENode::TYPE_INPUT: { - const VisualScriptExpression::InputNode *in = static_cast<const VisualScriptExpression::InputNode *>(p_node); r_ret = *p_inputs[in->index]; } break; case VisualScriptExpression::ENode::TYPE_CONSTANT: { - const VisualScriptExpression::ConstantNode *c = static_cast<const VisualScriptExpression::ConstantNode *>(p_node); r_ret = c->value; } break; case VisualScriptExpression::ENode::TYPE_SELF: { - r_ret = instance->get_owner_ptr(); } break; case VisualScriptExpression::ENode::TYPE_OPERATOR: { - const VisualScriptExpression::OperatorNode *op = static_cast<const VisualScriptExpression::OperatorNode *>(p_node); Variant a; @@ -1363,7 +1285,6 @@ public: } break; case VisualScriptExpression::ENode::TYPE_INDEX: { - const VisualScriptExpression::IndexNode *index = static_cast<const VisualScriptExpression::IndexNode *>(p_node); Variant base; @@ -1386,7 +1307,6 @@ public: } break; case VisualScriptExpression::ENode::TYPE_NAMED_INDEX: { - const VisualScriptExpression::NamedIndexNode *index = static_cast<const VisualScriptExpression::NamedIndexNode *>(p_node); Variant base; @@ -1408,7 +1328,6 @@ public: Array arr; arr.resize(array->array.size()); for (int i = 0; i < array->array.size(); i++) { - Variant value; bool ret = _execute(p_inputs, array->array[i], value, r_error_str, ce); if (ret) @@ -1424,7 +1343,6 @@ public: Dictionary d; for (int i = 0; i < dictionary->dict.size(); i += 2) { - Variant key; bool ret = _execute(p_inputs, dictionary->dict[i + 0], key, r_error_str, ce); if (ret) @@ -1441,7 +1359,6 @@ public: r_ret = d; } break; case VisualScriptExpression::ENode::TYPE_CONSTRUCTOR: { - const VisualScriptExpression::ConstructorNode *constructor = static_cast<const VisualScriptExpression::ConstructorNode *>(p_node); Vector<Variant> arr; @@ -1450,7 +1367,6 @@ public: argp.resize(constructor->arguments.size()); for (int i = 0; i < constructor->arguments.size(); i++) { - Variant value; bool ret = _execute(p_inputs, constructor->arguments[i], value, r_error_str, ce); if (ret) @@ -1468,7 +1384,6 @@ public: } break; case VisualScriptExpression::ENode::TYPE_BUILTIN_FUNC: { - const VisualScriptExpression::BuiltinFuncNode *bifunc = static_cast<const VisualScriptExpression::BuiltinFuncNode *>(p_node); Vector<Variant> arr; @@ -1477,7 +1392,6 @@ public: argp.resize(bifunc->arguments.size()); for (int i = 0; i < bifunc->arguments.size(); i++) { - Variant value; bool ret = _execute(p_inputs, bifunc->arguments[i], value, r_error_str, ce); if (ret) @@ -1495,7 +1409,6 @@ public: } break; case VisualScriptExpression::ENode::TYPE_CALL: { - const VisualScriptExpression::CallNode *call = static_cast<const VisualScriptExpression::CallNode *>(p_node); Variant base; @@ -1509,7 +1422,6 @@ public: argp.resize(call->arguments.size()); for (int i = 0; i < call->arguments.size(); i++) { - Variant value; bool ret2 = _execute(p_inputs, call->arguments[i], value, r_error_str, ce); if (ret2) @@ -1531,7 +1443,6 @@ public: } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!expression->root || expression->error_set) { r_error_str = expression->error_str; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -1545,7 +1456,6 @@ public: #ifdef DEBUG_ENABLED if (!error && expression->output_type != Variant::NIL && !Variant::can_convert_strict(p_outputs[0]->get_type(), expression->output_type)) { - r_error_str += "Can't convert expression result from " + Variant::get_type_name(p_outputs[0]->get_type()) + " to " + Variant::get_type_name(expression->output_type) + "."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; } @@ -1556,7 +1466,6 @@ public: }; VisualScriptNodeInstance *VisualScriptExpression::instance(VisualScriptInstance *p_instance) { - _compile_expression(); VisualScriptNodeInstanceExpression *instance = memnew(VisualScriptNodeInstanceExpression); instance->instance = p_instance; @@ -1574,13 +1483,11 @@ VisualScriptExpression::VisualScriptExpression() { } VisualScriptExpression::~VisualScriptExpression() { - if (nodes) { memdelete(nodes); } } void register_visual_script_expression_node() { - VisualScriptLanguage::singleton->add_register_func("operators/expression", create_node_generic<VisualScriptExpression>); } diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index 61b50ff99d..ed0857ab9f 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -35,12 +35,10 @@ #include "visual_script_builtin_funcs.h" class VisualScriptExpression : public VisualScriptNode { - GDCLASS(VisualScriptExpression, VisualScriptNode); friend class VisualScriptNodeInstanceExpression; struct Input { - Variant::Type type; String name; @@ -101,7 +99,6 @@ class VisualScriptExpression : public VisualScriptNode { static const char *token_name[TK_MAX]; struct Token { - TokenType type; Variant value; }; @@ -119,7 +116,6 @@ class VisualScriptExpression : public VisualScriptNode { bool error_set; struct ENode { - enum Type { TYPE_INPUT, TYPE_CONSTANT, @@ -147,7 +143,6 @@ class VisualScriptExpression : public VisualScriptNode { }; struct Expression { - bool is_op; union { Variant::Operator op; @@ -158,7 +153,6 @@ class VisualScriptExpression : public VisualScriptNode { ENode *_parse_expression(); struct InputNode : public ENode { - int index; InputNode() { type = TYPE_INPUT; @@ -166,7 +160,6 @@ class VisualScriptExpression : public VisualScriptNode { }; struct ConstantNode : public ENode { - Variant value; ConstantNode() { type = TYPE_CONSTANT; @@ -174,7 +167,6 @@ class VisualScriptExpression : public VisualScriptNode { }; struct OperatorNode : public ENode { - Variant::Operator op; ENode *nodes[2]; @@ -185,7 +177,6 @@ class VisualScriptExpression : public VisualScriptNode { }; struct SelfNode : public ENode { - SelfNode() { type = TYPE_SELF; } diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 8a644c6860..1f04ea8301 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -39,31 +39,25 @@ ////////////////////////////////////////// int VisualScriptReturn::get_output_sequence_port_count() const { - return 0; } bool VisualScriptReturn::has_input_sequence_port() const { - return true; } int VisualScriptReturn::get_input_value_port_count() const { - return with_value ? 1 : 0; } int VisualScriptReturn::get_output_value_port_count() const { - return 0; } String VisualScriptReturn::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptReturn::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "result"; pinfo.type = type; @@ -74,17 +68,14 @@ PropertyInfo VisualScriptReturn::get_output_value_port_info(int p_idx) const { } String VisualScriptReturn::get_caption() const { - return "Return"; } String VisualScriptReturn::get_text() const { - return get_name(); } void VisualScriptReturn::set_return_type(Variant::Type p_type) { - if (type == p_type) return; type = p_type; @@ -92,7 +83,6 @@ void VisualScriptReturn::set_return_type(Variant::Type p_type) { } Variant::Type VisualScriptReturn::get_return_type() const { - return type; } @@ -105,12 +95,10 @@ void VisualScriptReturn::set_enable_return_value(bool p_enable) { } bool VisualScriptReturn::is_return_value_enabled() const { - return with_value; } void VisualScriptReturn::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_return_type", "type"), &VisualScriptReturn::set_return_type); ClassDB::bind_method(D_METHOD("get_return_type"), &VisualScriptReturn::get_return_type); ClassDB::bind_method(D_METHOD("set_enable_return_value", "enable"), &VisualScriptReturn::set_enable_return_value); @@ -136,7 +124,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (with_value) { *p_working_mem = *p_inputs[0]; return STEP_EXIT_FUNCTION_BIT; @@ -148,7 +135,6 @@ public: }; VisualScriptNodeInstance *VisualScriptReturn::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceReturn *instance = memnew(VisualScriptNodeInstanceReturn); instance->node = this; instance->instance = p_instance; @@ -157,14 +143,12 @@ VisualScriptNodeInstance *VisualScriptReturn::instance(VisualScriptInstance *p_i } VisualScriptReturn::VisualScriptReturn() { - with_value = false; type = Variant::NIL; } template <bool with_value> static Ref<VisualScriptNode> create_return_node(const String &p_name) { - Ref<VisualScriptReturn> node; node.instance(); node->set_enable_return_value(with_value); @@ -176,26 +160,21 @@ static Ref<VisualScriptNode> create_return_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptCondition::get_output_sequence_port_count() const { - return 3; } bool VisualScriptCondition::has_input_sequence_port() const { - return true; } int VisualScriptCondition::get_input_value_port_count() const { - return 1; } int VisualScriptCondition::get_output_value_port_count() const { - return 0; } String VisualScriptCondition::get_output_sequence_port_text(int p_port) const { - if (p_port == 0) return "true"; else if (p_port == 1) @@ -205,7 +184,6 @@ String VisualScriptCondition::get_output_sequence_port_text(int p_port) const { } PropertyInfo VisualScriptCondition::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "cond"; pinfo.type = Variant::BOOL; @@ -216,12 +194,10 @@ PropertyInfo VisualScriptCondition::get_output_value_port_info(int p_idx) const } String VisualScriptCondition::get_caption() const { - return "Condition"; } String VisualScriptCondition::get_text() const { - return "if (cond) is: "; } @@ -238,7 +214,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) return 2; else if (p_inputs[0]->operator bool()) @@ -249,7 +224,6 @@ public: }; VisualScriptNodeInstance *VisualScriptCondition::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceCondition *instance = memnew(VisualScriptNodeInstanceCondition); instance->node = this; instance->instance = p_instance; @@ -264,26 +238,21 @@ VisualScriptCondition::VisualScriptCondition() { ////////////////////////////////////////// int VisualScriptWhile::get_output_sequence_port_count() const { - return 2; } bool VisualScriptWhile::has_input_sequence_port() const { - return true; } int VisualScriptWhile::get_input_value_port_count() const { - return 1; } int VisualScriptWhile::get_output_value_port_count() const { - return 0; } String VisualScriptWhile::get_output_sequence_port_text(int p_port) const { - if (p_port == 0) return "repeat"; else @@ -291,7 +260,6 @@ String VisualScriptWhile::get_output_sequence_port_text(int p_port) const { } PropertyInfo VisualScriptWhile::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "cond"; pinfo.type = Variant::BOOL; @@ -302,12 +270,10 @@ PropertyInfo VisualScriptWhile::get_output_value_port_info(int p_idx) const { } String VisualScriptWhile::get_caption() const { - return "While"; } String VisualScriptWhile::get_text() const { - return "while (cond): "; } @@ -324,7 +290,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool keep_going = p_inputs[0]->operator bool(); if (keep_going) @@ -335,7 +300,6 @@ public: }; VisualScriptNodeInstance *VisualScriptWhile::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceWhile *instance = memnew(VisualScriptNodeInstanceWhile); instance->node = this; instance->instance = p_instance; @@ -349,26 +313,21 @@ VisualScriptWhile::VisualScriptWhile() { ////////////////////////////////////////// int VisualScriptIterator::get_output_sequence_port_count() const { - return 2; } bool VisualScriptIterator::has_input_sequence_port() const { - return true; } int VisualScriptIterator::get_input_value_port_count() const { - return 1; } int VisualScriptIterator::get_output_value_port_count() const { - return 1; } String VisualScriptIterator::get_output_sequence_port_text(int p_port) const { - if (p_port == 0) return "each"; else @@ -376,7 +335,6 @@ String VisualScriptIterator::get_output_sequence_port_text(int p_port) const { } PropertyInfo VisualScriptIterator::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "input"; pinfo.type = Variant::NIL; @@ -389,12 +347,10 @@ PropertyInfo VisualScriptIterator::get_output_value_port_info(int p_idx) const { return pinfo; } String VisualScriptIterator::get_caption() const { - return "Iterator"; } String VisualScriptIterator::get_text() const { - return "for (elem) in (input): "; } @@ -411,7 +367,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_BEGIN_SEQUENCE) { p_working_mem[0] = *p_inputs[0]; bool valid; @@ -462,7 +417,6 @@ public: }; VisualScriptNodeInstance *VisualScriptIterator::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceIterator *instance = memnew(VisualScriptNodeInstanceIterator); instance->node = this; instance->instance = p_instance; @@ -477,26 +431,21 @@ VisualScriptIterator::VisualScriptIterator() { ////////////////////////////////////////// int VisualScriptSequence::get_output_sequence_port_count() const { - return steps; } bool VisualScriptSequence::has_input_sequence_port() const { - return true; } int VisualScriptSequence::get_input_value_port_count() const { - return 0; } int VisualScriptSequence::get_output_value_port_count() const { - return 1; } String VisualScriptSequence::get_output_sequence_port_text(int p_port) const { - return itos(p_port + 1); } @@ -507,17 +456,14 @@ PropertyInfo VisualScriptSequence::get_output_value_port_info(int p_idx) const { return PropertyInfo(Variant::INT, "current"); } String VisualScriptSequence::get_caption() const { - return "Sequence"; } String VisualScriptSequence::get_text() const { - return "in order: "; } void VisualScriptSequence::set_steps(int p_steps) { - ERR_FAIL_COND(p_steps < 1); if (steps == p_steps) return; @@ -527,12 +473,10 @@ void VisualScriptSequence::set_steps(int p_steps) { } int VisualScriptSequence::get_steps() const { - return steps; } void VisualScriptSequence::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_steps", "steps"), &VisualScriptSequence::set_steps); ClassDB::bind_method(D_METHOD("get_steps"), &VisualScriptSequence::get_steps); @@ -550,9 +494,7 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_BEGIN_SEQUENCE) { - p_working_mem[0] = 0; } @@ -570,7 +512,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSequence::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSequence *instance = memnew(VisualScriptNodeInstanceSequence); instance->node = this; instance->instance = p_instance; @@ -578,7 +519,6 @@ VisualScriptNodeInstance *VisualScriptSequence::instance(VisualScriptInstance *p return instance; } VisualScriptSequence::VisualScriptSequence() { - steps = 1; } @@ -587,26 +527,21 @@ VisualScriptSequence::VisualScriptSequence() { ////////////////////////////////////////// int VisualScriptSwitch::get_output_sequence_port_count() const { - return case_values.size() + 1; } bool VisualScriptSwitch::has_input_sequence_port() const { - return true; } int VisualScriptSwitch::get_input_value_port_count() const { - return case_values.size() + 1; } int VisualScriptSwitch::get_output_value_port_count() const { - return 0; } String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const { - if (p_port == case_values.size()) return "done"; @@ -614,7 +549,6 @@ String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const { } PropertyInfo VisualScriptSwitch::get_input_value_port_info(int p_idx) const { - if (p_idx < case_values.size()) { return PropertyInfo(case_values[p_idx].type, " ="); } else @@ -622,17 +556,14 @@ PropertyInfo VisualScriptSwitch::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptSwitch::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptSwitch::get_caption() const { - return "Switch"; } String VisualScriptSwitch::get_text() const { - return "'input' is:"; } @@ -646,13 +577,11 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) { return case_count; //exit } for (int i = 0; i < case_count; i++) { - if (*p_inputs[i] == *p_inputs[case_count]) { return i | STEP_FLAG_PUSH_STACK_BIT; } @@ -663,7 +592,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSwitch::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSwitch *instance = memnew(VisualScriptNodeInstanceSwitch); instance->instance = p_instance; instance->case_count = case_values.size(); @@ -671,7 +599,6 @@ VisualScriptNodeInstance *VisualScriptSwitch::instance(VisualScriptInstance *p_i } bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) { - if (String(p_name) == "case_count") { case_values.resize(p_value); _change_notify(); @@ -680,7 +607,6 @@ bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) } if (String(p_name).begins_with("case/")) { - int idx = String(p_name).get_slice("/", 1).to_int(); ERR_FAIL_INDEX_V(idx, case_values.size(), false); @@ -695,14 +621,12 @@ bool VisualScriptSwitch::_set(const StringName &p_name, const Variant &p_value) } bool VisualScriptSwitch::_get(const StringName &p_name, Variant &r_ret) const { - if (String(p_name) == "case_count") { r_ret = case_values.size(); return true; } if (String(p_name).begins_with("case/")) { - int idx = String(p_name).get_slice("/", 1).to_int(); ERR_FAIL_INDEX_V(idx, case_values.size(), false); @@ -713,7 +637,6 @@ bool VisualScriptSwitch::_get(const StringName &p_name, Variant &r_ret) const { return false; } void VisualScriptSwitch::_get_property_list(List<PropertyInfo> *p_list) const { - p_list->push_back(PropertyInfo(Variant::INT, "case_count", PROPERTY_HINT_RANGE, "0,128")); String argt = "Any"; @@ -737,46 +660,37 @@ VisualScriptSwitch::VisualScriptSwitch() { ////////////////////////////////////////// int VisualScriptTypeCast::get_output_sequence_port_count() const { - return 2; } bool VisualScriptTypeCast::has_input_sequence_port() const { - return true; } int VisualScriptTypeCast::get_input_value_port_count() const { - return 1; } int VisualScriptTypeCast::get_output_value_port_count() const { - return 1; } String VisualScriptTypeCast::get_output_sequence_port_text(int p_port) const { - return p_port == 0 ? "yes" : "no"; } PropertyInfo VisualScriptTypeCast::get_input_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, "instance"); } PropertyInfo VisualScriptTypeCast::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, "", PROPERTY_HINT_TYPE_STRING, get_base_type()); } String VisualScriptTypeCast::get_caption() const { - return "Type Cast"; } String VisualScriptTypeCast::get_text() const { - if (script != String()) return "Is " + script.get_file() + "?"; else @@ -784,7 +698,6 @@ String VisualScriptTypeCast::get_text() const { } void VisualScriptTypeCast::set_base_type(const StringName &p_type) { - if (base_type == p_type) return; @@ -794,12 +707,10 @@ void VisualScriptTypeCast::set_base_type(const StringName &p_type) { } StringName VisualScriptTypeCast::get_base_type() const { - return base_type; } void VisualScriptTypeCast::set_base_script(const String &p_path) { - if (script == p_path) return; @@ -808,12 +719,10 @@ void VisualScriptTypeCast::set_base_script(const String &p_path) { ports_changed_notify(); } String VisualScriptTypeCast::get_base_script() const { - return script; } VisualScriptTypeCast::TypeGuess VisualScriptTypeCast::guess_output_type(TypeGuess *p_inputs, int p_output) const { - TypeGuess tg; tg.type = Variant::OBJECT; if (script != String()) { @@ -837,7 +746,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Object *obj = *p_inputs[0]; *p_outputs[0] = Variant(); @@ -849,7 +757,6 @@ public: } if (script != String()) { - Ref<Script> obj_script = obj->get_script(); if (!obj_script.is_valid()) { return 1; //well, definitely not the script because object we got has no script. @@ -867,7 +774,6 @@ public: } while (obj_script.is_valid()) { - if (cast_script == obj_script) { *p_outputs[0] = *p_inputs[0]; //copy return 0; // it is the script, yey @@ -888,7 +794,6 @@ public: }; VisualScriptNodeInstance *VisualScriptTypeCast::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceTypeCast *instance = memnew(VisualScriptNodeInstanceTypeCast); instance->instance = p_instance; instance->base_type = base_type; @@ -897,7 +802,6 @@ VisualScriptNodeInstance *VisualScriptTypeCast::instance(VisualScriptInstance *p } void VisualScriptTypeCast::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "type"), &VisualScriptTypeCast::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptTypeCast::get_base_type); @@ -921,12 +825,10 @@ void VisualScriptTypeCast::_bind_methods() { } VisualScriptTypeCast::VisualScriptTypeCast() { - base_type = "Object"; } void register_visual_script_flow_control_nodes() { - VisualScriptLanguage::singleton->add_register_func("flow_control/return", create_return_node<false>); VisualScriptLanguage::singleton->add_register_func("flow_control/return_with_value", create_return_node<true>); VisualScriptLanguage::singleton->add_register_func("flow_control/condition", create_node_generic<VisualScriptCondition>); diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index 8597d051db..45b56b3073 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptReturn : public VisualScriptNode { - GDCLASS(VisualScriptReturn, VisualScriptNode); Variant::Type type; @@ -71,7 +70,6 @@ public: }; class VisualScriptCondition : public VisualScriptNode { - GDCLASS(VisualScriptCondition, VisualScriptNode); protected: @@ -99,7 +97,6 @@ public: }; class VisualScriptWhile : public VisualScriptNode { - GDCLASS(VisualScriptWhile, VisualScriptNode); protected: @@ -127,7 +124,6 @@ public: }; class VisualScriptIterator : public VisualScriptNode { - GDCLASS(VisualScriptIterator, VisualScriptNode); protected: @@ -155,7 +151,6 @@ public: }; class VisualScriptSequence : public VisualScriptNode { - GDCLASS(VisualScriptSequence, VisualScriptNode); int steps; @@ -188,7 +183,6 @@ public: }; class VisualScriptSwitch : public VisualScriptNode { - GDCLASS(VisualScriptSwitch, VisualScriptNode); struct Case { @@ -230,7 +224,6 @@ public: }; class VisualScriptTypeCast : public VisualScriptNode { - GDCLASS(VisualScriptTypeCast, VisualScriptNode); StringName base_type; diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index 3b6ae369ae..4ba0c27ec0 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -42,7 +42,6 @@ ////////////////////////////////////////// int VisualScriptFunctionCall::get_output_sequence_port_count() const { - if ((method_cache.flags & METHOD_FLAG_CONST && call_mode != CALL_MODE_INSTANCE) || (call_mode == CALL_MODE_BASIC_TYPE && Variant::is_method_const(basic_type, function))) return 0; else @@ -50,13 +49,11 @@ int VisualScriptFunctionCall::get_output_sequence_port_count() const { } bool VisualScriptFunctionCall::has_input_sequence_port() const { - return !((method_cache.flags & METHOD_FLAG_CONST && call_mode != CALL_MODE_INSTANCE) || (call_mode == CALL_MODE_BASIC_TYPE && Variant::is_method_const(basic_type, function))); } #ifdef TOOLS_ENABLED static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) return nullptr; @@ -76,7 +73,6 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const #endif Node *VisualScriptFunctionCall::_get_base_node() const { - #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); if (!script.is_valid()) @@ -111,7 +107,6 @@ Node *VisualScriptFunctionCall::_get_base_node() const { } StringName VisualScriptFunctionCall::_get_base_type() const { - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) return get_visual_script()->get_instance_base_type(); else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { @@ -124,13 +119,11 @@ StringName VisualScriptFunctionCall::_get_base_type() const { } int VisualScriptFunctionCall::get_input_value_port_count() const { - if (call_mode == CALL_MODE_BASIC_TYPE) { Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type, function); return types.size() + (rpc_call_mode >= RPC_RELIABLE_TO_ID ? 1 : 0) + 1; } else { - MethodBind *mb = ClassDB::get_method(_get_base_type(), function); if (mb) { int defaulted_args = mb->get_argument_count() < use_default_args ? mb->get_argument_count() : use_default_args; @@ -142,9 +135,7 @@ int VisualScriptFunctionCall::get_input_value_port_count() const { } } int VisualScriptFunctionCall::get_output_value_port_count() const { - if (call_mode == CALL_MODE_BASIC_TYPE) { - bool returns = false; Variant::get_method_return_type(basic_type, function, &returns); return returns ? 1 : 0; @@ -166,12 +157,10 @@ int VisualScriptFunctionCall::get_output_value_port_count() const { } String VisualScriptFunctionCall::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) const { - if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) { if (p_idx == 0) { PropertyInfo pi; @@ -184,7 +173,6 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons } if (rpc_call_mode >= RPC_RELIABLE_TO_ID) { - if (p_idx == 0) { return PropertyInfo(Variant::INT, "peer_id"); } else { @@ -195,13 +183,11 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons #ifdef DEBUG_METHODS_ENABLED if (call_mode == CALL_MODE_BASIC_TYPE) { - Vector<StringName> names = Variant::get_method_argument_names(basic_type, function); Vector<Variant::Type> types = Variant::get_method_argument_types(basic_type, function); return PropertyInfo(types[p_idx], names[p_idx]); } else { - MethodBind *mb = ClassDB::get_method(_get_base_type(), function); if (mb) { return mb->get_argument_info(p_idx); @@ -219,14 +205,11 @@ PropertyInfo VisualScriptFunctionCall::get_input_value_port_info(int p_idx) cons } PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) const { - #ifdef DEBUG_METHODS_ENABLED if (call_mode == CALL_MODE_BASIC_TYPE) { - return PropertyInfo(Variant::get_method_return_type(basic_type, function), ""); } else { - if (call_mode == CALL_MODE_INSTANCE) { if (p_idx == 0) { return PropertyInfo(Variant::OBJECT, "pass", PROPERTY_HINT_TYPE_STRING, get_base_type()); @@ -273,7 +256,6 @@ String VisualScriptFunctionCall::get_caption() const { } String VisualScriptFunctionCall::get_text() const { - if (rpc_call_mode) { return "RPC"; } @@ -281,7 +263,6 @@ String VisualScriptFunctionCall::get_text() const { } void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { - if (basic_type == p_type) return; basic_type = p_type; @@ -291,12 +272,10 @@ void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { } Variant::Type VisualScriptFunctionCall::get_basic_type() const { - return basic_type; } void VisualScriptFunctionCall::set_base_type(const StringName &p_type) { - if (base_type == p_type) return; @@ -306,12 +285,10 @@ void VisualScriptFunctionCall::set_base_type(const StringName &p_type) { } StringName VisualScriptFunctionCall::get_base_type() const { - return base_type; } void VisualScriptFunctionCall::set_base_script(const String &p_path) { - if (base_script == p_path) return; @@ -321,12 +298,10 @@ void VisualScriptFunctionCall::set_base_script(const String &p_path) { } String VisualScriptFunctionCall::get_base_script() const { - return base_script; } void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { - if (singleton == p_type) return; @@ -341,7 +316,6 @@ void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { } StringName VisualScriptFunctionCall::get_singleton() const { - return singleton; } @@ -350,7 +324,6 @@ void VisualScriptFunctionCall::_update_method_cache() { Ref<Script> script; if (call_mode == CALL_MODE_NODE_PATH) { - Node *node = _get_base_node(); if (node) { type = node->get_class(); @@ -358,7 +331,6 @@ void VisualScriptFunctionCall::_update_method_cache() { script = node->get_script(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { type = get_visual_script()->get_instance_base_type(); base_type = type; //cache, too @@ -366,7 +338,6 @@ void VisualScriptFunctionCall::_update_method_cache() { } } else if (call_mode == CALL_MODE_SINGLETON) { - Object *obj = Engine::get_singleton()->get_singleton_object(singleton); if (obj) { type = obj->get_class(); @@ -374,17 +345,13 @@ void VisualScriptFunctionCall::_update_method_cache() { } } else if (call_mode == CALL_MODE_INSTANCE) { - type = base_type; if (base_script != String()) { - if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - script = Ref<Resource>(ResourceCache::get(base_script)); } else { return; @@ -421,14 +388,12 @@ void VisualScriptFunctionCall::_update_method_cache() { } } } else if (script.is_valid() && script->has_method(function)) { - method_cache = script->get_method_info(function); use_default_args = method_cache.default_arguments.size(); } } void VisualScriptFunctionCall::set_function(const StringName &p_type) { - if (function == p_type) return; @@ -446,12 +411,10 @@ void VisualScriptFunctionCall::set_function(const StringName &p_type) { ports_changed_notify(); } StringName VisualScriptFunctionCall::get_function() const { - return function; } void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) { - if (base_path == p_type) return; @@ -461,12 +424,10 @@ void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) { } NodePath VisualScriptFunctionCall::get_base_path() const { - return base_path; } void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) return; @@ -475,12 +436,10 @@ void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) { ports_changed_notify(); } VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() const { - return call_mode; } void VisualScriptFunctionCall::set_use_default_args(int p_amount) { - if (use_default_args == p_amount) return; @@ -489,7 +448,6 @@ void VisualScriptFunctionCall::set_use_default_args(int p_amount) { } void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCallMode p_mode) { - if (rpc_call_mode == p_mode) return; rpc_call_mode = p_mode; @@ -498,22 +456,18 @@ void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCa } VisualScriptFunctionCall::RPCCallMode VisualScriptFunctionCall::get_rpc_call_mode() const { - return rpc_call_mode; } int VisualScriptFunctionCall::get_use_default_args() const { - return use_default_args; } void VisualScriptFunctionCall::set_validate(bool p_amount) { - validate = p_amount; } bool VisualScriptFunctionCall::get_validate() const { - return validate; } @@ -523,12 +477,10 @@ void VisualScriptFunctionCall::_set_argument_cache(const Dictionary &p_cache) { } Dictionary VisualScriptFunctionCall::_get_argument_cache() const { - return method_cache; } void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const { - if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -568,7 +520,6 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { - Node *bnode = _get_base_node(); if (bnode) { property.hint_string = bnode->get_path(); //convert to loong string @@ -577,9 +528,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } if (property.name == "function") { - if (call_mode == CALL_MODE_BASIC_TYPE) { - property.hint = PROPERTY_HINT_METHOD_OF_VARIANT_TYPE; property.hint_string = Variant::get_type_name(basic_type); @@ -587,13 +536,11 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT; property.hint_string = itos(get_visual_script()->get_instance_id()); } else if (call_mode == CALL_MODE_SINGLETON) { - Object *obj = Engine::get_singleton()->get_singleton_object(singleton); if (obj) { property.hint = PROPERTY_HINT_METHOD_OF_INSTANCE; property.hint_string = itos(obj->get_instance_id()); } else { - property.hint = PROPERTY_HINT_METHOD_OF_BASE_TYPE; property.hint_string = base_type; //should be cached } @@ -603,15 +550,12 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (base_script != String()) { if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script)); if (script.is_valid()) { - property.hint = PROPERTY_HINT_METHOD_OF_SCRIPT; property.hint_string = itos(script->get_instance_id()); } @@ -631,18 +575,15 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } if (property.name == "use_default_args") { - property.hint = PROPERTY_HINT_RANGE; int mc = 0; if (call_mode == CALL_MODE_BASIC_TYPE) { - mc = Variant::get_method_default_arguments(basic_type, function).size(); } else { MethodBind *mb = ClassDB::get_method(_get_base_type(), function); if (mb) { - mc = mb->get_default_argument_count(); } } @@ -650,7 +591,6 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (mc == 0) { property.usage = 0; //do not show } else { - property.hint_string = "0," + itos(mc) + ",1"; } } @@ -663,7 +603,6 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const } void VisualScriptFunctionCall::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptFunctionCall::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptFunctionCall::get_base_type); @@ -761,7 +700,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } _FORCE_INLINE_ bool call_rpc(Object *p_base, const Variant **p_args, int p_argcount) { - if (!p_base) return false; @@ -789,11 +727,8 @@ public: } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (call_mode) { - case VisualScriptFunctionCall::CALL_MODE_SELF: { - Object *object = instance->get_owner_ptr(); if (rpc_mode) { @@ -805,7 +740,6 @@ public: } } break; case VisualScriptFunctionCall::CALL_MODE_NODE_PATH: { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -831,7 +765,6 @@ public: } break; case VisualScriptFunctionCall::CALL_MODE_INSTANCE: case VisualScriptFunctionCall::CALL_MODE_BASIC_TYPE: { - Variant v = *p_inputs[0]; if (rpc_mode) { @@ -863,7 +796,6 @@ public: } break; case VisualScriptFunctionCall::CALL_MODE_SINGLETON: { - Object *object = Engine::get_singleton()->get_singleton_object(singleton); if (!object) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -882,7 +814,6 @@ public: } if (!validate) { - //ignore call errors if validation is disabled r_error.error = Callable::CallError::CALL_OK; r_error_str = String(); @@ -893,7 +824,6 @@ public: }; VisualScriptNodeInstance *VisualScriptFunctionCall::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceFunctionCall *instance = memnew(VisualScriptNodeInstanceFunctionCall); instance->node = this; instance->instance = p_instance; @@ -909,7 +839,6 @@ VisualScriptNodeInstance *VisualScriptFunctionCall::instance(VisualScriptInstanc } VisualScriptFunctionCall::TypeGuess VisualScriptFunctionCall::guess_output_type(TypeGuess *p_inputs, int p_output) const { - if (p_output == 0 && call_mode == CALL_MODE_INSTANCE) { return p_inputs[0]; } @@ -918,7 +847,6 @@ VisualScriptFunctionCall::TypeGuess VisualScriptFunctionCall::guess_output_type( } VisualScriptFunctionCall::VisualScriptFunctionCall() { - validate = true; call_mode = CALL_MODE_SELF; basic_type = Variant::NIL; @@ -929,7 +857,6 @@ VisualScriptFunctionCall::VisualScriptFunctionCall() { template <VisualScriptFunctionCall::CallMode cmode> static Ref<VisualScriptNode> create_function_call_node(const String &p_name) { - Ref<VisualScriptFunctionCall> node; node.instance(); node->set_call_mode(cmode); @@ -941,17 +868,14 @@ static Ref<VisualScriptNode> create_function_call_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptPropertySet::get_output_sequence_port_count() const { - return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0; } bool VisualScriptPropertySet::has_input_sequence_port() const { - return call_mode != CALL_MODE_BASIC_TYPE; } Node *VisualScriptPropertySet::_get_base_node() const { - #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); if (!script.is_valid()) @@ -987,7 +911,6 @@ Node *VisualScriptPropertySet::_get_base_node() const { } StringName VisualScriptPropertySet::_get_base_type() const { - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) return get_visual_script()->get_instance_base_type(); else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { @@ -1000,25 +923,20 @@ StringName VisualScriptPropertySet::_get_base_type() const { } int VisualScriptPropertySet::get_input_value_port_count() const { - int pc = (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 2 : 1; return pc; } int VisualScriptPropertySet::get_output_value_port_count() const { - return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0; } String VisualScriptPropertySet::get_output_sequence_port_text(int p_port) const { - return String(); } void VisualScriptPropertySet::_adjust_input_index(PropertyInfo &pinfo) const { - if (index != StringName()) { - Variant v; Callable::CallError ce; v = Variant::construct(pinfo.type, nullptr, 0, ce); @@ -1065,7 +983,6 @@ PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) cons } String VisualScriptPropertySet::get_caption() const { - static const char *opname[ASSIGN_OP_MAX] = { "Set", "Add", "Subtract", "Multiply", "Divide", "Mod", "ShiftLeft", "ShiftRight", "BitAnd", "BitOr", "BitXor" }; @@ -1079,7 +996,6 @@ String VisualScriptPropertySet::get_caption() const { } String VisualScriptPropertySet::get_text() const { - if (call_mode == CALL_MODE_BASIC_TYPE) { return String("On ") + Variant::get_type_name(basic_type); } @@ -1096,20 +1012,17 @@ String VisualScriptPropertySet::get_text() const { void VisualScriptPropertySet::_update_base_type() { //cache it because this information may not be available on load if (call_mode == CALL_MODE_NODE_PATH) { - Node *node = _get_base_node(); if (node) { base_type = node->get_class(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { base_type = get_visual_script()->get_instance_base_type(); } } } void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { - if (basic_type == p_type) return; basic_type = p_type; @@ -1120,12 +1033,10 @@ void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { } Variant::Type VisualScriptPropertySet::get_basic_type() const { - return basic_type; } void VisualScriptPropertySet::set_base_type(const StringName &p_type) { - if (base_type == p_type) return; @@ -1135,12 +1046,10 @@ void VisualScriptPropertySet::set_base_type(const StringName &p_type) { } StringName VisualScriptPropertySet::get_base_type() const { - return base_type; } void VisualScriptPropertySet::set_base_script(const String &p_path) { - if (base_script == p_path) return; @@ -1150,12 +1059,10 @@ void VisualScriptPropertySet::set_base_script(const String &p_path) { } String VisualScriptPropertySet::get_base_script() const { - return base_script; } void VisualScriptPropertySet::_update_cache() { - if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop())) return; @@ -1163,7 +1070,6 @@ void VisualScriptPropertySet::_update_cache() { return; if (call_mode == CALL_MODE_BASIC_TYPE) { - //not super efficient.. Variant v; @@ -1174,21 +1080,17 @@ void VisualScriptPropertySet::_update_cache() { v.get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == property) { - type_cache = E->get(); } } } else { - StringName type; Ref<Script> script; Node *node = nullptr; if (call_mode == CALL_MODE_NODE_PATH) { - node = _get_base_node(); if (node) { type = node->get_class(); @@ -1196,24 +1098,19 @@ void VisualScriptPropertySet::_update_cache() { script = node->get_script(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { type = get_visual_script()->get_instance_base_type(); base_type = type; //cache, too script = get_visual_script(); } } else if (call_mode == CALL_MODE_INSTANCE) { - type = base_type; if (base_script != String()) { - if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - script = Ref<Resource>(ResourceCache::get(base_script)); } else { return; @@ -1224,19 +1121,16 @@ void VisualScriptPropertySet::_update_cache() { List<PropertyInfo> pinfo; if (node) { - node->get_property_list(&pinfo); } else { ClassDB::get_property_list(type, &pinfo); } if (script.is_valid()) { - script->get_script_property_list(&pinfo); } for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == property) { type_cache = E->get(); return; @@ -1246,7 +1140,6 @@ void VisualScriptPropertySet::_update_cache() { } void VisualScriptPropertySet::set_property(const StringName &p_type) { - if (property == p_type) return; @@ -1257,12 +1150,10 @@ void VisualScriptPropertySet::set_property(const StringName &p_type) { ports_changed_notify(); } StringName VisualScriptPropertySet::get_property() const { - return property; } void VisualScriptPropertySet::set_base_path(const NodePath &p_type) { - if (base_path == p_type) return; @@ -1273,12 +1164,10 @@ void VisualScriptPropertySet::set_base_path(const NodePath &p_type) { } NodePath VisualScriptPropertySet::get_base_path() const { - return base_path; } void VisualScriptPropertySet::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) return; @@ -1288,7 +1177,6 @@ void VisualScriptPropertySet::set_call_mode(CallMode p_mode) { ports_changed_notify(); } VisualScriptPropertySet::CallMode VisualScriptPropertySet::get_call_mode() const { - return call_mode; } @@ -1297,12 +1185,10 @@ void VisualScriptPropertySet::_set_type_cache(const Dictionary &p_type) { } Dictionary VisualScriptPropertySet::_get_type_cache() const { - return type_cache; } void VisualScriptPropertySet::set_index(const StringName &p_type) { - if (index == p_type) return; index = p_type; @@ -1312,12 +1198,10 @@ void VisualScriptPropertySet::set_index(const StringName &p_type) { } StringName VisualScriptPropertySet::get_index() const { - return index; } void VisualScriptPropertySet::set_assign_op(AssignOp p_op) { - ERR_FAIL_INDEX(p_op, ASSIGN_OP_MAX); if (assign_op == p_op) return; @@ -1333,7 +1217,6 @@ VisualScriptPropertySet::AssignOp VisualScriptPropertySet::get_assign_op() const } void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { - if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -1356,7 +1239,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { - Node *bnode = _get_base_node(); if (bnode) { property.hint_string = bnode->get_path(); //convert to loong string @@ -1365,9 +1247,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } if (property.name == "property") { - if (call_mode == CALL_MODE_BASIC_TYPE) { - property.hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE; property.hint_string = Variant::get_type_name(basic_type); @@ -1380,15 +1260,12 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { if (base_script != String()) { if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script)); if (script.is_valid()) { - property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT; property.hint_string = itos(script->get_instance_id()); } @@ -1408,7 +1285,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } if (property.name == "index") { - Callable::CallError ce; Variant v = Variant::construct(type_cache.type, nullptr, 0, ce); List<PropertyInfo> plist; @@ -1427,7 +1303,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { } void VisualScriptPropertySet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptPropertySet::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptPropertySet::get_base_type); @@ -1520,11 +1395,9 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } _FORCE_INLINE_ void _process_get(Variant &source, const Variant &p_argument, bool &valid) { - if (index != StringName() && assign_op == VisualScriptPropertySet::ASSIGN_OP_NONE) { source.set_named(index, p_argument, &valid); } else { - Variant value; if (index != StringName()) { value = source.get_named(index, &valid); @@ -1579,11 +1452,8 @@ public: } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (call_mode) { - case VisualScriptPropertySet::CALL_MODE_SELF: { - Object *object = instance->get_owner_ptr(); bool valid; @@ -1602,7 +1472,6 @@ public: } } break; case VisualScriptPropertySet::CALL_MODE_NODE_PATH: { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -1620,7 +1489,6 @@ public: bool valid; if (needs_get) { - Variant value = another->get(property, &valid); _process_get(value, *p_inputs[0], valid); another->set(property, value, &valid); @@ -1636,7 +1504,6 @@ public: } break; case VisualScriptPropertySet::CALL_MODE_INSTANCE: case VisualScriptPropertySet::CALL_MODE_BASIC_TYPE: { - Variant v = *p_inputs[0]; bool valid; @@ -1664,7 +1531,6 @@ public: }; VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstancePropertySet *instance = memnew(VisualScriptNodeInstancePropertySet); instance->node = this; instance->instance = p_instance; @@ -1678,7 +1544,6 @@ VisualScriptNodeInstance *VisualScriptPropertySet::instance(VisualScriptInstance } VisualScriptPropertySet::TypeGuess VisualScriptPropertySet::guess_output_type(TypeGuess *p_inputs, int p_output) const { - if (p_output == 0 && call_mode == CALL_MODE_INSTANCE) { return p_inputs[0]; } @@ -1686,7 +1551,6 @@ VisualScriptPropertySet::TypeGuess VisualScriptPropertySet::guess_output_type(Ty return VisualScriptNode::guess_output_type(p_inputs, p_output); } VisualScriptPropertySet::VisualScriptPropertySet() { - assign_op = ASSIGN_OP_NONE; call_mode = CALL_MODE_SELF; base_type = "Object"; @@ -1695,7 +1559,6 @@ VisualScriptPropertySet::VisualScriptPropertySet() { template <VisualScriptPropertySet::CallMode cmode> static Ref<VisualScriptNode> create_property_set_node(const String &p_name) { - Ref<VisualScriptPropertySet> node; node.instance(); node->set_call_mode(cmode); @@ -1707,31 +1570,26 @@ static Ref<VisualScriptNode> create_property_set_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptPropertyGet::get_output_sequence_port_count() const { - return 0; // (call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?0:1; } bool VisualScriptPropertyGet::has_input_sequence_port() const { - return false; //(call_mode==CALL_MODE_SELF || call_mode==CALL_MODE_NODE_PATH)?false:true; } void VisualScriptPropertyGet::_update_base_type() { //cache it because this information may not be available on load if (call_mode == CALL_MODE_NODE_PATH) { - Node *node = _get_base_node(); if (node) { base_type = node->get_class(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { base_type = get_visual_script()->get_instance_base_type(); } } } Node *VisualScriptPropertyGet::_get_base_node() const { - #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); if (!script.is_valid()) @@ -1767,7 +1625,6 @@ Node *VisualScriptPropertyGet::_get_base_node() const { } StringName VisualScriptPropertyGet::_get_base_type() const { - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) return get_visual_script()->get_instance_base_type(); else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { @@ -1780,21 +1637,17 @@ StringName VisualScriptPropertyGet::_get_base_type() const { } int VisualScriptPropertyGet::get_input_value_port_count() const { - return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0; } int VisualScriptPropertyGet::get_output_value_port_count() const { - return 1; } String VisualScriptPropertyGet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const { - if (call_mode == CALL_MODE_INSTANCE || call_mode == CALL_MODE_BASIC_TYPE) { if (p_idx == 0) { PropertyInfo pi; @@ -1819,12 +1672,10 @@ PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) cons } String VisualScriptPropertyGet::get_caption() const { - return String("Get ") + property; } String VisualScriptPropertyGet::get_text() const { - if (call_mode == CALL_MODE_BASIC_TYPE) { return String("On ") + Variant::get_type_name(basic_type); } @@ -1839,7 +1690,6 @@ String VisualScriptPropertyGet::get_text() const { } void VisualScriptPropertyGet::set_base_type(const StringName &p_type) { - if (base_type == p_type) return; @@ -1849,12 +1699,10 @@ void VisualScriptPropertyGet::set_base_type(const StringName &p_type) { } StringName VisualScriptPropertyGet::get_base_type() const { - return base_type; } void VisualScriptPropertyGet::set_base_script(const String &p_path) { - if (base_script == p_path) return; @@ -1864,14 +1712,11 @@ void VisualScriptPropertyGet::set_base_script(const String &p_path) { } String VisualScriptPropertyGet::get_base_script() const { - return base_script; } void VisualScriptPropertyGet::_update_cache() { - if (call_mode == CALL_MODE_BASIC_TYPE) { - //not super efficient.. Variant v; @@ -1882,22 +1727,18 @@ void VisualScriptPropertyGet::_update_cache() { v.get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - if (E->get().name == property) { - type_cache = E->get().type; return; } } } else { - StringName type; Ref<Script> script; Node *node = nullptr; if (call_mode == CALL_MODE_NODE_PATH) { - node = _get_base_node(); if (node) { type = node->get_class(); @@ -1905,24 +1746,19 @@ void VisualScriptPropertyGet::_update_cache() { script = node->get_script(); } } else if (call_mode == CALL_MODE_SELF) { - if (get_visual_script().is_valid()) { type = get_visual_script()->get_instance_base_type(); base_type = type; //cache, too script = get_visual_script(); } } else if (call_mode == CALL_MODE_INSTANCE) { - type = base_type; if (base_script != String()) { - if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - script = Ref<Resource>(ResourceCache::get(base_script)); } else { return; @@ -1942,7 +1778,6 @@ void VisualScriptPropertyGet::_update_cache() { } if (node) { - Variant prop = node->get(property, &valid); if (valid) { type_cache = prop.get_type(); @@ -1951,7 +1786,6 @@ void VisualScriptPropertyGet::_update_cache() { } if (script.is_valid()) { - type_ret = script->get_static_property_type(property, &valid); if (valid) { @@ -1963,7 +1797,6 @@ void VisualScriptPropertyGet::_update_cache() { } void VisualScriptPropertyGet::set_property(const StringName &p_type) { - if (property == p_type) return; @@ -1974,12 +1807,10 @@ void VisualScriptPropertyGet::set_property(const StringName &p_type) { ports_changed_notify(); } StringName VisualScriptPropertyGet::get_property() const { - return property; } void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) { - if (base_path == p_type) return; @@ -1990,12 +1821,10 @@ void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) { } NodePath VisualScriptPropertyGet::get_base_path() const { - return base_path; } void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) return; @@ -2005,12 +1834,10 @@ void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) { ports_changed_notify(); } VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const { - return call_mode; } void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) { - if (basic_type == p_type) return; basic_type = p_type; @@ -2020,7 +1847,6 @@ void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) { } Variant::Type VisualScriptPropertyGet::get_basic_type() const { - return basic_type; } @@ -2029,12 +1855,10 @@ void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) { } Variant::Type VisualScriptPropertyGet::_get_type_cache() const { - return type_cache; } void VisualScriptPropertyGet::set_index(const StringName &p_type) { - if (index == p_type) return; index = p_type; @@ -2044,12 +1868,10 @@ void VisualScriptPropertyGet::set_index(const StringName &p_type) { } StringName VisualScriptPropertyGet::get_index() const { - return index; } void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { - if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -2072,7 +1894,6 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { - Node *bnode = _get_base_node(); if (bnode) { property.hint_string = bnode->get_path(); //convert to loong string @@ -2081,9 +1902,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { } if (property.name == "property") { - if (call_mode == CALL_MODE_BASIC_TYPE) { - property.hint = PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE; property.hint_string = Variant::get_type_name(basic_type); @@ -2096,15 +1915,12 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { if (base_script != String()) { if (!ResourceCache::has(base_script) && ScriptServer::edit_request_func) { - ScriptServer::edit_request_func(base_script); //make sure it's loaded } if (ResourceCache::has(base_script)) { - Ref<Script> script = Ref<Resource>(ResourceCache::get(base_script)); if (script.is_valid()) { - property.hint = PROPERTY_HINT_PROPERTY_OF_SCRIPT; property.hint_string = itos(script->get_instance_id()); } @@ -2123,7 +1939,6 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { } if (property.name == "index") { - Callable::CallError ce; Variant v = Variant::construct(type_cache, nullptr, 0, ce); List<PropertyInfo> plist; @@ -2142,7 +1957,6 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { } void VisualScriptPropertyGet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptPropertyGet::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptPropertyGet::get_base_type); @@ -2212,11 +2026,8 @@ public: VisualScriptInstance *instance; virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (call_mode) { - case VisualScriptPropertyGet::CALL_MODE_SELF: { - Object *object = instance->get_owner_ptr(); bool valid; @@ -2234,7 +2045,6 @@ public: } } break; case VisualScriptPropertyGet::CALL_MODE_NODE_PATH: { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2265,7 +2075,6 @@ public: } break; default: { - bool valid; Variant v = *p_inputs[0]; @@ -2286,7 +2095,6 @@ public: }; VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstancePropertyGet *instance = memnew(VisualScriptNodeInstancePropertyGet); instance->node = this; instance->instance = p_instance; @@ -2299,7 +2107,6 @@ VisualScriptNodeInstance *VisualScriptPropertyGet::instance(VisualScriptInstance } VisualScriptPropertyGet::VisualScriptPropertyGet() { - call_mode = CALL_MODE_SELF; base_type = "Object"; basic_type = Variant::NIL; @@ -2308,7 +2115,6 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() { template <VisualScriptPropertyGet::CallMode cmode> static Ref<VisualScriptNode> create_property_get_node(const String &p_name) { - Ref<VisualScriptPropertyGet> node; node.instance(); node->set_call_mode(cmode); @@ -2320,20 +2126,16 @@ static Ref<VisualScriptNode> create_property_get_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptEmitSignal::get_output_sequence_port_count() const { - return 1; } bool VisualScriptEmitSignal::has_input_sequence_port() const { - return true; } int VisualScriptEmitSignal::get_input_value_port_count() const { - Ref<VisualScript> vs = get_visual_script(); if (vs.is_valid()) { - if (!vs->has_custom_signal(name)) return 0; @@ -2347,15 +2149,12 @@ int VisualScriptEmitSignal::get_output_value_port_count() const { } String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const { - Ref<VisualScript> vs = get_visual_script(); if (vs.is_valid()) { - if (!vs->has_custom_signal(name)) return PropertyInfo(); @@ -2366,17 +2165,14 @@ PropertyInfo VisualScriptEmitSignal::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptEmitSignal::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptEmitSignal::get_caption() const { - return "Emit " + String(name); } void VisualScriptEmitSignal::set_signal(const StringName &p_type) { - if (name == p_type) return; @@ -2386,12 +2182,10 @@ void VisualScriptEmitSignal::set_signal(const StringName &p_type) { ports_changed_notify(); } StringName VisualScriptEmitSignal::get_signal() const { - return name; } void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { - if (property.name == "signal") { property.hint = PROPERTY_HINT_ENUM; @@ -2399,13 +2193,11 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { Ref<VisualScript> vs = get_visual_script(); if (vs.is_valid()) { - vs->get_custom_signal_list(&sigs); } String ml; for (List<StringName>::Element *E = sigs.front(); E; E = E->next()) { - if (ml != String()) ml += ","; ml += E->get(); @@ -2416,7 +2208,6 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { } void VisualScriptEmitSignal::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_signal", "name"), &VisualScriptEmitSignal::set_signal); ClassDB::bind_method(D_METHOD("get_signal"), &VisualScriptEmitSignal::get_signal); @@ -2435,7 +2226,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Object *obj = instance->get_owner_ptr(); obj->emit_signal(name, p_inputs, argcount); @@ -2445,7 +2235,6 @@ public: }; VisualScriptNodeInstance *VisualScriptEmitSignal::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceEmitSignal *instance = memnew(VisualScriptNodeInstanceEmitSignal); instance->node = this; instance->instance = p_instance; @@ -2458,7 +2247,6 @@ VisualScriptEmitSignal::VisualScriptEmitSignal() { } static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) { - Vector<String> path = p_name.split("/"); ERR_FAIL_COND_V(path.size() < 4, Ref<VisualScriptNode>()); String base_type = path[2]; @@ -2470,7 +2258,6 @@ static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) { Variant::Type type = Variant::VARIANT_MAX; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (Variant::get_type_name(Variant::Type(i)) == base_type) { type = Variant::Type(i); break; @@ -2487,7 +2274,6 @@ static Ref<VisualScriptNode> create_basic_type_call_node(const String &p_name) { } void register_visual_script_func_nodes() { - VisualScriptLanguage::singleton->add_register_func("functions/call", create_node_generic<VisualScriptFunctionCall>); VisualScriptLanguage::singleton->add_register_func("functions/set", create_node_generic<VisualScriptPropertySet>); VisualScriptLanguage::singleton->add_register_func("functions/get", create_node_generic<VisualScriptPropertyGet>); @@ -2497,7 +2283,6 @@ void register_visual_script_func_nodes() { VisualScriptLanguage::singleton->add_register_func("functions/emit_signal", create_node_generic<VisualScriptEmitSignal>); for (int i = 0; i < Variant::VARIANT_MAX; i++) { - Variant::Type t = Variant::Type(i); String type_name = Variant::get_type_name(t); Callable::CallError ce; diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index 2dba0ae3c1..6921f0e820 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptFunctionCall : public VisualScriptNode { - GDCLASS(VisualScriptFunctionCall, VisualScriptNode); public: @@ -137,7 +136,6 @@ VARIANT_ENUM_CAST(VisualScriptFunctionCall::CallMode); VARIANT_ENUM_CAST(VisualScriptFunctionCall::RPCCallMode); class VisualScriptPropertySet : public VisualScriptNode { - GDCLASS(VisualScriptPropertySet, VisualScriptNode); public: @@ -243,7 +241,6 @@ VARIANT_ENUM_CAST(VisualScriptPropertySet::CallMode); VARIANT_ENUM_CAST(VisualScriptPropertySet::AssignOp); class VisualScriptPropertyGet : public VisualScriptNode { - GDCLASS(VisualScriptPropertyGet, VisualScriptNode); public: @@ -325,7 +322,6 @@ public: VARIANT_ENUM_CAST(VisualScriptPropertyGet::CallMode); class VisualScriptEmitSignal : public VisualScriptNode { - GDCLASS(VisualScriptEmitSignal, VisualScriptNode); private: diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 52399d29d0..8ae50c3b48 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -43,9 +43,7 @@ ////////////////////////////////////////// bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "argument_count") { - int new_argc = p_value; int argc = arguments.size(); if (argc == new_argc) @@ -66,7 +64,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value ERR_FAIL_INDEX_V(idx, arguments.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); arguments.write[idx].type = new_type; ports_changed_notify(); @@ -75,7 +72,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value } if (what == "name") { - arguments.write[idx].name = p_value; ports_changed_notify(); return true; @@ -107,7 +103,6 @@ bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value } bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "argument_count") { r_ret = arguments.size(); return true; @@ -149,7 +144,6 @@ bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const return false; } void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const { - p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256")); String argt = "Any"; for (int i = 1; i < Variant::VARIANT_MAX; i++) { @@ -171,35 +165,28 @@ void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const } int VisualScriptFunction::get_output_sequence_port_count() const { - return 1; } bool VisualScriptFunction::has_input_sequence_port() const { - return false; } int VisualScriptFunction::get_input_value_port_count() const { - return 0; } int VisualScriptFunction::get_output_value_port_count() const { - return arguments.size(); } String VisualScriptFunction::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const { - ERR_FAIL_V(PropertyInfo()); } PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, arguments.size(), PropertyInfo()); PropertyInfo out; out.type = arguments[p_idx].type; @@ -210,17 +197,14 @@ PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const { } String VisualScriptFunction::get_caption() const { - return "Function"; } String VisualScriptFunction::get_text() const { - return get_name(); //use name as function name I guess } void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_name, int p_index, const PropertyHint p_hint, const String &p_hint_string) { - Argument arg; arg.name = p_name; arg.type = p_type; @@ -234,31 +218,26 @@ void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_na ports_changed_notify(); } void VisualScriptFunction::set_argument_type(int p_argidx, Variant::Type p_type) { - ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.write[p_argidx].type = p_type; ports_changed_notify(); } Variant::Type VisualScriptFunction::get_argument_type(int p_argidx) const { - ERR_FAIL_INDEX_V(p_argidx, arguments.size(), Variant::NIL); return arguments[p_argidx].type; } void VisualScriptFunction::set_argument_name(int p_argidx, const String &p_name) { - ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.write[p_argidx].name = p_name; ports_changed_notify(); } String VisualScriptFunction::get_argument_name(int p_argidx) const { - ERR_FAIL_INDEX_V(p_argidx, arguments.size(), String()); return arguments[p_argidx].name; } void VisualScriptFunction::remove_argument(int p_argidx) { - ERR_FAIL_INDEX(p_argidx, arguments.size()); arguments.remove(p_argidx); @@ -266,7 +245,6 @@ void VisualScriptFunction::remove_argument(int p_argidx) { } int VisualScriptFunction::get_argument_count() const { - return arguments.size(); } @@ -286,7 +264,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - int ac = node->get_argument_count(); for (int i = 0; i < ac; i++) { @@ -310,7 +287,6 @@ public: }; VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceFunction *instance = memnew(VisualScriptNodeInstanceFunction); instance->node = this; instance->instance = p_instance; @@ -318,7 +294,6 @@ VisualScriptNodeInstance *VisualScriptFunction::instance(VisualScriptInstance *p } VisualScriptFunction::VisualScriptFunction() { - stack_size = 256; stack_less = false; sequenced = true; @@ -335,23 +310,19 @@ bool VisualScriptFunction::is_stack_less() const { } void VisualScriptFunction::set_sequenced(bool p_enable) { - sequenced = p_enable; } bool VisualScriptFunction::is_sequenced() const { - return sequenced; } void VisualScriptFunction::set_stack_size(int p_size) { - ERR_FAIL_COND(p_size < 1 || p_size > 100000); stack_size = p_size; } int VisualScriptFunction::get_stack_size() const { - return stack_size; } @@ -418,9 +389,7 @@ bool VisualScriptLists::is_output_port_type_editable() const { // for the inspector bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { - if (p_name == "input_count" && is_input_port_editable()) { - int new_argc = p_value; int argc = inputports.size(); if (argc == new_argc) @@ -441,7 +410,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_INDEX_V(idx, inputports.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); inputports.write[idx].type = new_type; ports_changed_notify(); @@ -450,7 +418,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (what == "name") { - inputports.write[idx].name = p_value; ports_changed_notify(); return true; @@ -458,7 +425,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (p_name == "output_count" && is_output_port_editable()) { - int new_argc = p_value; int argc = outputports.size(); if (argc == new_argc) @@ -479,7 +445,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { ERR_FAIL_INDEX_V(idx, outputports.size(), false); String what = String(p_name).get_slice("/", 1); if (what == "type") { - Variant::Type new_type = Variant::Type(int(p_value)); outputports.write[idx].type = new_type; ports_changed_notify(); @@ -488,7 +453,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { } if (what == "name") { - outputports.write[idx].name = p_value; ports_changed_notify(); return true; @@ -504,7 +468,6 @@ bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) { return false; } bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const { - if (p_name == "input_count" && is_input_port_editable()) { r_ret = inputports.size(); return true; @@ -549,7 +512,6 @@ bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const { return false; } void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const { - if (is_input_port_editable()) { p_list->push_back(PropertyInfo(Variant::INT, "input_count", PROPERTY_HINT_RANGE, "0,256")); String argt = "Any"; @@ -580,7 +542,6 @@ void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const { // input data port interaction void VisualScriptLists::add_input_data_port(Variant::Type p_type, const String &p_name, int p_index) { - if (!is_input_port_editable()) return; @@ -596,7 +557,6 @@ void VisualScriptLists::add_input_data_port(Variant::Type p_type, const String & _change_notify(); } void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) { - if (!is_input_port_type_editable()) return; @@ -607,7 +567,6 @@ void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type _change_notify(); } void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) { - if (!is_input_port_name_editable()) return; @@ -618,7 +577,6 @@ void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name _change_notify(); } void VisualScriptLists::remove_input_data_port(int p_argidx) { - if (!is_input_port_editable()) return; @@ -632,7 +590,6 @@ void VisualScriptLists::remove_input_data_port(int p_argidx) { // output data port interaction void VisualScriptLists::add_output_data_port(Variant::Type p_type, const String &p_name, int p_index) { - if (!is_output_port_editable()) return; @@ -648,7 +605,6 @@ void VisualScriptLists::add_output_data_port(Variant::Type p_type, const String _change_notify(); } void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) { - if (!is_output_port_type_editable()) return; @@ -659,7 +615,6 @@ void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_typ _change_notify(); } void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) { - if (!is_output_port_name_editable()) return; @@ -670,7 +625,6 @@ void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_nam _change_notify(); } void VisualScriptLists::remove_output_data_port(int p_argidx) { - if (!is_output_port_editable()) return; @@ -763,7 +717,6 @@ public: virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (input_count > 0) { Array arr; for (int i = 0; i < input_count; i++) @@ -778,7 +731,6 @@ public: }; VisualScriptNodeInstance *VisualScriptComposeArray::instance(VisualScriptInstance *p_instance) { - VisualScriptComposeArrayNode *instance = memnew(VisualScriptComposeArrayNode); instance->input_count = inputports.size(); return instance; @@ -795,31 +747,25 @@ VisualScriptComposeArray::VisualScriptComposeArray() { ////////////////////////////////////////// int VisualScriptOperator::get_output_sequence_port_count() const { - return 0; } bool VisualScriptOperator::has_input_sequence_port() const { - return false; } int VisualScriptOperator::get_input_value_port_count() const { - return (op == Variant::OP_BIT_NEGATE || op == Variant::OP_NOT || op == Variant::OP_NEGATE || op == Variant::OP_POSITIVE) ? 1 : 2; } int VisualScriptOperator::get_output_value_port_count() const { - return 1; } String VisualScriptOperator::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const { - static const Variant::Type port_types[Variant::OP_MAX][2] = { { Variant::NIL, Variant::NIL }, //OP_EQUAL, { Variant::NIL, Variant::NIL }, //OP_NOT_EQUAL, @@ -937,7 +883,6 @@ static const char *op_names[] = { }; String VisualScriptOperator::get_caption() const { - static const wchar_t *op_names[] = { //comparison L"A = B", //OP_EQUAL, @@ -974,7 +919,6 @@ String VisualScriptOperator::get_caption() const { } void VisualScriptOperator::set_operator(Variant::Operator p_op) { - if (op == p_op) return; op = p_op; @@ -982,12 +926,10 @@ void VisualScriptOperator::set_operator(Variant::Operator p_op) { } Variant::Operator VisualScriptOperator::get_operator() const { - return op; } void VisualScriptOperator::set_typed(Variant::Type p_op) { - if (typed == p_op) return; @@ -996,12 +938,10 @@ void VisualScriptOperator::set_typed(Variant::Type p_op) { } Variant::Type VisualScriptOperator::get_typed() const { - return typed; } void VisualScriptOperator::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualScriptOperator::set_operator); ClassDB::bind_method(D_METHOD("get_operator"), &VisualScriptOperator::get_operator); @@ -1032,17 +972,14 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; if (unary) { - Variant::evaluate(op, *p_inputs[0], Variant(), *p_outputs[0], valid); } else { Variant::evaluate(op, *p_inputs[0], *p_inputs[1], *p_outputs[0], valid); } if (!valid) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; if (p_outputs[0]->get_type() == Variant::STRING) { r_error_str = *p_outputs[0]; @@ -1059,7 +996,6 @@ public: }; VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceOperator *instance = memnew(VisualScriptNodeInstanceOperator); instance->unary = get_input_value_port_count() == 1; instance->op = op; @@ -1067,14 +1003,12 @@ VisualScriptNodeInstance *VisualScriptOperator::instance(VisualScriptInstance *p } VisualScriptOperator::VisualScriptOperator() { - op = Variant::OP_ADD; typed = Variant::NIL; } template <Variant::Operator OP> static Ref<VisualScriptNode> create_op_node(const String &p_name) { - Ref<VisualScriptOperator> node; node.instance(); node->set_operator(OP); @@ -1086,31 +1020,25 @@ static Ref<VisualScriptNode> create_op_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptSelect::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSelect::has_input_sequence_port() const { - return false; } int VisualScriptSelect::get_input_value_port_count() const { - return 3; } int VisualScriptSelect::get_output_value_port_count() const { - return 1; } String VisualScriptSelect::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSelect::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::BOOL, "cond"); } else if (p_idx == 1) { @@ -1120,22 +1048,18 @@ PropertyInfo VisualScriptSelect::get_input_value_port_info(int p_idx) const { } } PropertyInfo VisualScriptSelect::get_output_value_port_info(int p_idx) const { - return PropertyInfo(typed, "out"); } String VisualScriptSelect::get_caption() const { - return "Select"; } String VisualScriptSelect::get_text() const { - return "a if cond, else b"; } void VisualScriptSelect::set_typed(Variant::Type p_op) { - if (typed == p_op) return; @@ -1144,12 +1068,10 @@ void VisualScriptSelect::set_typed(Variant::Type p_op) { } Variant::Type VisualScriptSelect::get_typed() const { - return typed; } void VisualScriptSelect::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_typed", "type"), &VisualScriptSelect::set_typed); ClassDB::bind_method(D_METHOD("get_typed"), &VisualScriptSelect::get_typed); @@ -1166,7 +1088,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool cond = *p_inputs[0]; if (cond) *p_outputs[0] = *p_inputs[1]; @@ -1178,13 +1099,11 @@ public: }; VisualScriptNodeInstance *VisualScriptSelect::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSelect *instance = memnew(VisualScriptNodeInstanceSelect); return instance; } VisualScriptSelect::VisualScriptSelect() { - typed = Variant::NIL; } @@ -1193,36 +1112,29 @@ VisualScriptSelect::VisualScriptSelect() { ////////////////////////////////////////// int VisualScriptVariableGet::get_output_sequence_port_count() const { - return 0; } bool VisualScriptVariableGet::has_input_sequence_port() const { - return false; } int VisualScriptVariableGet::get_input_value_port_count() const { - return 0; } int VisualScriptVariableGet::get_output_value_port_count() const { - return 1; } String VisualScriptVariableGet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptVariableGet::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "value"; if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) { @@ -1235,11 +1147,9 @@ PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) cons } String VisualScriptVariableGet::get_caption() const { - return "Get " + variable; } void VisualScriptVariableGet::set_variable(StringName p_variable) { - if (variable == p_variable) return; variable = p_variable; @@ -1247,12 +1157,10 @@ void VisualScriptVariableGet::set_variable(StringName p_variable) { } StringName VisualScriptVariableGet::get_variable() const { - return variable; } void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { - if (property.name == "var_name" && get_visual_script().is_valid()) { Ref<VisualScript> vs = get_visual_script(); List<StringName> vars; @@ -1272,7 +1180,6 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { } void VisualScriptVariableGet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableGet::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableGet::get_variable); @@ -1286,7 +1193,6 @@ public: StringName variable; virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!instance->get_variable(variable, p_outputs[0])) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("VariableGet not found in script: ") + "'" + String(variable) + "'"; @@ -1297,7 +1203,6 @@ public: }; VisualScriptNodeInstance *VisualScriptVariableGet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceVariableGet *instance = memnew(VisualScriptNodeInstanceVariableGet); instance->node = this; instance->instance = p_instance; @@ -1312,31 +1217,25 @@ VisualScriptVariableGet::VisualScriptVariableGet() { ////////////////////////////////////////// int VisualScriptVariableSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptVariableSet::has_input_sequence_port() const { - return true; } int VisualScriptVariableSet::get_input_value_port_count() const { - return 1; } int VisualScriptVariableSet::get_output_value_port_count() const { - return 0; } String VisualScriptVariableSet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = "set"; if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) { @@ -1349,17 +1248,14 @@ PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptVariableSet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptVariableSet::get_caption() const { - return "Set " + variable; } void VisualScriptVariableSet::set_variable(StringName p_variable) { - if (variable == p_variable) return; variable = p_variable; @@ -1367,12 +1263,10 @@ void VisualScriptVariableSet::set_variable(StringName p_variable) { } StringName VisualScriptVariableSet::get_variable() const { - return variable; } void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { - if (property.name == "var_name" && get_visual_script().is_valid()) { Ref<VisualScript> vs = get_visual_script(); List<StringName> vars; @@ -1392,7 +1286,6 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { } void VisualScriptVariableSet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableSet::set_variable); ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableSet::get_variable); @@ -1408,9 +1301,7 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!instance->set_variable(variable, *p_inputs[0])) { - r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = RTR("VariableSet not found in script: ") + "'" + String(variable) + "'"; } @@ -1420,7 +1311,6 @@ public: }; VisualScriptNodeInstance *VisualScriptVariableSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceVariableSet *instance = memnew(VisualScriptNodeInstanceVariableSet); instance->node = this; instance->instance = p_instance; @@ -1435,36 +1325,29 @@ VisualScriptVariableSet::VisualScriptVariableSet() { ////////////////////////////////////////// int VisualScriptConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptConstant::has_input_sequence_port() const { - return false; } int VisualScriptConstant::get_input_value_port_count() const { - return 0; } int VisualScriptConstant::get_output_value_port_count() const { - return 1; } String VisualScriptConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.name = String(value); pinfo.type = type; @@ -1472,12 +1355,10 @@ PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const { } String VisualScriptConstant::get_caption() const { - return "Constant"; } void VisualScriptConstant::set_constant_type(Variant::Type p_type) { - if (type == p_type) return; @@ -1489,12 +1370,10 @@ void VisualScriptConstant::set_constant_type(Variant::Type p_type) { } Variant::Type VisualScriptConstant::get_constant_type() const { - return type; } void VisualScriptConstant::set_constant_value(Variant p_value) { - if (value == p_value) return; @@ -1502,12 +1381,10 @@ void VisualScriptConstant::set_constant_value(Variant p_value) { ports_changed_notify(); } Variant VisualScriptConstant::get_constant_value() const { - return value; } void VisualScriptConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "value") { property.type = type; if (type == Variant::NIL) @@ -1516,7 +1393,6 @@ void VisualScriptConstant::_validate_property(PropertyInfo &property) const { } void VisualScriptConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant_type", "type"), &VisualScriptConstant::set_constant_type); ClassDB::bind_method(D_METHOD("get_constant_type"), &VisualScriptConstant::get_constant_type); @@ -1538,21 +1414,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = constant; return 0; } }; VisualScriptNodeInstance *VisualScriptConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceConstant *instance = memnew(VisualScriptNodeInstanceConstant); instance->constant = value; return instance; } VisualScriptConstant::VisualScriptConstant() { - type = Variant::NIL; } @@ -1561,36 +1434,29 @@ VisualScriptConstant::VisualScriptConstant() { ////////////////////////////////////////// int VisualScriptPreload::get_output_sequence_port_count() const { - return 0; } bool VisualScriptPreload::has_input_sequence_port() const { - return false; } int VisualScriptPreload::get_input_value_port_count() const { - return 0; } int VisualScriptPreload::get_output_value_port_count() const { - return 1; } String VisualScriptPreload::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptPreload::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const { - PropertyInfo pinfo; pinfo.type = Variant::OBJECT; if (preload.is_valid()) { @@ -1611,12 +1477,10 @@ PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const { } String VisualScriptPreload::get_caption() const { - return "Preload"; } void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) { - if (preload == p_preload) return; @@ -1625,12 +1489,10 @@ void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) { } Ref<Resource> VisualScriptPreload::get_preload() const { - return preload; } void VisualScriptPreload::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_preload", "resource"), &VisualScriptPreload::set_preload); ClassDB::bind_method(D_METHOD("get_preload"), &VisualScriptPreload::get_preload); @@ -1643,14 +1505,12 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = preload; return 0; } }; VisualScriptNodeInstance *VisualScriptPreload::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstancePreload *instance = memnew(VisualScriptNodeInstancePreload); instance->preload = preload; return instance; @@ -1664,31 +1524,25 @@ VisualScriptPreload::VisualScriptPreload() { ////////////////////////////////////////// int VisualScriptIndexGet::get_output_sequence_port_count() const { - return 0; } bool VisualScriptIndexGet::has_input_sequence_port() const { - return false; } int VisualScriptIndexGet::get_input_value_port_count() const { - return 2; } int VisualScriptIndexGet::get_output_value_port_count() const { - return 1; } String VisualScriptIndexGet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::NIL, "base"); } else { @@ -1697,12 +1551,10 @@ PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptIndexGet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptIndexGet::get_caption() const { - return "Get Index"; } @@ -1711,7 +1563,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; *p_outputs[0] = p_inputs[0]->get(*p_inputs[1], &valid); @@ -1724,7 +1575,6 @@ public: }; VisualScriptNodeInstance *VisualScriptIndexGet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceIndexGet *instance = memnew(VisualScriptNodeInstanceIndexGet); return instance; } @@ -1736,31 +1586,25 @@ VisualScriptIndexGet::VisualScriptIndexGet() { ////////////////////////////////////////// int VisualScriptIndexSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptIndexSet::has_input_sequence_port() const { - return true; } int VisualScriptIndexSet::get_input_value_port_count() const { - return 3; } int VisualScriptIndexSet::get_output_value_port_count() const { - return 0; } String VisualScriptIndexSet::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const { - if (p_idx == 0) { return PropertyInfo(Variant::NIL, "base"); } else if (p_idx == 1) { @@ -1772,12 +1616,10 @@ PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptIndexSet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptIndexSet::get_caption() const { - return "Set Index"; } @@ -1786,7 +1628,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - bool valid; *p_outputs[0] = *p_inputs[0]; p_outputs[0]->set(*p_inputs[1], *p_inputs[2], &valid); @@ -1800,7 +1641,6 @@ public: }; VisualScriptNodeInstance *VisualScriptIndexSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceIndexSet *instance = memnew(VisualScriptNodeInstanceIndexSet); return instance; } @@ -1812,31 +1652,25 @@ VisualScriptIndexSet::VisualScriptIndexSet() { ////////////////////////////////////////// int VisualScriptGlobalConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptGlobalConstant::has_input_sequence_port() const { - return false; } int VisualScriptGlobalConstant::get_input_value_port_count() const { - return 0; } int VisualScriptGlobalConstant::get_output_value_port_count() const { - return 1; } String VisualScriptGlobalConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptGlobalConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } @@ -1846,12 +1680,10 @@ PropertyInfo VisualScriptGlobalConstant::get_output_value_port_info(int p_idx) c } String VisualScriptGlobalConstant::get_caption() const { - return "Global Constant"; } void VisualScriptGlobalConstant::set_global_constant(int p_which) { - index = p_which; _change_notify(); ports_changed_notify(); @@ -1867,28 +1699,24 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = GlobalConstants::get_global_constant_value(index); return 0; } }; VisualScriptNodeInstance *VisualScriptGlobalConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceGlobalConstant *instance = memnew(VisualScriptNodeInstanceGlobalConstant); instance->index = index; return instance; } void VisualScriptGlobalConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_global_constant", "index"), &VisualScriptGlobalConstant::set_global_constant); ClassDB::bind_method(D_METHOD("get_global_constant"), &VisualScriptGlobalConstant::get_global_constant); String cc; for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { - if (i > 0) cc += ","; cc += GlobalConstants::get_global_constant_name(i); @@ -1897,7 +1725,6 @@ void VisualScriptGlobalConstant::_bind_methods() { } VisualScriptGlobalConstant::VisualScriptGlobalConstant() { - index = 0; } @@ -1906,31 +1733,25 @@ VisualScriptGlobalConstant::VisualScriptGlobalConstant() { ////////////////////////////////////////// int VisualScriptClassConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptClassConstant::has_input_sequence_port() const { - return false; } int VisualScriptClassConstant::get_input_value_port_count() const { - return 0; } int VisualScriptClassConstant::get_output_value_port_count() const { - return 1; } String VisualScriptClassConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptClassConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } @@ -1943,12 +1764,10 @@ PropertyInfo VisualScriptClassConstant::get_output_value_port_info(int p_idx) co } String VisualScriptClassConstant::get_caption() const { - return "Class Constant"; } void VisualScriptClassConstant::set_class_constant(const StringName &p_which) { - name = p_which; _change_notify(); ports_changed_notify(); @@ -1959,7 +1778,6 @@ StringName VisualScriptClassConstant::get_class_constant() { } void VisualScriptClassConstant::set_base_type(const StringName &p_which) { - base_type = p_which; List<String> constants; ClassDB::get_integer_constant_list(base_type, &constants, true); @@ -1992,7 +1810,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Invalid constant name, pick a valid class constant."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2004,16 +1821,13 @@ public: }; VisualScriptNodeInstance *VisualScriptClassConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceClassConstant *instance = memnew(VisualScriptNodeInstanceClassConstant); instance->value = ClassDB::get_integer_constant(base_type, name, &instance->valid); return instance; } void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant") { - List<String> constants; ClassDB::get_integer_constant_list(base_type, &constants, true); @@ -2028,7 +1842,6 @@ void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const } void VisualScriptClassConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_class_constant", "name"), &VisualScriptClassConstant::set_class_constant); ClassDB::bind_method(D_METHOD("get_class_constant"), &VisualScriptClassConstant::get_class_constant); @@ -2040,7 +1853,6 @@ void VisualScriptClassConstant::_bind_methods() { } VisualScriptClassConstant::VisualScriptClassConstant() { - base_type = "Object"; } @@ -2049,41 +1861,33 @@ VisualScriptClassConstant::VisualScriptClassConstant() { ////////////////////////////////////////// int VisualScriptBasicTypeConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptBasicTypeConstant::has_input_sequence_port() const { - return false; } int VisualScriptBasicTypeConstant::get_input_value_port_count() const { - return 0; } int VisualScriptBasicTypeConstant::get_output_value_port_count() const { - return 1; } String VisualScriptBasicTypeConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptBasicTypeConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptBasicTypeConstant::get_output_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } String VisualScriptBasicTypeConstant::get_caption() const { - return "Basic Constant"; } @@ -2096,7 +1900,6 @@ String VisualScriptBasicTypeConstant::get_text() const { } void VisualScriptBasicTypeConstant::set_basic_type_constant(const StringName &p_which) { - name = p_which; _change_notify(); ports_changed_notify(); @@ -2107,7 +1910,6 @@ StringName VisualScriptBasicTypeConstant::get_basic_type_constant() const { } void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) { - type = p_which; List<StringName> constants; @@ -2141,7 +1943,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Invalid constant name, pick a valid basic type constant."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2153,16 +1954,13 @@ public: }; VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceBasicTypeConstant *instance = memnew(VisualScriptNodeInstanceBasicTypeConstant); instance->value = Variant::get_constant_value(type, name, &instance->valid); return instance; } void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) const { - if (property.name == "constant") { - List<StringName> constants; Variant::get_constants_for_type(type, &constants); @@ -2181,7 +1979,6 @@ void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) c } void VisualScriptBasicTypeConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_basic_type", "name"), &VisualScriptBasicTypeConstant::set_basic_type); ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptBasicTypeConstant::get_basic_type); @@ -2198,7 +1995,6 @@ void VisualScriptBasicTypeConstant::_bind_methods() { } VisualScriptBasicTypeConstant::VisualScriptBasicTypeConstant() { - type = Variant::NIL; } @@ -2229,46 +2025,37 @@ double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX] = { }; int VisualScriptMathConstant::get_output_sequence_port_count() const { - return 0; } bool VisualScriptMathConstant::has_input_sequence_port() const { - return false; } int VisualScriptMathConstant::get_input_value_port_count() const { - return 0; } int VisualScriptMathConstant::get_output_value_port_count() const { - return 1; } String VisualScriptMathConstant::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptMathConstant::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptMathConstant::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::FLOAT, const_name[constant]); } String VisualScriptMathConstant::get_caption() const { - return "Math Constant"; } void VisualScriptMathConstant::set_math_constant(MathConstant p_which) { - constant = p_which; _change_notify(); ports_changed_notify(); @@ -2284,28 +2071,24 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = value; return 0; } }; VisualScriptNodeInstance *VisualScriptMathConstant::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceMathConstant *instance = memnew(VisualScriptNodeInstanceMathConstant); instance->value = const_value[constant]; return instance; } void VisualScriptMathConstant::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_math_constant", "which"), &VisualScriptMathConstant::set_math_constant); ClassDB::bind_method(D_METHOD("get_math_constant"), &VisualScriptMathConstant::get_math_constant); String cc; for (int i = 0; i < MATH_CONSTANT_MAX; i++) { - if (i > 0) cc += ","; cc += const_name[i]; @@ -2324,7 +2107,6 @@ void VisualScriptMathConstant::_bind_methods() { } VisualScriptMathConstant::VisualScriptMathConstant() { - constant = MATH_CONSTANT_ONE; } @@ -2333,46 +2115,37 @@ VisualScriptMathConstant::VisualScriptMathConstant() { ////////////////////////////////////////// int VisualScriptEngineSingleton::get_output_sequence_port_count() const { - return 0; } bool VisualScriptEngineSingleton::has_input_sequence_port() const { - return false; } int VisualScriptEngineSingleton::get_input_value_port_count() const { - return 0; } int VisualScriptEngineSingleton::get_output_value_port_count() const { - return 1; } String VisualScriptEngineSingleton::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptEngineSingleton::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptEngineSingleton::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, singleton); } String VisualScriptEngineSingleton::get_caption() const { - return "Get Engine Singleton"; } void VisualScriptEngineSingleton::set_singleton(const String &p_string) { - singleton = p_string; _change_notify(); @@ -2390,21 +2163,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = singleton; return 0; } }; VisualScriptNodeInstance *VisualScriptEngineSingleton::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton); instance->singleton = Engine::get_singleton()->get_singleton_object(singleton); return instance; } VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output_type(TypeGuess *p_inputs, int p_output) const { - Object *obj = Engine::get_singleton()->get_singleton_object(singleton); TypeGuess tg; tg.type = Variant::OBJECT; @@ -2417,7 +2187,6 @@ VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output } void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) const { - String cc; List<Engine::Singleton> singletons; @@ -2438,7 +2207,6 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con } void VisualScriptEngineSingleton::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_singleton", "name"), &VisualScriptEngineSingleton::set_singleton); ClassDB::bind_method(D_METHOD("get_singleton"), &VisualScriptEngineSingleton::get_singleton); @@ -2446,7 +2214,6 @@ void VisualScriptEngineSingleton::_bind_methods() { } VisualScriptEngineSingleton::VisualScriptEngineSingleton() { - singleton = String(); } @@ -2455,46 +2222,37 @@ VisualScriptEngineSingleton::VisualScriptEngineSingleton() { ////////////////////////////////////////// int VisualScriptSceneNode::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSceneNode::has_input_sequence_port() const { - return false; } int VisualScriptSceneNode::get_input_value_port_count() const { - return 0; } int VisualScriptSceneNode::get_output_value_port_count() const { - return 1; } String VisualScriptSceneNode::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSceneNode::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSceneNode::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, path.simplified()); } String VisualScriptSceneNode::get_caption() const { - return "Get Scene Node"; } void VisualScriptSceneNode::set_node_path(const NodePath &p_path) { - path = p_path; _change_notify(); ports_changed_notify(); @@ -2513,7 +2271,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2535,7 +2292,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSceneNode *instance = memnew(VisualScriptNodeInstanceSceneNode); instance->node = this; instance->instance = p_instance; @@ -2546,7 +2302,6 @@ VisualScriptNodeInstance *VisualScriptSceneNode::instance(VisualScriptInstance * #ifdef TOOLS_ENABLED static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) return nullptr; @@ -2567,7 +2322,6 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const #endif VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGuess *p_inputs, int p_output) const { - VisualScriptSceneNode::TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "Node"; @@ -2604,10 +2358,8 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu } void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const { - #ifdef TOOLS_ENABLED if (property.name == "node_path") { - Ref<Script> script = get_visual_script(); if (!script.is_valid()) return; @@ -2634,7 +2386,6 @@ void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const { } void VisualScriptSceneNode::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_node_path", "path"), &VisualScriptSceneNode::set_node_path); ClassDB::bind_method(D_METHOD("get_node_path"), &VisualScriptSceneNode::get_node_path); @@ -2642,7 +2393,6 @@ void VisualScriptSceneNode::_bind_methods() { } VisualScriptSceneNode::VisualScriptSceneNode() { - path = String("."); } @@ -2651,41 +2401,33 @@ VisualScriptSceneNode::VisualScriptSceneNode() { ////////////////////////////////////////// int VisualScriptSceneTree::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSceneTree::has_input_sequence_port() const { - return false; } int VisualScriptSceneTree::get_input_value_port_count() const { - return 0; } int VisualScriptSceneTree::get_output_value_port_count() const { - return 1; } String VisualScriptSceneTree::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSceneTree::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSceneTree::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::OBJECT, "Scene Tree", PROPERTY_HINT_TYPE_STRING, "SceneTree"); } String VisualScriptSceneTree::get_caption() const { - return "Get Scene Tree"; } @@ -2697,7 +2439,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -2719,7 +2460,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSceneTree *instance = memnew(VisualScriptNodeInstanceSceneTree); instance->node = this; instance->instance = p_instance; @@ -2727,7 +2467,6 @@ VisualScriptNodeInstance *VisualScriptSceneTree::instance(VisualScriptInstance * } VisualScriptSceneTree::TypeGuess VisualScriptSceneTree::guess_output_type(TypeGuess *p_inputs, int p_output) const { - TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "SceneTree"; @@ -2748,46 +2487,37 @@ VisualScriptSceneTree::VisualScriptSceneTree() { ////////////////////////////////////////// int VisualScriptResourcePath::get_output_sequence_port_count() const { - return 0; } bool VisualScriptResourcePath::has_input_sequence_port() const { - return false; } int VisualScriptResourcePath::get_input_value_port_count() const { - return 0; } int VisualScriptResourcePath::get_output_value_port_count() const { - return 1; } String VisualScriptResourcePath::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptResourcePath::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptResourcePath::get_output_value_port_info(int p_idx) const { - return PropertyInfo(Variant::STRING, path); } String VisualScriptResourcePath::get_caption() const { - return "Resource Path"; } void VisualScriptResourcePath::set_resource_path(const String &p_path) { - path = p_path; _change_notify(); ports_changed_notify(); @@ -2804,21 +2534,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = path; return 0; } }; VisualScriptNodeInstance *VisualScriptResourcePath::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceResourcePath *instance = memnew(VisualScriptNodeInstanceResourcePath); instance->path = path; return instance; } void VisualScriptResourcePath::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_resource_path", "path"), &VisualScriptResourcePath::set_resource_path); ClassDB::bind_method(D_METHOD("get_resource_path"), &VisualScriptResourcePath::get_resource_path); @@ -2826,7 +2553,6 @@ void VisualScriptResourcePath::_bind_methods() { } VisualScriptResourcePath::VisualScriptResourcePath() { - path = ""; } @@ -2835,36 +2561,29 @@ VisualScriptResourcePath::VisualScriptResourcePath() { ////////////////////////////////////////// int VisualScriptSelf::get_output_sequence_port_count() const { - return 0; } bool VisualScriptSelf::has_input_sequence_port() const { - return false; } int VisualScriptSelf::get_input_value_port_count() const { - return 0; } int VisualScriptSelf::get_output_value_port_count() const { - return 1; } String VisualScriptSelf::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const { - String type_name; if (get_visual_script().is_valid()) type_name = get_visual_script()->get_instance_base_type(); @@ -2875,7 +2594,6 @@ PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const { } String VisualScriptSelf::get_caption() const { - return "Get Self"; } @@ -2886,21 +2604,18 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = instance->get_owner_ptr(); return 0; } }; VisualScriptNodeInstance *VisualScriptSelf::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSelf *instance = memnew(VisualScriptNodeInstanceSelf); instance->instance = p_instance; return instance; } VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inputs, int p_output) const { - VisualScriptSceneNode::TypeGuess tg; tg.type = Variant::OBJECT; tg.gdclass = "Object"; @@ -2926,7 +2641,6 @@ VisualScriptSelf::VisualScriptSelf() { ////////////////////////////////////////// int VisualScriptCustomNode::get_output_sequence_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_count")) { return get_script_instance()->call("_get_output_sequence_port_count"); } @@ -2934,7 +2648,6 @@ int VisualScriptCustomNode::get_output_sequence_port_count() const { } bool VisualScriptCustomNode::has_input_sequence_port() const { - if (get_script_instance() && get_script_instance()->has_method("_has_input_sequence_port")) { return get_script_instance()->call("_has_input_sequence_port"); } @@ -2942,14 +2655,12 @@ bool VisualScriptCustomNode::has_input_sequence_port() const { } int VisualScriptCustomNode::get_input_value_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_count")) { return get_script_instance()->call("_get_input_value_port_count"); } return 0; } int VisualScriptCustomNode::get_output_value_port_count() const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_count")) { return get_script_instance()->call("_get_output_value_port_count"); } @@ -2957,7 +2668,6 @@ int VisualScriptCustomNode::get_output_value_port_count() const { } String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const { - if (get_script_instance() && get_script_instance()->has_method("_get_output_sequence_port_text")) { return get_script_instance()->call("_get_output_sequence_port_text", p_port); } @@ -2966,7 +2676,6 @@ String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const { } PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const { - PropertyInfo info; if (get_script_instance() && get_script_instance()->has_method("_get_input_value_port_type")) { info.type = Variant::Type(int(get_script_instance()->call("_get_input_value_port_type", p_idx))); @@ -2978,7 +2687,6 @@ PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const { - PropertyInfo info; if (get_script_instance() && get_script_instance()->has_method("_get_output_value_port_type")) { info.type = Variant::Type(int(get_script_instance()->call("_get_output_value_port_type", p_idx))); @@ -2990,7 +2698,6 @@ PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const } String VisualScriptCustomNode::get_caption() const { - if (get_script_instance() && get_script_instance()->has_method("_get_caption")) { return get_script_instance()->call("_get_caption"); } @@ -2998,7 +2705,6 @@ String VisualScriptCustomNode::get_caption() const { } String VisualScriptCustomNode::get_text() const { - if (get_script_instance() && get_script_instance()->has_method("_get_text")) { return get_script_instance()->call("_get_text"); } @@ -3006,7 +2712,6 @@ String VisualScriptCustomNode::get_text() const { } String VisualScriptCustomNode::get_category() const { - if (get_script_instance() && get_script_instance()->has_method("_get_category")) { return get_script_instance()->call("_get_category"); } @@ -3023,7 +2728,6 @@ public: virtual int get_working_memory_size() const { return work_mem_size; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (node->get_script_instance()) { #ifdef DEBUG_ENABLED if (!node->get_script_instance()->has_method(VisualScriptLanguage::singleton->_step)) { @@ -3085,7 +2789,6 @@ public: }; VisualScriptNodeInstance *VisualScriptCustomNode::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceCustomNode *instance = memnew(VisualScriptNodeInstanceCustomNode); instance->instance = p_instance; instance->node = this; @@ -3106,7 +2809,6 @@ void VisualScriptCustomNode::_script_changed() { } void VisualScriptCustomNode::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_output_sequence_port_count")); BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_input_sequence_port")); @@ -3150,21 +2852,17 @@ VisualScriptCustomNode::VisualScriptCustomNode() { ////////////////////////////////////////// int VisualScriptSubCall::get_output_sequence_port_count() const { - return 1; } bool VisualScriptSubCall::has_input_sequence_port() const { - return true; } int VisualScriptSubCall::get_input_value_port_count() const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { - MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); return mi.arguments.size(); } @@ -3172,20 +2870,16 @@ int VisualScriptSubCall::get_input_value_port_count() const { return 0; } int VisualScriptSubCall::get_output_value_port_count() const { - return 1; } String VisualScriptSubCall::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { - MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); return mi.arguments[p_idx]; } @@ -3194,7 +2888,6 @@ PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const { } PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const { - Ref<Script> script = get_script(); if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) { MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall); @@ -3204,12 +2897,10 @@ PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const { } String VisualScriptSubCall::get_caption() const { - return "SubCall"; } String VisualScriptSubCall::get_text() const { - Ref<Script> script = get_script(); if (script.is_valid()) { if (script->get_name() != String()) @@ -3222,7 +2913,6 @@ String VisualScriptSubCall::get_text() const { } String VisualScriptSubCall::get_category() const { - return "custom"; } @@ -3236,7 +2926,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (!valid) { r_error_str = "Node requires a script with a _subcall(<args>) method to work."; r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -3248,7 +2937,6 @@ public: }; VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceSubCall *instance = memnew(VisualScriptNodeInstanceSubCall); instance->instance = p_instance; Ref<Script> script = get_script(); @@ -3262,7 +2950,6 @@ VisualScriptNodeInstance *VisualScriptSubCall::instance(VisualScriptInstance *p_ } void VisualScriptSubCall::_bind_methods() { - MethodInfo scmi(Variant::NIL, "_subcall", PropertyInfo(Variant::NIL, "arguments")); scmi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; BIND_VMETHOD(scmi); @@ -3276,12 +2963,10 @@ VisualScriptSubCall::VisualScriptSubCall() { ////////////////////////////////////////// int VisualScriptComment::get_output_sequence_port_count() const { - return 0; } bool VisualScriptComment::has_input_sequence_port() const { - return false; } @@ -3289,37 +2974,30 @@ int VisualScriptComment::get_input_value_port_count() const { return 0; } int VisualScriptComment::get_output_value_port_count() const { - return 0; } String VisualScriptComment::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptComment::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptComment::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptComment::get_caption() const { - return title; } String VisualScriptComment::get_text() const { - return description; } void VisualScriptComment::set_title(const String &p_title) { - if (title == p_title) return; title = p_title; @@ -3327,36 +3005,30 @@ void VisualScriptComment::set_title(const String &p_title) { } String VisualScriptComment::get_title() const { - return title; } void VisualScriptComment::set_description(const String &p_description) { - if (description == p_description) return; description = p_description; ports_changed_notify(); } String VisualScriptComment::get_description() const { - return description; } void VisualScriptComment::set_size(const Size2 &p_size) { - if (size == p_size) return; size = p_size; ports_changed_notify(); } Size2 VisualScriptComment::get_size() const { - return size; } String VisualScriptComment::get_category() const { - return "data"; } @@ -3367,20 +3039,17 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - return 0; } }; VisualScriptNodeInstance *VisualScriptComment::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceComment *instance = memnew(VisualScriptNodeInstanceComment); instance->instance = p_instance; return instance; } void VisualScriptComment::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_title", "title"), &VisualScriptComment::set_title); ClassDB::bind_method(D_METHOD("get_title"), &VisualScriptComment::get_title); @@ -3396,7 +3065,6 @@ void VisualScriptComment::_bind_methods() { } VisualScriptComment::VisualScriptComment() { - title = "Comment"; size = Size2(150, 150); } @@ -3406,12 +3074,10 @@ VisualScriptComment::VisualScriptComment() { ////////////////////////////////////////// int VisualScriptConstructor::get_output_sequence_port_count() const { - return 0; } bool VisualScriptConstructor::has_input_sequence_port() const { - return false; } @@ -3419,37 +3085,30 @@ int VisualScriptConstructor::get_input_value_port_count() const { return constructor.arguments.size(); } int VisualScriptConstructor::get_output_value_port_count() const { - return 1; } String VisualScriptConstructor::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptConstructor::get_input_value_port_info(int p_idx) const { - return constructor.arguments[p_idx]; } PropertyInfo VisualScriptConstructor::get_output_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } String VisualScriptConstructor::get_caption() const { - return "Construct " + Variant::get_type_name(type); } String VisualScriptConstructor::get_category() const { - return "functions"; } void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) { - if (type == p_type) return; @@ -3458,18 +3117,15 @@ void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) { } Variant::Type VisualScriptConstructor::get_constructor_type() const { - return type; } void VisualScriptConstructor::set_constructor(const Dictionary &p_info) { - constructor = MethodInfo::from_dict(p_info); ports_changed_notify(); } Dictionary VisualScriptConstructor::get_constructor() const { - return constructor; } @@ -3482,7 +3138,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Callable::CallError ce; *p_outputs[0] = Variant::construct(type, p_inputs, argcount, ce); if (ce.error != Callable::CallError::CALL_OK) { @@ -3494,7 +3149,6 @@ public: }; VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceConstructor *instance = memnew(VisualScriptNodeInstanceConstructor); instance->instance = p_instance; instance->type = type; @@ -3503,7 +3157,6 @@ VisualScriptNodeInstance *VisualScriptConstructor::instance(VisualScriptInstance } void VisualScriptConstructor::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constructor_type", "type"), &VisualScriptConstructor::set_constructor_type); ClassDB::bind_method(D_METHOD("get_constructor_type"), &VisualScriptConstructor::get_constructor_type); @@ -3515,14 +3168,12 @@ void VisualScriptConstructor::_bind_methods() { } VisualScriptConstructor::VisualScriptConstructor() { - type = Variant::NIL; } static Map<String, Pair<Variant::Type, MethodInfo>> constructor_map; static Ref<VisualScriptNode> create_constructor_node(const String &p_name) { - ERR_FAIL_COND_V(!constructor_map.has(p_name), Ref<VisualScriptNode>()); Ref<VisualScriptConstructor> vsc; @@ -3538,12 +3189,10 @@ static Ref<VisualScriptNode> create_constructor_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptLocalVar::get_output_sequence_port_count() const { - return 0; } bool VisualScriptLocalVar::has_input_sequence_port() const { - return false; } @@ -3551,36 +3200,29 @@ int VisualScriptLocalVar::get_input_value_port_count() const { return 0; } int VisualScriptLocalVar::get_output_value_port_count() const { - return 1; } String VisualScriptLocalVar::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptLocalVar::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const { - return PropertyInfo(type, name); } String VisualScriptLocalVar::get_caption() const { - return "Get Local Var"; } String VisualScriptLocalVar::get_category() const { - return "data"; } void VisualScriptLocalVar::set_var_name(const StringName &p_name) { - if (name == p_name) return; @@ -3589,18 +3231,15 @@ void VisualScriptLocalVar::set_var_name(const StringName &p_name) { } StringName VisualScriptLocalVar::get_var_name() const { - return name; } void VisualScriptLocalVar::set_var_type(Variant::Type p_type) { - type = p_type; ports_changed_notify(); } Variant::Type VisualScriptLocalVar::get_var_type() const { - return type; } @@ -3611,14 +3250,12 @@ public: virtual int get_working_memory_size() const { return 1; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_outputs[0] = *p_working_mem; return 0; } }; VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceLocalVar *instance = memnew(VisualScriptNodeInstanceLocalVar); instance->instance = p_instance; instance->name = name; @@ -3627,7 +3264,6 @@ VisualScriptNodeInstance *VisualScriptLocalVar::instance(VisualScriptInstance *p } void VisualScriptLocalVar::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVar::set_var_name); ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVar::get_var_name); @@ -3644,7 +3280,6 @@ void VisualScriptLocalVar::_bind_methods() { } VisualScriptLocalVar::VisualScriptLocalVar() { - name = "new_local"; type = Variant::NIL; } @@ -3654,12 +3289,10 @@ VisualScriptLocalVar::VisualScriptLocalVar() { ////////////////////////////////////////// int VisualScriptLocalVarSet::get_output_sequence_port_count() const { - return 1; } bool VisualScriptLocalVarSet::has_input_sequence_port() const { - return true; } @@ -3667,41 +3300,33 @@ int VisualScriptLocalVarSet::get_input_value_port_count() const { return 1; } int VisualScriptLocalVarSet::get_output_value_port_count() const { - return 1; } String VisualScriptLocalVarSet::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptLocalVarSet::get_input_value_port_info(int p_idx) const { - return PropertyInfo(type, "set"); } PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) const { - return PropertyInfo(type, "get"); } String VisualScriptLocalVarSet::get_caption() const { - return "Set Local Var"; } String VisualScriptLocalVarSet::get_text() const { - return name; } String VisualScriptLocalVarSet::get_category() const { - return "data"; } void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) { - if (name == p_name) return; @@ -3710,18 +3335,15 @@ void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) { } StringName VisualScriptLocalVarSet::get_var_name() const { - return name; } void VisualScriptLocalVarSet::set_var_type(Variant::Type p_type) { - type = p_type; ports_changed_notify(); } Variant::Type VisualScriptLocalVarSet::get_var_type() const { - return type; } @@ -3732,7 +3354,6 @@ public: virtual int get_working_memory_size() const { return 1; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - *p_working_mem = *p_inputs[0]; *p_outputs[0] = *p_working_mem; return 0; @@ -3740,7 +3361,6 @@ public: }; VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceLocalVarSet *instance = memnew(VisualScriptNodeInstanceLocalVarSet); instance->instance = p_instance; instance->name = name; @@ -3749,7 +3369,6 @@ VisualScriptNodeInstance *VisualScriptLocalVarSet::instance(VisualScriptInstance } void VisualScriptLocalVarSet::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVarSet::set_var_name); ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVarSet::get_var_name); @@ -3766,7 +3385,6 @@ void VisualScriptLocalVarSet::_bind_methods() { } VisualScriptLocalVarSet::VisualScriptLocalVarSet() { - name = "new_local"; type = Variant::NIL; } @@ -3776,12 +3394,10 @@ VisualScriptLocalVarSet::VisualScriptLocalVarSet() { ////////////////////////////////////////// int VisualScriptInputAction::get_output_sequence_port_count() const { - return 0; } bool VisualScriptInputAction::has_input_sequence_port() const { - return false; } @@ -3789,21 +3405,17 @@ int VisualScriptInputAction::get_input_value_port_count() const { return 0; } int VisualScriptInputAction::get_output_value_port_count() const { - return 1; } String VisualScriptInputAction::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptInputAction::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const { - String mstr; switch (mode) { case MODE_PRESSED: { @@ -3824,17 +3436,14 @@ PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) cons } String VisualScriptInputAction::get_caption() const { - return "Action " + name; } String VisualScriptInputAction::get_category() const { - return "data"; } void VisualScriptInputAction::set_action_name(const StringName &p_name) { - if (name == p_name) return; @@ -3843,12 +3452,10 @@ void VisualScriptInputAction::set_action_name(const StringName &p_name) { } StringName VisualScriptInputAction::get_action_name() const { - return name; } void VisualScriptInputAction::set_action_mode(Mode p_mode) { - if (mode == p_mode) return; @@ -3856,7 +3463,6 @@ void VisualScriptInputAction::set_action_mode(Mode p_mode) { ports_changed_notify(); } VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const { - return mode; } @@ -3867,7 +3473,6 @@ public: VisualScriptInputAction::Mode mode; virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - switch (mode) { case VisualScriptInputAction::MODE_PRESSED: { *p_outputs[0] = Input::get_singleton()->is_action_pressed(action); @@ -3888,7 +3493,6 @@ public: }; VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceInputAction *instance = memnew(VisualScriptNodeInstanceInputAction); instance->instance = p_instance; instance->action = name; @@ -3898,9 +3502,7 @@ VisualScriptNodeInstance *VisualScriptInputAction::instance(VisualScriptInstance } void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { - if (property.name == "action") { - property.hint = PROPERTY_HINT_ENUM; String actions; @@ -3932,7 +3534,6 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { } void VisualScriptInputAction::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_action_name", "name"), &VisualScriptInputAction::set_action_name); ClassDB::bind_method(D_METHOD("get_action_name"), &VisualScriptInputAction::get_action_name); @@ -3949,7 +3550,6 @@ void VisualScriptInputAction::_bind_methods() { } VisualScriptInputAction::VisualScriptInputAction() { - name = ""; mode = MODE_PRESSED; } @@ -3959,12 +3559,10 @@ VisualScriptInputAction::VisualScriptInputAction() { ////////////////////////////////////////// int VisualScriptDeconstruct::get_output_sequence_port_count() const { - return 0; } bool VisualScriptDeconstruct::has_input_sequence_port() const { - return false; } @@ -3972,37 +3570,30 @@ int VisualScriptDeconstruct::get_input_value_port_count() const { return 1; } int VisualScriptDeconstruct::get_output_value_port_count() const { - return elements.size(); } String VisualScriptDeconstruct::get_output_sequence_port_text(int p_port) const { - return ""; } PropertyInfo VisualScriptDeconstruct::get_input_value_port_info(int p_idx) const { - return PropertyInfo(type, "value"); } PropertyInfo VisualScriptDeconstruct::get_output_value_port_info(int p_idx) const { - return PropertyInfo(elements[p_idx].type, elements[p_idx].name); } String VisualScriptDeconstruct::get_caption() const { - return "Deconstruct " + Variant::get_type_name(type); } String VisualScriptDeconstruct::get_category() const { - return "functions"; } void VisualScriptDeconstruct::_update_elements() { - elements.clear(); Variant v; Callable::CallError ce; @@ -4012,7 +3603,6 @@ void VisualScriptDeconstruct::_update_elements() { v.get_property_list(&pinfo); for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { - Element e; e.name = E->get().name; e.type = E->get().type; @@ -4021,7 +3611,6 @@ void VisualScriptDeconstruct::_update_elements() { } void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) { - if (type == p_type) return; @@ -4032,12 +3621,10 @@ void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) { } Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const { - return type; } void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) { - ERR_FAIL_COND(p_elements.size() % 2 == 1); elements.resize(p_elements.size() / 2); for (int i = 0; i < elements.size(); i++) { @@ -4047,7 +3634,6 @@ void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) { } Array VisualScriptDeconstruct::_get_elem_cache() const { - Array ret; for (int i = 0; i < elements.size(); i++) { ret.push_back(elements[i].name); @@ -4064,7 +3650,6 @@ public: //virtual int get_working_memory_size() const { return 0; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - Variant in = *p_inputs[0]; for (int i = 0; i < outputs.size(); i++) { @@ -4082,7 +3667,6 @@ public: }; VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceDeconstruct *instance = memnew(VisualScriptNodeInstanceDeconstruct); instance->instance = p_instance; instance->outputs.resize(elements.size()); @@ -4097,7 +3681,6 @@ void VisualScriptDeconstruct::_validate_property(PropertyInfo &property) const { } void VisualScriptDeconstruct::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_deconstruct_type", "type"), &VisualScriptDeconstruct::set_deconstruct_type); ClassDB::bind_method(D_METHOD("get_deconstruct_type"), &VisualScriptDeconstruct::get_deconstruct_type); @@ -4114,7 +3697,6 @@ void VisualScriptDeconstruct::_bind_methods() { } VisualScriptDeconstruct::VisualScriptDeconstruct() { - type = Variant::NIL; } @@ -4127,7 +3709,6 @@ static Ref<VisualScriptNode> create_node_deconst_typed(const String &p_name) { } void register_visual_script_nodes() { - VisualScriptLanguage::singleton->add_register_func("data/set_variable", create_node_generic<VisualScriptVariableSet>); VisualScriptLanguage::singleton->add_register_func("data/get_variable", create_node_generic<VisualScriptVariableGet>); VisualScriptLanguage::singleton->add_register_func("data/engine_singleton", create_node_generic<VisualScriptEngineSingleton>); @@ -4199,12 +3780,10 @@ void register_visual_script_nodes() { VisualScriptLanguage::singleton->add_register_func("functions/compose_array", create_node_generic<VisualScriptComposeArray>); for (int i = 1; i < Variant::VARIANT_MAX; i++) { - List<MethodInfo> constructors; Variant::get_constructor_list(Variant::Type(i), &constructors); for (List<MethodInfo>::Element *E = constructors.front(); E; E = E->next()) { - if (E->get().arguments.size() > 0) { String name = "functions/constructors/" + Variant::get_type_name(Variant::Type(i)) + "("; for (int j = 0; j < E->get().arguments.size(); j++) { @@ -4229,6 +3808,5 @@ void register_visual_script_nodes() { } void unregister_visual_script_nodes() { - constructor_map.clear(); } diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index 0df5071491..fa284b216c 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptFunction : public VisualScriptNode { - GDCLASS(VisualScriptFunction, VisualScriptNode); struct Argument { @@ -104,7 +103,6 @@ public: }; class VisualScriptLists : public VisualScriptNode { - GDCLASS(VisualScriptLists, VisualScriptNode) struct Port { @@ -176,7 +174,6 @@ public: }; class VisualScriptComposeArray : public VisualScriptLists { - GDCLASS(VisualScriptComposeArray, VisualScriptLists) public: @@ -201,7 +198,6 @@ public: }; class VisualScriptOperator : public VisualScriptNode { - GDCLASS(VisualScriptOperator, VisualScriptNode); Variant::Type typed; @@ -237,7 +233,6 @@ public: }; class VisualScriptSelect : public VisualScriptNode { - GDCLASS(VisualScriptSelect, VisualScriptNode); Variant::Type typed; @@ -270,7 +265,6 @@ public: }; class VisualScriptVariableGet : public VisualScriptNode { - GDCLASS(VisualScriptVariableGet, VisualScriptNode); StringName variable; @@ -303,7 +297,6 @@ public: }; class VisualScriptVariableSet : public VisualScriptNode { - GDCLASS(VisualScriptVariableSet, VisualScriptNode); StringName variable; @@ -336,7 +329,6 @@ public: }; class VisualScriptConstant : public VisualScriptNode { - GDCLASS(VisualScriptConstant, VisualScriptNode); Variant::Type type; @@ -373,7 +365,6 @@ public: }; class VisualScriptPreload : public VisualScriptNode { - GDCLASS(VisualScriptPreload, VisualScriptNode); Ref<Resource> preload; @@ -405,7 +396,6 @@ public: }; class VisualScriptIndexGet : public VisualScriptNode { - GDCLASS(VisualScriptIndexGet, VisualScriptNode); public: @@ -429,7 +419,6 @@ public: }; class VisualScriptIndexSet : public VisualScriptNode { - GDCLASS(VisualScriptIndexSet, VisualScriptNode); public: @@ -453,7 +442,6 @@ public: }; class VisualScriptGlobalConstant : public VisualScriptNode { - GDCLASS(VisualScriptGlobalConstant, VisualScriptNode); int index; @@ -484,7 +472,6 @@ public: }; class VisualScriptClassConstant : public VisualScriptNode { - GDCLASS(VisualScriptClassConstant, VisualScriptNode); StringName base_type; @@ -521,7 +508,6 @@ public: }; class VisualScriptBasicTypeConstant : public VisualScriptNode { - GDCLASS(VisualScriptBasicTypeConstant, VisualScriptNode); Variant::Type type; @@ -559,7 +545,6 @@ public: }; class VisualScriptMathConstant : public VisualScriptNode { - GDCLASS(VisualScriptMathConstant, VisualScriptNode); public: @@ -609,7 +594,6 @@ public: VARIANT_ENUM_CAST(VisualScriptMathConstant::MathConstant) class VisualScriptEngineSingleton : public VisualScriptNode { - GDCLASS(VisualScriptEngineSingleton, VisualScriptNode); String singleton; @@ -645,7 +629,6 @@ public: }; class VisualScriptSceneNode : public VisualScriptNode { - GDCLASS(VisualScriptSceneNode, VisualScriptNode); NodePath path; @@ -680,7 +663,6 @@ public: }; class VisualScriptSceneTree : public VisualScriptNode { - GDCLASS(VisualScriptSceneTree, VisualScriptNode); protected: @@ -710,7 +692,6 @@ public: }; class VisualScriptResourcePath : public VisualScriptNode { - GDCLASS(VisualScriptResourcePath, VisualScriptNode); String path; @@ -742,7 +723,6 @@ public: }; class VisualScriptSelf : public VisualScriptNode { - GDCLASS(VisualScriptSelf, VisualScriptNode); protected: @@ -771,7 +751,6 @@ public: }; class VisualScriptCustomNode : public VisualScriptNode { - GDCLASS(VisualScriptCustomNode, VisualScriptNode); protected: @@ -819,7 +798,6 @@ public: VARIANT_ENUM_CAST(VisualScriptCustomNode::StartMode); class VisualScriptSubCall : public VisualScriptNode { - GDCLASS(VisualScriptSubCall, VisualScriptNode); protected: @@ -847,7 +825,6 @@ public: }; class VisualScriptComment : public VisualScriptNode { - GDCLASS(VisualScriptComment, VisualScriptNode); String title; @@ -888,7 +865,6 @@ public: }; class VisualScriptConstructor : public VisualScriptNode { - GDCLASS(VisualScriptConstructor, VisualScriptNode); Variant::Type type; @@ -924,7 +900,6 @@ public: }; class VisualScriptLocalVar : public VisualScriptNode { - GDCLASS(VisualScriptLocalVar, VisualScriptNode); StringName name; @@ -960,7 +935,6 @@ public: }; class VisualScriptLocalVarSet : public VisualScriptNode { - GDCLASS(VisualScriptLocalVarSet, VisualScriptNode); StringName name; @@ -997,7 +971,6 @@ public: }; class VisualScriptInputAction : public VisualScriptNode { - GDCLASS(VisualScriptInputAction, VisualScriptNode); public: @@ -1045,7 +1018,6 @@ public: VARIANT_ENUM_CAST(VisualScriptInputAction::Mode) class VisualScriptDeconstruct : public VisualScriptNode { - GDCLASS(VisualScriptDeconstruct, VisualScriptNode); struct Element { diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp index b06cf513ba..3cdf3f5d75 100644 --- a/modules/visual_script/visual_script_property_selector.cpp +++ b/modules/visual_script/visual_script_property_selector.cpp @@ -46,17 +46,14 @@ void VisualScriptPropertySelector::_text_changed(const String &p_newtext) { } void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) { - Ref<InputEventKey> k = p_ie; if (k.is_valid()) { - switch (k->get_keycode()) { case KEY_UP: case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { - search_options->call("_gui_input", k); search_box->accept_event(); @@ -199,7 +196,6 @@ void VisualScriptPropertySelector::_update_search() { v = Variant::construct(type, nullptr, 0, ce); v.get_method_list(&methods); } else { - Object *obj = ObjectDB::get_instance(script); if (Object::cast_to<Script>(obj)) { Object::cast_to<Script>(obj)->get_script_method_list(&methods); @@ -209,7 +205,6 @@ void VisualScriptPropertySelector::_update_search() { } } for (List<MethodInfo>::Element *M = methods.front(); M; M = M->next()) { - String name = M->get().name.get_slice(":", 0); if (name.begins_with("_") && !(M->get().flags & METHOD_FLAG_VIRTUAL)) continue; @@ -225,7 +220,6 @@ void VisualScriptPropertySelector::_update_search() { if (mi.arguments.size() > 0) { desc_arguments = "("; for (int i = 0; i < mi.arguments.size(); i++) { - if (i > 0) { desc_arguments += ", "; } @@ -411,7 +405,6 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt } void VisualScriptPropertySelector::_confirmed() { - TreeItem *ti = search_options->get_selected(); if (!ti) return; @@ -420,7 +413,6 @@ void VisualScriptPropertySelector::_confirmed() { } void VisualScriptPropertySelector::_item_selected() { - help_bit->set_text(""); TreeItem *item = search_options->get_selected(); @@ -442,7 +434,6 @@ void VisualScriptPropertySelector::_item_selected() { String at_class = class_type; while (at_class != String()) { - Map<String, DocData::ClassDoc>::Element *E = dd->class_list.find(at_class); if (E) { for (int i = 0; i < E->get().properties.size(); i++) { @@ -457,7 +448,6 @@ void VisualScriptPropertySelector::_item_selected() { at_class = class_type; while (at_class != String()) { - Map<String, DocData::ClassDoc>::Element *C = dd->class_list.find(at_class); if (C) { for (int i = 0; i < C->get().methods.size(); i++) { @@ -523,15 +513,12 @@ void VisualScriptPropertySelector::_hide_requested() { } void VisualScriptPropertySelector::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - connect("confirmed", callable_mp(this, &VisualScriptPropertySelector::_confirmed)); } } void VisualScriptPropertySelector::select_method_from_base_type(const String &p_base, const String &p_current, const bool p_virtuals_only, const bool p_connecting, bool clear_text) { - base_type = p_base; selected = p_current; type = Variant::NIL; @@ -555,7 +542,6 @@ void VisualScriptPropertySelector::set_type_filter(const Vector<Variant::Type> & } void VisualScriptPropertySelector::select_from_base_type(const String &p_base, const String &p_current, bool p_virtuals_only, bool p_seq_connect, const bool p_connecting, bool clear_text) { - base_type = p_base; selected = p_current; type = Variant::NIL; @@ -684,17 +670,14 @@ void VisualScriptPropertySelector::select_from_visual_script(const String &p_bas } void VisualScriptPropertySelector::show_window(float p_screen_ratio) { - popup_centered_ratio(p_screen_ratio); } void VisualScriptPropertySelector::_bind_methods() { - ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "name"), PropertyInfo(Variant::STRING, "category"), PropertyInfo(Variant::BOOL, "connecting"))); } VisualScriptPropertySelector::VisualScriptPropertySelector() { - vbc = memnew(VBoxContainer); add_child(vbc); //set_child_rect(vbc); diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index 2296745ad0..e87f42c6e9 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -40,46 +40,37 @@ ////////////////////////////////////////// int VisualScriptYield::get_output_sequence_port_count() const { - return 1; } bool VisualScriptYield::has_input_sequence_port() const { - return true; } int VisualScriptYield::get_input_value_port_count() const { - return 0; } int VisualScriptYield::get_output_value_port_count() const { - return 0; } String VisualScriptYield::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptYield::get_input_value_port_info(int p_idx) const { - return PropertyInfo(); } PropertyInfo VisualScriptYield::get_output_value_port_info(int p_idx) const { - return PropertyInfo(); } String VisualScriptYield::get_caption() const { - return yield_mode == YIELD_RETURN ? "Yield" : "Wait"; } String VisualScriptYield::get_text() const { - switch (yield_mode) { case YIELD_RETURN: return ""; @@ -108,7 +99,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return false; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_RESUME_YIELD) { return 0; //resuming yield } else { @@ -126,7 +116,6 @@ public: int ret = STEP_YIELD_BIT; switch (mode) { - case VisualScriptYield::YIELD_RETURN: ret = STEP_EXIT_FUNCTION_BIT; break; //return the yield @@ -149,7 +138,6 @@ public: }; VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceYield *instance = memnew(VisualScriptNodeInstanceYield); //instance->instance=p_instance; instance->mode = yield_mode; @@ -158,7 +146,6 @@ VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_in } void VisualScriptYield::set_yield_mode(YieldMode p_mode) { - if (yield_mode == p_mode) return; yield_mode = p_mode; @@ -167,12 +154,10 @@ void VisualScriptYield::set_yield_mode(YieldMode p_mode) { } VisualScriptYield::YieldMode VisualScriptYield::get_yield_mode() { - return yield_mode; } void VisualScriptYield::set_wait_time(float p_time) { - if (wait_time == p_time) return; wait_time = p_time; @@ -180,12 +165,10 @@ void VisualScriptYield::set_wait_time(float p_time) { } float VisualScriptYield::get_wait_time() { - return wait_time; } void VisualScriptYield::_validate_property(PropertyInfo &property) const { - if (property.name == "wait_time") { if (yield_mode != YIELD_WAIT) { property.usage = 0; @@ -194,7 +177,6 @@ void VisualScriptYield::_validate_property(PropertyInfo &property) const { } void VisualScriptYield::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_yield_mode", "mode"), &VisualScriptYield::set_yield_mode); ClassDB::bind_method(D_METHOD("get_yield_mode"), &VisualScriptYield::get_yield_mode); @@ -210,14 +192,12 @@ void VisualScriptYield::_bind_methods() { } VisualScriptYield::VisualScriptYield() { - yield_mode = YIELD_FRAME; wait_time = 1; } template <VisualScriptYield::YieldMode MODE> static Ref<VisualScriptNode> create_yield_node(const String &p_name) { - Ref<VisualScriptYield> node; node.instance(); node->set_yield_mode(MODE); @@ -229,18 +209,15 @@ static Ref<VisualScriptNode> create_yield_node(const String &p_name) { ////////////////////////////////////////////////// int VisualScriptYieldSignal::get_output_sequence_port_count() const { - return 1; } bool VisualScriptYieldSignal::has_input_sequence_port() const { - return true; } #ifdef TOOLS_ENABLED static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) return nullptr; @@ -260,7 +237,6 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const #endif Node *VisualScriptYieldSignal::_get_base_node() const { - #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); if (!script.is_valid()) @@ -295,7 +271,6 @@ Node *VisualScriptYieldSignal::_get_base_node() const { } StringName VisualScriptYieldSignal::_get_base_type() const { - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) return get_visual_script()->get_instance_base_type(); else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { @@ -308,14 +283,12 @@ StringName VisualScriptYieldSignal::_get_base_type() const { } int VisualScriptYieldSignal::get_input_value_port_count() const { - if (call_mode == CALL_MODE_INSTANCE) return 1; else return 0; } int VisualScriptYieldSignal::get_output_value_port_count() const { - MethodInfo sr; if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) @@ -325,12 +298,10 @@ int VisualScriptYieldSignal::get_output_value_port_count() const { } String VisualScriptYieldSignal::get_output_sequence_port_text(int p_port) const { - return String(); } PropertyInfo VisualScriptYieldSignal::get_input_value_port_info(int p_idx) const { - if (call_mode == CALL_MODE_INSTANCE) return PropertyInfo(Variant::OBJECT, "instance"); else @@ -338,7 +309,6 @@ PropertyInfo VisualScriptYieldSignal::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptYieldSignal::get_output_value_port_info(int p_idx) const { - MethodInfo sr; if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) @@ -348,7 +318,6 @@ PropertyInfo VisualScriptYieldSignal::get_output_value_port_info(int p_idx) cons } String VisualScriptYieldSignal::get_caption() const { - static const char *cname[3] = { "WaitSignal", "WaitNodeSignal", @@ -359,7 +328,6 @@ String VisualScriptYieldSignal::get_caption() const { } String VisualScriptYieldSignal::get_text() const { - if (call_mode == CALL_MODE_SELF) return " " + String(signal) + "()"; else @@ -367,7 +335,6 @@ String VisualScriptYieldSignal::get_text() const { } void VisualScriptYieldSignal::set_base_type(const StringName &p_type) { - if (base_type == p_type) return; @@ -378,12 +345,10 @@ void VisualScriptYieldSignal::set_base_type(const StringName &p_type) { } StringName VisualScriptYieldSignal::get_base_type() const { - return base_type; } void VisualScriptYieldSignal::set_signal(const StringName &p_type) { - if (signal == p_type) return; @@ -393,12 +358,10 @@ void VisualScriptYieldSignal::set_signal(const StringName &p_type) { ports_changed_notify(); } StringName VisualScriptYieldSignal::get_signal() const { - return signal; } void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) { - if (base_path == p_type) return; @@ -409,12 +372,10 @@ void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) { } NodePath VisualScriptYieldSignal::get_base_path() const { - return base_path; } void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) return; @@ -425,12 +386,10 @@ void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) { } VisualScriptYieldSignal::CallMode VisualScriptYieldSignal::get_call_mode() const { - return call_mode; } void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { - if (property.name == "base_type") { if (call_mode != CALL_MODE_INSTANCE) { property.usage = PROPERTY_USAGE_NOEDITOR; @@ -441,7 +400,6 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { if (call_mode != CALL_MODE_NODE_PATH) { property.usage = 0; } else { - Node *bnode = _get_base_node(); if (bnode) { property.hint_string = bnode->get_path(); //convert to loong string @@ -467,7 +425,6 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { String ml; for (List<String>::Element *E = mstring.front(); E; E = E->next()) { - if (ml != String()) ml += ","; ml += E->get(); @@ -478,7 +435,6 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { } void VisualScriptYieldSignal::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_base_type", "base_type"), &VisualScriptYieldSignal::set_base_type); ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptYieldSignal::get_base_type); @@ -524,7 +480,6 @@ public: //virtual bool get_output_port_unsequenced(int p_idx,Variant* r_value,Variant* p_working_mem,String &r_error) const { return true; } virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) { - if (p_start_mode == START_MODE_RESUME_YIELD) { return 0; //resuming yield } else { @@ -533,14 +488,11 @@ public: Object *object = nullptr; switch (call_mode) { - case VisualScriptYieldSignal::CALL_MODE_SELF: { - object = instance->get_owner_ptr(); } break; case VisualScriptYieldSignal::CALL_MODE_NODE_PATH: { - Node *node = Object::cast_to<Node>(instance->get_owner_ptr()); if (!node) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -559,7 +511,6 @@ public: } break; case VisualScriptYieldSignal::CALL_MODE_INSTANCE: { - object = *p_inputs[0]; if (!object) { r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD; @@ -583,7 +534,6 @@ public: }; VisualScriptNodeInstance *VisualScriptYieldSignal::instance(VisualScriptInstance *p_instance) { - VisualScriptNodeInstanceYieldSignal *instance = memnew(VisualScriptNodeInstanceYieldSignal); instance->node = this; instance->instance = p_instance; @@ -594,14 +544,12 @@ VisualScriptNodeInstance *VisualScriptYieldSignal::instance(VisualScriptInstance return instance; } VisualScriptYieldSignal::VisualScriptYieldSignal() { - call_mode = CALL_MODE_SELF; base_type = "Object"; } template <VisualScriptYieldSignal::CallMode cmode> static Ref<VisualScriptNode> create_yield_signal_node(const String &p_name) { - Ref<VisualScriptYieldSignal> node; node.instance(); node->set_call_mode(cmode); @@ -609,7 +557,6 @@ static Ref<VisualScriptNode> create_yield_signal_node(const String &p_name) { } void register_visual_script_yield_nodes() { - VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_frame", create_yield_node<VisualScriptYield::YIELD_FRAME>); VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_physics_frame", create_yield_node<VisualScriptYield::YIELD_PHYSICS_FRAME>); VisualScriptLanguage::singleton->add_register_func("functions/wait/wait_time", create_yield_node<VisualScriptYield::YIELD_WAIT>); diff --git a/modules/visual_script/visual_script_yield_nodes.h b/modules/visual_script/visual_script_yield_nodes.h index 4b976bd6c6..4877e8b7e6 100644 --- a/modules/visual_script/visual_script_yield_nodes.h +++ b/modules/visual_script/visual_script_yield_nodes.h @@ -34,7 +34,6 @@ #include "visual_script.h" class VisualScriptYield : public VisualScriptNode { - GDCLASS(VisualScriptYield, VisualScriptNode); public: @@ -84,7 +83,6 @@ public: VARIANT_ENUM_CAST(VisualScriptYield::YieldMode) class VisualScriptYieldSignal : public VisualScriptNode { - GDCLASS(VisualScriptYieldSignal, VisualScriptNode); public: diff --git a/modules/webm/register_types.cpp b/modules/webm/register_types.cpp index 5449dd458c..6248787879 100644 --- a/modules/webm/register_types.cpp +++ b/modules/webm/register_types.cpp @@ -35,7 +35,6 @@ static Ref<ResourceFormatLoaderWebm> resource_loader_webm; void register_webm_types() { - resource_loader_webm.instance(); ResourceLoader::add_resource_format_loader(resource_loader_webm, true); @@ -43,7 +42,6 @@ void register_webm_types() { } void unregister_webm_types() { - ResourceLoader::remove_resource_format_loader(resource_loader_webm); resource_loader_webm.unref(); } diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index faf1f32124..897900249e 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -48,24 +48,19 @@ #include <mkvparser/mkvparser.h> class MkvReader : public mkvparser::IMkvReader { - public: MkvReader(const String &p_file) { - file = FileAccess::open(p_file, FileAccess::READ); ERR_FAIL_COND_MSG(!file, "Failed loading resource: '" + p_file + "'."); } ~MkvReader() { - if (file) memdelete(file); } virtual int Read(long long pos, long len, unsigned char *buf) { - if (file) { - if (file->get_position() != (size_t)pos) file->seek(pos); if (file->get_buffer(buf, len) == len) @@ -75,9 +70,7 @@ public: } virtual int Length(long long *total, long long *available) { - if (file) { - const size_t len = file->get_len(); if (total) *total = len; @@ -98,26 +91,20 @@ VideoStreamPlaybackWebm::VideoStreamPlaybackWebm() : texture(memnew(ImageTexture)) {} VideoStreamPlaybackWebm::~VideoStreamPlaybackWebm() { - delete_pointers(); } bool VideoStreamPlaybackWebm::open_file(const String &p_file) { - file_name = p_file; webm = memnew(WebMDemuxer(new MkvReader(file_name), 0, audio_track)); if (webm->isOpen()) { - video = memnew(VPXDecoder(*webm, OS::get_singleton()->get_processor_count())); if (video->isOpen()) { - audio = memnew(OpusVorbisDecoder(*webm)); if (audio->isOpen()) { - audio_frame = memnew(WebMFrame); pcm = (float *)memalloc(sizeof(float) * audio->getBufferSamples() * webm->getChannels()); } else { - memdelete(audio); audio = nullptr; } @@ -139,9 +126,7 @@ bool VideoStreamPlaybackWebm::open_file(const String &p_file) { } void VideoStreamPlaybackWebm::stop() { - if (playing) { - delete_pointers(); pcm = nullptr; @@ -163,7 +148,6 @@ void VideoStreamPlaybackWebm::stop() { playing = false; } void VideoStreamPlaybackWebm::play() { - stop(); delay_compensation = ProjectSettings::get_singleton()->get("audio/video_delay_compensation_ms"); @@ -173,56 +157,45 @@ void VideoStreamPlaybackWebm::play() { } bool VideoStreamPlaybackWebm::is_playing() const { - return playing; } void VideoStreamPlaybackWebm::set_paused(bool p_paused) { - paused = p_paused; } bool VideoStreamPlaybackWebm::is_paused() const { - return paused; } void VideoStreamPlaybackWebm::set_loop(bool p_enable) { - //Empty } bool VideoStreamPlaybackWebm::has_loop() const { - return false; } float VideoStreamPlaybackWebm::get_length() const { - if (webm) return webm->getLength(); return 0.0f; } float VideoStreamPlaybackWebm::get_playback_position() const { - return video_pos; } void VideoStreamPlaybackWebm::seek(float p_time) { - //Not implemented } void VideoStreamPlaybackWebm::set_audio_track(int p_idx) { - audio_track = p_idx; } Ref<Texture2D> VideoStreamPlaybackWebm::get_texture() const { - return texture; } void VideoStreamPlaybackWebm::update(float p_delta) { - if ((!playing || paused) || !video) return; @@ -235,16 +208,13 @@ void VideoStreamPlaybackWebm::update(float p_delta) { bool audio_buffer_full = false; if (samples_offset > -1) { - //Mix remaining samples const int to_read = num_decoded_samples - samples_offset; const int mixed = mix_callback(mix_udata, pcm + samples_offset * webm->getChannels(), to_read); if (mixed != to_read) { - samples_offset += mixed; audio_buffer_full = true; } else { - samples_offset = -1; } } @@ -252,10 +222,8 @@ void VideoStreamPlaybackWebm::update(float p_delta) { const bool hasAudio = (audio && mix_callback); while ((hasAudio && !audio_buffer_full && !has_enough_video_frames()) || (!hasAudio && video_frames_pos == 0)) { - if (hasAudio && !audio_buffer_full && audio_frame->isValid() && audio->getPCMF(*audio_frame, pcm, num_decoded_samples) && num_decoded_samples > 0) { - const int mixed = mix_callback(mix_udata, pcm, num_decoded_samples); if (mixed != num_decoded_samples) { @@ -266,7 +234,6 @@ void VideoStreamPlaybackWebm::update(float p_delta) { WebMFrame *video_frame; if (video_frames_pos >= video_frames_capacity) { - WebMFrame **video_frames_new = (WebMFrame **)memrealloc(video_frames, ++video_frames_capacity * sizeof(void *)); ERR_FAIL_COND(!video_frames_new); //Out of memory (video_frames = video_frames_new)[video_frames_capacity - 1] = memnew(WebMFrame); @@ -282,26 +249,20 @@ void VideoStreamPlaybackWebm::update(float p_delta) { bool video_frame_done = false; while (video_frames_pos > 0 && !video_frame_done) { - WebMFrame *video_frame = video_frames[0]; // It seems VPXDecoder::decode has to be executed even though we might skip this frame if (video->decode(*video_frame)) { - VPXDecoder::IMAGE_ERROR err; VPXDecoder::Image image; if (should_process(*video_frame)) { - if ((err = video->getImage(image)) != VPXDecoder::NO_FRAME) { - if (err == VPXDecoder::NO_ERROR && image.w == webm->getWidth() && image.h == webm->getHeight()) { - uint8_t *w = frame_data.ptrw(); bool converted = false; if (image.chromaShiftW == 0 && image.chromaShiftH == 0 && image.cs == VPX_CS_SRGB) { - uint8_t *wp = w; unsigned char *rRow = image.planes[2]; unsigned char *gRow = image.planes[0]; @@ -319,22 +280,18 @@ void VideoStreamPlaybackWebm::update(float p_delta) { } converted = true; } else if (image.chromaShiftW == 1 && image.chromaShiftH == 1) { - yuv420_2_rgb8888(w, image.planes[0], image.planes[1], image.planes[2], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2); //libyuv::I420ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); converted = true; } else if (image.chromaShiftW == 1 && image.chromaShiftH == 0) { - yuv422_2_rgb8888(w, image.planes[0], image.planes[1], image.planes[2], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2); //libyuv::I422ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); converted = true; } else if (image.chromaShiftW == 0 && image.chromaShiftH == 0) { - yuv444_2_rgb8888(w, image.planes[0], image.planes[1], image.planes[2], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2); //libyuv::I444ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); converted = true; } else if (image.chromaShiftW == 2 && image.chromaShiftH == 0) { - //libyuv::I411ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2] image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); //converted = true; } @@ -359,18 +316,15 @@ void VideoStreamPlaybackWebm::update(float p_delta) { } void VideoStreamPlaybackWebm::set_mix_callback(VideoStreamPlayback::AudioMixCallback p_callback, void *p_userdata) { - mix_callback = p_callback; mix_udata = p_userdata; } int VideoStreamPlaybackWebm::get_channels() const { - if (audio) return webm->getChannels(); return 0; } int VideoStreamPlaybackWebm::get_mix_rate() const { - if (audio) return webm->getSampleRate(); return 0; @@ -397,7 +351,6 @@ bool VideoStreamPlaybackWebm::should_process(WebMFrame &video_frame) { } void VideoStreamPlaybackWebm::delete_pointers() { - if (pcm) memfree(pcm); @@ -423,7 +376,6 @@ void VideoStreamPlaybackWebm::delete_pointers() { VideoStreamWebm::VideoStreamWebm() {} Ref<VideoStreamPlayback> VideoStreamWebm::instance_playback() { - Ref<VideoStreamPlaybackWebm> pb = memnew(VideoStreamPlaybackWebm); pb->set_audio_track(audio_track); if (pb->open_file(file)) @@ -432,16 +384,13 @@ Ref<VideoStreamPlayback> VideoStreamWebm::instance_playback() { } void VideoStreamWebm::set_file(const String &p_file) { - file = p_file; } String VideoStreamWebm::get_file() { - return file; } void VideoStreamWebm::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamWebm::set_file); ClassDB::bind_method(D_METHOD("get_file"), &VideoStreamWebm::get_file); @@ -449,14 +398,12 @@ void VideoStreamWebm::_bind_methods() { } void VideoStreamWebm::set_audio_track(int p_track) { - audio_track = p_track; } //////////// RES ResourceFormatLoaderWebm::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - FileAccess *f = FileAccess::open(p_path, FileAccess::READ); if (!f) { if (r_error) { @@ -480,17 +427,14 @@ RES ResourceFormatLoaderWebm::load(const String &p_path, const String &p_origina } void ResourceFormatLoaderWebm::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("webm"); } bool ResourceFormatLoaderWebm::handles_type(const String &p_type) const { - return ClassDB::is_parent_class(p_type, "VideoStream"); } String ResourceFormatLoaderWebm::get_resource_type(const String &p_path) const { - String el = p_path.get_extension().to_lower(); if (el == "webm") return "VideoStreamWebm"; diff --git a/modules/webm/video_stream_webm.h b/modules/webm/video_stream_webm.h index 0a32dfc671..f6c148b29b 100644 --- a/modules/webm/video_stream_webm.h +++ b/modules/webm/video_stream_webm.h @@ -40,7 +40,6 @@ class VPXDecoder; class OpusVorbisDecoder; class VideoStreamPlaybackWebm : public VideoStreamPlayback { - GDCLASS(VideoStreamPlaybackWebm, VideoStreamPlayback); String file_name; @@ -107,7 +106,6 @@ private: /**/ class VideoStreamWebm : public VideoStream { - GDCLASS(VideoStreamWebm, VideoStream); String file; diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp index 6c778d2809..744b7ef8b9 100644 --- a/modules/webp/image_loader_webp.cpp +++ b/modules/webp/image_loader_webp.cpp @@ -39,7 +39,6 @@ #include <webp/encode.h> static Vector<uint8_t> _webp_lossy_pack(const Ref<Image> &p_image, float p_quality) { - ERR_FAIL_COND_V(p_image.is_null() || p_image->empty(), Vector<uint8_t>()); Ref<Image> img = p_image->duplicate(); @@ -55,7 +54,6 @@ static Vector<uint8_t> _webp_lossy_pack(const Ref<Image> &p_image, float p_quali uint8_t *dst_buff = nullptr; size_t dst_size = 0; if (img->get_format() == Image::FORMAT_RGB8) { - dst_size = WebPEncodeRGB(r, s.width, s.height, 3 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff); } else { dst_size = WebPEncodeRGBA(r, s.width, s.height, 4 * s.width, CLAMP(p_quality * 100.0, 0, 100.0), &dst_buff); @@ -76,7 +74,6 @@ static Vector<uint8_t> _webp_lossy_pack(const Ref<Image> &p_image, float p_quali } static Ref<Image> _webp_lossy_unpack(const Vector<uint8_t> &p_buffer) { - int size = p_buffer.size() - 4; ERR_FAIL_COND_V(size <= 0, Ref<Image>()); const uint8_t *r = p_buffer.ptr(); @@ -113,7 +110,6 @@ static Ref<Image> _webp_lossy_unpack(const Vector<uint8_t> &p_buffer) { } Error webp_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p_buffer_len) { - ERR_FAIL_NULL_V(p_image, ERR_INVALID_PARAMETER); WebPBitstreamFeatures features; @@ -141,7 +137,6 @@ Error webp_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p } static Ref<Image> _webp_mem_loader_func(const uint8_t *p_png, int p_size) { - Ref<Image> img; img.instance(); Error err = webp_load_image_from_buffer(img.ptr(), p_png, p_size); @@ -150,7 +145,6 @@ static Ref<Image> _webp_mem_loader_func(const uint8_t *p_png, int p_size) { } Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale) { - Vector<uint8_t> src_image; int src_image_len = f->get_len(); ERR_FAIL_COND_V(src_image_len == 0, ERR_FILE_CORRUPT); @@ -168,7 +162,6 @@ Error ImageLoaderWEBP::load_image(Ref<Image> p_image, FileAccess *f, bool p_forc } void ImageLoaderWEBP::get_recognized_extensions(List<String> *p_extensions) const { - p_extensions->push_back("webp"); } diff --git a/modules/webp/image_loader_webp.h b/modules/webp/image_loader_webp.h index 9206ca2525..49a7407600 100644 --- a/modules/webp/image_loader_webp.h +++ b/modules/webp/image_loader_webp.h @@ -34,7 +34,6 @@ #include "core/io/image_loader.h" class ImageLoaderWEBP : public ImageFormatLoader { - public: virtual Error load_image(Ref<Image> p_image, FileAccess *f, bool p_force_linear, float p_scale); virtual void get_recognized_extensions(List<String> *p_extensions) const; diff --git a/modules/webp/register_types.cpp b/modules/webp/register_types.cpp index fe945b01d4..0788b06309 100644 --- a/modules/webp/register_types.cpp +++ b/modules/webp/register_types.cpp @@ -35,12 +35,10 @@ static ImageLoaderWEBP *image_loader_webp = nullptr; void register_webp_types() { - image_loader_webp = memnew(ImageLoaderWEBP); ImageLoader::add_image_format_loader(image_loader_webp); } void unregister_webp_types() { - memdelete(image_loader_webp); } diff --git a/modules/webrtc/webrtc_data_channel_js.cpp b/modules/webrtc/webrtc_data_channel_js.cpp index 40c3f5801b..2c648ba9f9 100644 --- a/modules/webrtc/webrtc_data_channel_js.cpp +++ b/modules/webrtc/webrtc_data_channel_js.cpp @@ -68,7 +68,6 @@ void WebRTCDataChannelJS::_on_error() { } void WebRTCDataChannelJS::_on_message(uint8_t *p_data, uint32_t p_size, bool p_is_string) { - ERR_FAIL_COND_MSG(in_buffer.space_left() < (int)(p_size + 5), "Buffer full! Dropping data."); uint8_t is_string = p_is_string ? 1 : 0; diff --git a/modules/webrtc/webrtc_multiplayer.cpp b/modules/webrtc/webrtc_multiplayer.cpp index f294733961..72115628ed 100644 --- a/modules/webrtc/webrtc_multiplayer.cpp +++ b/modules/webrtc/webrtc_multiplayer.cpp @@ -320,7 +320,6 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) Map<int, Ref<ConnectedPeer>>::Element *E = nullptr; if (target_peer > 0) { - E = peer_map.find(target_peer); ERR_FAIL_COND_V_MSG(!E, ERR_INVALID_PARAMETER, "Invalid target peer: " + itos(target_peer) + "."); @@ -332,7 +331,6 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) int exclude = -target_peer; for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) { - // Exclude packet. If target_peer == 0 then don't exclude any packets if (target_peer != 0 && F->key() == exclude) continue; diff --git a/modules/webrtc/webrtc_multiplayer.h b/modules/webrtc/webrtc_multiplayer.h index 0e1335b8a8..876e2c6fe9 100644 --- a/modules/webrtc/webrtc_multiplayer.h +++ b/modules/webrtc/webrtc_multiplayer.h @@ -35,7 +35,6 @@ #include "webrtc_peer_connection.h" class WebRTCMultiplayer : public NetworkedMultiplayerPeer { - GDCLASS(WebRTCMultiplayer, NetworkedMultiplayerPeer); protected: @@ -50,7 +49,6 @@ private: }; class ConnectedPeer : public Reference { - public: Ref<WebRTCPeerConnection> connection; List<Ref<WebRTCDataChannel>> channels; diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp index 399e4f09ff..f71dcc956c 100644 --- a/modules/webrtc/webrtc_peer_connection.cpp +++ b/modules/webrtc/webrtc_peer_connection.cpp @@ -33,12 +33,10 @@ WebRTCPeerConnection *(*WebRTCPeerConnection::_create)() = nullptr; Ref<WebRTCPeerConnection> WebRTCPeerConnection::create_ref() { - return create(); } WebRTCPeerConnection *WebRTCPeerConnection::create() { - if (!_create) return nullptr; return _create(); diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.cpp b/modules/webrtc/webrtc_peer_connection_gdnative.cpp index f082646629..aaa45d3a54 100644 --- a/modules/webrtc/webrtc_peer_connection_gdnative.cpp +++ b/modules/webrtc/webrtc_peer_connection_gdnative.cpp @@ -49,7 +49,6 @@ Error WebRTCPeerConnectionGDNative::set_default_library(const godot_net_webrtc_l } WebRTCPeerConnection *WebRTCPeerConnectionGDNative::_create() { - WebRTCPeerConnectionGDNative *obj = memnew(WebRTCPeerConnectionGDNative); ERR_FAIL_COND_V_MSG(!default_library, obj, "Default GDNative WebRTC implementation not defined."); diff --git a/modules/webrtc/webrtc_peer_connection_js.h b/modules/webrtc/webrtc_peer_connection_js.h index 6540077e84..cdaf3068e3 100644 --- a/modules/webrtc/webrtc_peer_connection_js.h +++ b/modules/webrtc/webrtc_peer_connection_js.h @@ -36,7 +36,6 @@ #include "webrtc_peer_connection.h" class WebRTCPeerConnectionJS : public WebRTCPeerConnection { - private: int _js_id; ConnectionState _conn_state; diff --git a/modules/websocket/editor_debugger_server_websocket.h b/modules/websocket/editor_debugger_server_websocket.h index cd2c1e45cd..c66db1b72a 100644 --- a/modules/websocket/editor_debugger_server_websocket.h +++ b/modules/websocket/editor_debugger_server_websocket.h @@ -36,7 +36,6 @@ #include "editor/debugger/editor_debugger_server.h" class EditorDebuggerServerWebSocket : public EditorDebuggerServer { - GDCLASS(EditorDebuggerServerWebSocket, EditorDebuggerServer); private: diff --git a/modules/websocket/emws_client.cpp b/modules/websocket/emws_client.cpp index bc9d75d327..7c31449709 100644 --- a/modules/websocket/emws_client.cpp +++ b/modules/websocket/emws_client.cpp @@ -65,7 +65,6 @@ EMSCRIPTEN_KEEPALIVE void _esws_on_close(void *obj, int code, char *reason, int } Error EMWSClient::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) { - String proto_string; for (int i = 0; i < p_protocols.size(); i++) { if (i != 0) @@ -190,12 +189,10 @@ void EMWSClient::poll() { } Ref<WebSocketPeer> EMWSClient::get_peer(int p_peer_id) const { - return _peer; } NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() const { - if (_peer->is_connected_to_host()) { if (_is_connecting) return CONNECTION_CONNECTING; @@ -206,17 +203,14 @@ NetworkedMultiplayerPeer::ConnectionStatus EMWSClient::get_connection_status() c }; void EMWSClient::disconnect_from_host(int p_code, String p_reason) { - _peer->close(p_code, p_reason); }; IP_Address EMWSClient::get_connected_host() const { - ERR_FAIL_V_MSG(IP_Address(), "Not supported in HTML5 export."); }; uint16_t EMWSClient::get_connected_port() const { - ERR_FAIL_V_MSG(0, "Not supported in HTML5 export."); }; @@ -244,7 +238,6 @@ EMWSClient::EMWSClient() { }; EMWSClient::~EMWSClient() { - disconnect_from_host(); _peer = Ref<EMWSPeer>(); /* clang-format off */ diff --git a/modules/websocket/emws_client.h b/modules/websocket/emws_client.h index 9f1c220ed4..ab8a0612bb 100644 --- a/modules/websocket/emws_client.h +++ b/modules/websocket/emws_client.h @@ -38,7 +38,6 @@ #include "websocket_client.h" class EMWSClient : public WebSocketClient { - GDCIIMPL(EMWSClient, WebSocketClient); private: diff --git a/modules/websocket/emws_peer.cpp b/modules/websocket/emws_peer.cpp index 9472daa620..749f45451a 100644 --- a/modules/websocket/emws_peer.cpp +++ b/modules/websocket/emws_peer.cpp @@ -34,7 +34,6 @@ #include "core/io/ip.h" void EMWSPeer::set_sock(int p_sock, unsigned int p_in_buf_size, unsigned int p_in_pkt_size) { - peer_sock = p_sock; _in_buffer.resize(p_in_pkt_size, p_in_buf_size); _packet_buffer.resize((1 << p_in_buf_size)); @@ -49,13 +48,11 @@ EMWSPeer::WriteMode EMWSPeer::get_write_mode() const { } Error EMWSPeer::read_msg(uint8_t *p_data, uint32_t p_size, bool p_is_string) { - uint8_t is_string = p_is_string ? 1 : 0; return _in_buffer.write_packet(p_data, p_size, &is_string); } Error EMWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - int is_bin = write_mode == WebSocketPeer::WRITE_MODE_BINARY ? 1 : 0; /* clang-format off */ @@ -86,7 +83,6 @@ Error EMWSPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { }; Error EMWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - if (_in_buffer.packets_left() == 0) return ERR_UNAVAILABLE; @@ -101,22 +97,18 @@ Error EMWSPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { }; 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) { /* clang-format off */ EM_ASM({ @@ -134,17 +126,14 @@ void EMWSPeer::close(int p_code, String p_reason) { }; IP_Address EMWSPeer::get_connected_host() const { - ERR_FAIL_V_MSG(IP_Address(), "Not supported in HTML5 export."); }; 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."); } @@ -155,7 +144,6 @@ EMWSPeer::EMWSPeer() { }; EMWSPeer::~EMWSPeer() { - close(); }; diff --git a/modules/websocket/emws_peer.h b/modules/websocket/emws_peer.h index 6308ebe490..9c00f2d58b 100644 --- a/modules/websocket/emws_peer.h +++ b/modules/websocket/emws_peer.h @@ -41,7 +41,6 @@ #include "websocket_peer.h" class EMWSPeer : public WebSocketPeer { - GDCIIMPL(EMWSPeer, WebSocketPeer); private: diff --git a/modules/websocket/emws_server.cpp b/modules/websocket/emws_server.cpp index 95cffb4775..9d43283d3e 100644 --- a/modules/websocket/emws_server.cpp +++ b/modules/websocket/emws_server.cpp @@ -34,7 +34,6 @@ #include "core/os/os.h" Error EMWSServer::listen(int p_port, Vector<String> p_protocols, bool gd_mp_api) { - return FAILED; } @@ -60,12 +59,10 @@ Vector<String> EMWSServer::get_protocols() const { } IP_Address EMWSServer::get_peer_address(int p_peer_id) const { - return IP_Address(); } int EMWSServer::get_peer_port(int p_peer_id) const { - return 0; } diff --git a/modules/websocket/emws_server.h b/modules/websocket/emws_server.h index f273fd078f..bb6f35a711 100644 --- a/modules/websocket/emws_server.h +++ b/modules/websocket/emws_server.h @@ -38,7 +38,6 @@ #include "websocket_server.h" class EMWSServer : public WebSocketServer { - GDCIIMPL(EMWSServer, WebSocketServer); public: diff --git a/modules/websocket/packet_buffer.h b/modules/websocket/packet_buffer.h index 5f5f0e20cd..9973efe297 100644 --- a/modules/websocket/packet_buffer.h +++ b/modules/websocket/packet_buffer.h @@ -36,7 +36,6 @@ template <class T> class PacketBuffer { - private: typedef struct { uint32_t size; diff --git a/modules/websocket/remote_debugger_peer_websocket.cpp b/modules/websocket/remote_debugger_peer_websocket.cpp index 6ff03651d1..a0629ecf00 100644 --- a/modules/websocket/remote_debugger_peer_websocket.cpp +++ b/modules/websocket/remote_debugger_peer_websocket.cpp @@ -33,7 +33,6 @@ #include "core/project_settings.h" Error RemoteDebuggerPeerWebSocket::connect_to_host(const String &p_uri) { - Vector<String> protocols; protocols.push_back("binary"); // Compatibility for emscripten TCP-to-WebSocket. @@ -41,7 +40,6 @@ Error RemoteDebuggerPeerWebSocket::connect_to_host(const String &p_uri) { ws_client->poll(); if (ws_client->get_connection_status() == WebSocketClient::CONNECTION_DISCONNECTED) { - ERR_PRINT("Remote Debugger: Unable to connect. Status: " + String::num(ws_client->get_connection_status()) + "."); return FAILED; } diff --git a/modules/websocket/remote_debugger_peer_websocket.h b/modules/websocket/remote_debugger_peer_websocket.h index 33e4edaa21..bb03e5e892 100644 --- a/modules/websocket/remote_debugger_peer_websocket.h +++ b/modules/websocket/remote_debugger_peer_websocket.h @@ -39,7 +39,6 @@ #include "core/debugger/remote_debugger_peer.h" class RemoteDebuggerPeerWebSocket : public RemoteDebuggerPeer { - Ref<WebSocketClient> ws_client; Ref<WebSocketPeer> ws_peer; List<Array> in_queue; diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp index 7ee4b990b5..7cf3bf74bb 100644 --- a/modules/websocket/websocket_client.cpp +++ b/modules/websocket/websocket_client.cpp @@ -33,7 +33,6 @@ GDCINULL(WebSocketClient); WebSocketClient::WebSocketClient() { - verify_ssl = true; } @@ -76,33 +75,27 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto } void WebSocketClient::set_verify_ssl_enabled(bool p_verify_ssl) { - verify_ssl = p_verify_ssl; } bool WebSocketClient::is_verify_ssl_enabled() const { - return verify_ssl; } Ref<X509Certificate> WebSocketClient::get_trusted_ssl_certificate() const { - return ssl_cert; } void WebSocketClient::set_trusted_ssl_certificate(Ref<X509Certificate> p_cert) { - ERR_FAIL_COND(get_connection_status() != CONNECTION_DISCONNECTED); ssl_cert = p_cert; } bool WebSocketClient::is_server() const { - return false; } void WebSocketClient::_on_peer_packet() { - if (_is_multiplayer) { _process_multiplayer(get_peer(1), 1); } else { @@ -111,7 +104,6 @@ void WebSocketClient::_on_peer_packet() { } void WebSocketClient::_on_connect(String p_protocol) { - if (_is_multiplayer) { // need to wait for ID confirmation... } else { @@ -120,12 +112,10 @@ void WebSocketClient::_on_connect(String p_protocol) { } void WebSocketClient::_on_close_request(int p_code, String p_reason) { - emit_signal("server_close_request", p_code, p_reason); } void WebSocketClient::_on_disconnect(bool p_was_clean) { - if (_is_multiplayer) { emit_signal("connection_failed"); } else { @@ -134,7 +124,6 @@ void WebSocketClient::_on_disconnect(bool p_was_clean) { } void WebSocketClient::_on_error() { - if (_is_multiplayer) { emit_signal("connection_failed"); } else { diff --git a/modules/websocket/websocket_client.h b/modules/websocket/websocket_client.h index 4dc1224066..ba8e21aed6 100644 --- a/modules/websocket/websocket_client.h +++ b/modules/websocket/websocket_client.h @@ -37,7 +37,6 @@ #include "websocket_peer.h" class WebSocketClient : public WebSocketMultiplayerPeer { - GDCLASS(WebSocketClient, WebSocketMultiplayerPeer); GDCICLASS(WebSocketClient); diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index 9b71b32e33..57f577dca1 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -33,7 +33,6 @@ #include "core/os/os.h" WebSocketMultiplayerPeer::WebSocketMultiplayerPeer() { - _is_multiplayer = false; _peer_id = 0; _target_peer = 0; @@ -46,16 +45,13 @@ WebSocketMultiplayerPeer::WebSocketMultiplayerPeer() { } WebSocketMultiplayerPeer::~WebSocketMultiplayerPeer() { - _clear(); } int WebSocketMultiplayerPeer::_gen_unique_id() const { - uint32_t hash = 0; while (hash == 0 || hash == 1) { - hash = hash_djb2_one_32( (uint32_t)OS::get_singleton()->get_ticks_usec()); hash = hash_djb2_one_32( @@ -72,7 +68,6 @@ int WebSocketMultiplayerPeer::_gen_unique_id() const { return hash; } void WebSocketMultiplayerPeer::_clear() { - _peer_map.clear(); if (_current_packet.data != nullptr) memfree(_current_packet.data); @@ -86,7 +81,6 @@ void WebSocketMultiplayerPeer::_clear() { } void WebSocketMultiplayerPeer::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_buffers", "input_buffer_size_kb", "input_max_packets", "output_buffer_size_kb", "output_max_packets"), &WebSocketMultiplayerPeer::set_buffers); ClassDB::bind_method(D_METHOD("get_peer", "peer_id"), &WebSocketMultiplayerPeer::get_peer); @@ -97,14 +91,12 @@ void WebSocketMultiplayerPeer::_bind_methods() { // PacketPeer // int WebSocketMultiplayerPeer::get_available_packet_count() const { - ERR_FAIL_COND_V_MSG(!_is_multiplayer, 0, "Please use get_peer(ID).get_available_packet_count to get available packet count from peers when not using the MultiplayerAPI."); return _incoming_packets.size(); } Error WebSocketMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - ERR_FAIL_COND_V_MSG(!_is_multiplayer, ERR_UNCONFIGURED, "Please use get_peer(ID).get_packet/var to communicate with peers when not using the MultiplayerAPI."); r_buffer_size = 0; @@ -124,7 +116,6 @@ Error WebSocketMultiplayerPeer::get_packet(const uint8_t **r_buffer, int &r_buff } Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V_MSG(!_is_multiplayer, ERR_UNCONFIGURED, "Please use get_peer(ID).put_packet/var to communicate with peers when not using the MultiplayerAPI."); Vector<uint8_t> buffer = _make_pkt(SYS_NONE, get_unique_id(), _target_peer, p_buffer, p_buffer_size); @@ -140,23 +131,19 @@ Error WebSocketMultiplayerPeer::put_packet(const uint8_t *p_buffer, int p_buffer // NetworkedMultiplayerPeer // void WebSocketMultiplayerPeer::set_transfer_mode(TransferMode p_mode) { - // Websocket uses TCP, reliable } NetworkedMultiplayerPeer::TransferMode WebSocketMultiplayerPeer::get_transfer_mode() const { - // Websocket uses TCP, reliable return TRANSFER_MODE_RELIABLE; } void WebSocketMultiplayerPeer::set_target_peer(int p_target_peer) { - _target_peer = p_target_peer; } int WebSocketMultiplayerPeer::get_packet_peer() const { - ERR_FAIL_COND_V_MSG(!_is_multiplayer, 1, "This function is not available when not using the MultiplayerAPI."); ERR_FAIL_COND_V(_incoming_packets.size() == 0, 1); @@ -164,22 +151,18 @@ int WebSocketMultiplayerPeer::get_packet_peer() const { } int WebSocketMultiplayerPeer::get_unique_id() const { - return _peer_id; } void WebSocketMultiplayerPeer::set_refuse_new_connections(bool p_enable) { - _refusing = p_enable; } bool WebSocketMultiplayerPeer::is_refusing_new_connections() const { - return _refusing; } void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_type, int32_t p_peer_id) { - ERR_FAIL_COND(!p_peer.is_valid()); ERR_FAIL_COND(!p_peer->is_connected_to_host()); @@ -188,7 +171,6 @@ void WebSocketMultiplayerPeer::_send_sys(Ref<WebSocketPeer> p_peer, uint8_t p_ty } Vector<uint8_t> WebSocketMultiplayerPeer::_make_pkt(uint8_t p_type, int32_t p_from, int32_t p_to, const uint8_t *p_data, uint32_t p_data_size) { - Vector<uint8_t> out; out.resize(PROTO_SIZE + p_data_size); @@ -202,7 +184,6 @@ Vector<uint8_t> WebSocketMultiplayerPeer::_make_pkt(uint8_t p_type, int32_t p_fr } void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) { - // First of all, confirm the ID! _send_sys(get_peer(p_peer_id), SYS_ID, p_peer_id); @@ -242,11 +223,9 @@ void WebSocketMultiplayerPeer::_store_pkt(int32_t p_source, int32_t p_dest, cons Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, const uint8_t *p_buffer, uint32_t p_buffer_size) { if (p_to == 1) { - return OK; // Will not send to self } else if (p_to == 0) { - for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { if (E->key() != p_from) E->get()->put_packet(p_buffer, p_buffer_size); @@ -254,7 +233,6 @@ Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, cons return OK; // Sent to all but sender } else if (p_to < 0) { - for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { if (E->key() != p_from && E->key() != -p_to) E->get()->put_packet(p_buffer, p_buffer_size); @@ -262,7 +240,6 @@ Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, cons return OK; // Sent to all but sender and excluded } else { - ERR_FAIL_COND_V(p_to == p_from, FAILED); Ref<WebSocketPeer> peer_to = get_peer(p_to); @@ -273,7 +250,6 @@ Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, cons } void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, uint32_t p_peer_id) { - ERR_FAIL_COND(!p_peer.is_valid()); const uint8_t *in_buffer; @@ -304,12 +280,10 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u _store_pkt(from, to, in_buffer, data_size); } else if (to == 0) { - // Broadcast, for us too _store_pkt(from, to, in_buffer, data_size); } else if (to < 0) { - // All but one, for us if not excluded if (_peer_id != -(int32_t)p_peer_id) _store_pkt(from, to, in_buffer, data_size); @@ -318,7 +292,6 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u _server_relay(from, to, in_buffer, size); } else { - if (type == SYS_NONE) { // Payload message _store_pkt(from, to, in_buffer, data_size); @@ -331,7 +304,6 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u copymem(&id, &in_buffer[PROTO_SIZE], 4); switch (type) { - case SYS_ADD: // Add peer _peer_map[id] = Ref<WebSocketPeer>(); emit_signal("peer_connected", id); diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h index c6669c730c..3ee26e2c5b 100644 --- a/modules/websocket/websocket_multiplayer_peer.h +++ b/modules/websocket/websocket_multiplayer_peer.h @@ -37,7 +37,6 @@ #include "websocket_peer.h" class WebSocketMultiplayerPeer : public NetworkedMultiplayerPeer { - GDCLASS(WebSocketMultiplayerPeer, NetworkedMultiplayerPeer); private: diff --git a/modules/websocket/websocket_peer.h b/modules/websocket/websocket_peer.h index d4173600ec..5f7d1c768b 100644 --- a/modules/websocket/websocket_peer.h +++ b/modules/websocket/websocket_peer.h @@ -36,7 +36,6 @@ #include "websocket_macros.h" class WebSocketPeer : public PacketPeer { - GDCLASS(WebSocketPeer, PacketPeer); GDCICLASS(WebSocketPeer); diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp index a7ced65543..4c1fcff626 100644 --- a/modules/websocket/websocket_server.cpp +++ b/modules/websocket/websocket_server.cpp @@ -41,7 +41,6 @@ WebSocketServer::~WebSocketServer() { } void WebSocketServer::_bind_methods() { - ClassDB::bind_method(D_METHOD("is_listening"), &WebSocketServer::is_listening); ClassDB::bind_method(D_METHOD("listen", "port", "protocols", "gd_mp_api"), &WebSocketServer::listen, DEFVAL(Vector<String>()), DEFVAL(false)); ClassDB::bind_method(D_METHOD("stop"), &WebSocketServer::stop); @@ -117,12 +116,10 @@ NetworkedMultiplayerPeer::ConnectionStatus WebSocketServer::get_connection_statu } bool WebSocketServer::is_server() const { - return true; } void WebSocketServer::_on_peer_packet(int32_t p_peer_id) { - if (_is_multiplayer) { _process_multiplayer(get_peer(p_peer_id), p_peer_id); } else { @@ -131,7 +128,6 @@ void WebSocketServer::_on_peer_packet(int32_t p_peer_id) { } void WebSocketServer::_on_connect(int32_t p_peer_id, String p_protocol) { - if (_is_multiplayer) { // Send add to clients _send_add(p_peer_id); @@ -142,7 +138,6 @@ void WebSocketServer::_on_connect(int32_t p_peer_id, String p_protocol) { } 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); @@ -153,6 +148,5 @@ void WebSocketServer::_on_disconnect(int32_t p_peer_id, bool 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); } diff --git a/modules/websocket/websocket_server.h b/modules/websocket/websocket_server.h index 3ce4dbe711..5df0a37945 100644 --- a/modules/websocket/websocket_server.h +++ b/modules/websocket/websocket_server.h @@ -37,7 +37,6 @@ #include "websocket_peer.h" class WebSocketServer : public WebSocketMultiplayerPeer { - GDCLASS(WebSocketServer, WebSocketMultiplayerPeer); GDCICLASS(WebSocketServer); diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index 0eaafe2d66..271e475786 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -154,7 +154,6 @@ 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); _peer = Ref<WSLPeer>(memnew(WSLPeer)); @@ -278,14 +277,12 @@ void WSLClient::poll() { } Ref<WebSocketPeer> WSLClient::get_peer(int p_peer_id) const { - ERR_FAIL_COND_V(p_peer_id != 1, nullptr); return _peer; } NetworkedMultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const { - if (_peer->is_connected_to_host()) return CONNECTION_CONNECTED; @@ -296,7 +293,6 @@ NetworkedMultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() co } void WSLClient::disconnect_from_host(int p_code, String p_reason) { - _peer->close(p_code, p_reason); _connection = Ref<StreamPeer>(nullptr); _tcp = Ref<StreamPeerTCP>(memnew(StreamPeerTCP)); @@ -314,13 +310,11 @@ void WSLClient::disconnect_from_host(int p_code, String p_reason) { } IP_Address WSLClient::get_connected_host() const { - ERR_FAIL_COND_V(!_peer->is_connected_to_host(), IP_Address()); return _peer->get_connected_host(); } uint16_t WSLClient::get_connected_port() const { - ERR_FAIL_COND_V(!_peer->is_connected_to_host(), 0); return _peer->get_connected_port(); } @@ -347,7 +341,6 @@ WSLClient::WSLClient() { } WSLClient::~WSLClient() { - _peer->close_now(); _peer->invalidate(); disconnect_from_host(); diff --git a/modules/websocket/wsl_client.h b/modules/websocket/wsl_client.h index 2cecfd97ee..8355a5a737 100644 --- a/modules/websocket/wsl_client.h +++ b/modules/websocket/wsl_client.h @@ -41,7 +41,6 @@ #include "wslay/wslay.h" class WSLClient : public WebSocketClient { - GDCIIMPL(WSLClient, WebSocketClient); private: diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp index 44b71f70f4..98dff6fec9 100644 --- a/modules/websocket/wsl_peer.cpp +++ b/modules/websocket/wsl_peer.cpp @@ -234,7 +234,6 @@ void WSLPeer::poll() { } Error WSLPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { - ERR_FAIL_COND_V(!is_connected_to_host(), FAILED); struct wslay_event_msg msg; // Should I use fragmented? @@ -251,7 +250,6 @@ Error WSLPeer::put_packet(const uint8_t *p_buffer, int p_buffer_size) { } Error WSLPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { - r_buffer_size = 0; ERR_FAIL_COND_V(!is_connected_to_host(), FAILED); @@ -270,7 +268,6 @@ Error WSLPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { } int WSLPeer::get_available_packet_count() const { - if (!is_connected_to_host()) return 0; @@ -278,12 +275,10 @@ int WSLPeer::get_available_packet_count() const { } bool WSLPeer::was_string_packet() const { - return _is_string; } bool WSLPeer::is_connected_to_host() const { - return _data != nullptr; } @@ -305,21 +300,18 @@ void WSLPeer::close(int p_code, String p_reason) { } IP_Address WSLPeer::get_connected_host() const { - ERR_FAIL_COND_V(!is_connected_to_host() || _data->tcp.is_null(), IP_Address()); return _data->tcp->get_connected_host(); } uint16_t WSLPeer::get_connected_port() const { - ERR_FAIL_COND_V(!is_connected_to_host() || _data->tcp.is_null(), 0); return _data->tcp->get_connected_port(); } void WSLPeer::set_no_delay(bool p_enabled) { - ERR_FAIL_COND(!is_connected_to_host() || _data->tcp.is_null()); _data->tcp->set_no_delay(p_enabled); } @@ -337,7 +329,6 @@ WSLPeer::WSLPeer() { } WSLPeer::~WSLPeer() { - close(); invalidate(); _wsl_destroy(&_data); diff --git a/modules/websocket/wsl_peer.h b/modules/websocket/wsl_peer.h index 3b0639831a..fe4abfb64c 100644 --- a/modules/websocket/wsl_peer.h +++ b/modules/websocket/wsl_peer.h @@ -44,7 +44,6 @@ #define WSL_MAX_HEADER_SIZE 4096 class WSLPeer : public WebSocketPeer { - GDCIIMPL(WSLPeer, WebSocketPeer); public: diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index cc4685973e..a3f4349f04 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -169,7 +169,6 @@ Error WSLServer::listen(int p_port, const Vector<String> p_protocols, bool gd_mp } void WSLServer::poll() { - List<int> remove_ids; for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { Ref<WSLPeer> peer = (WSLPeer *)E->get().ptr(); diff --git a/modules/websocket/wsl_server.h b/modules/websocket/wsl_server.h index 2e893d6727..f86de02797 100644 --- a/modules/websocket/wsl_server.h +++ b/modules/websocket/wsl_server.h @@ -43,12 +43,10 @@ #define WSL_SERVER_TIMEOUT 1000 class WSLServer : public WebSocketServer { - GDCIIMPL(WSLServer, WebSocketServer); private: class PendingPeer : public Reference { - private: bool _parse_request(const Vector<String> p_protocols); diff --git a/modules/xatlas_unwrap/register_types.cpp b/modules/xatlas_unwrap/register_types.cpp index f77646ce28..b996be2a4c 100644 --- a/modules/xatlas_unwrap/register_types.cpp +++ b/modules/xatlas_unwrap/register_types.cpp @@ -42,7 +42,6 @@ extern bool (*array_mesh_lightmap_unwrap_callback)(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, int p_index_count, float **r_uv, int **r_vertex, int *r_vertex_count, int **r_index, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y, int *&r_cache_data, unsigned int &r_cache_size, bool &r_used_cache); bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_vertices, const float *p_normals, int p_vertex_count, const int *p_indices, int p_index_count, float **r_uvs, int **r_vertices, int *r_vertex_count, int **r_indices, int *r_index_count, int *r_size_hint_x, int *r_size_hint_y, int *&r_cache_data, unsigned int &r_cache_size, bool &r_used_cache) { - CryptoCore::MD5Context ctx; ctx.start(); @@ -230,7 +229,6 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver } void register_xatlas_unwrap_types() { - array_mesh_lightmap_unwrap_callback = xatlas_mesh_lightmap_unwrap_callback; } |