diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 16:41:43 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2020-05-14 21:57:34 +0200 |
commit | 0ee0fa42e6639b6fa474b7cf6afc6b1a78142185 (patch) | |
tree | 198d4ff7665d89307f6ca2469fa38620a9eb1672 /modules | |
parent | 07bc4e2f96f8f47991339654ff4ab16acc19d44f (diff) |
Style: Enforce braces around if blocks and loops
Using clang-tidy's `readability-braces-around-statements`.
https://clang.llvm.org/extra/clang-tidy/checks/readability-braces-around-statements.html
Diffstat (limited to 'modules')
101 files changed, 2707 insertions, 1443 deletions
diff --git a/modules/assimp/editor_scene_importer_assimp.cpp b/modules/assimp/editor_scene_importer_assimp.cpp index 7f0e27b0ee..9c90faf66b 100644 --- a/modules/assimp/editor_scene_importer_assimp.cpp +++ b/modules/assimp/editor_scene_importer_assimp.cpp @@ -208,8 +208,9 @@ T EditorSceneImporterAssimp::_interpolate_track(const Vector<float> &p_times, co //could use binary search, worth it? int idx = -1; for (int i = 0; i < p_times.size(); i++) { - if (p_times[i] > p_time) + if (p_times[i] > p_time) { break; + } idx++; } diff --git a/modules/basis_universal/register_types.cpp b/modules/basis_universal/register_types.cpp index d3cfcc0092..27b299a65d 100644 --- a/modules/basis_universal/register_types.cpp +++ b/modules/basis_universal/register_types.cpp @@ -240,8 +240,9 @@ static Ref<Image> basis_universal_unpacker(const Vector<uint8_t> &p_buffer) { { uint8_t *w = gpudata.ptrw(); uint8_t *dst = w; - for (int i = 0; i < gpudata.size(); i++) + for (int i = 0; i < gpudata.size(); i++) { dst[i] = 0x00; + } int ofs = 0; tr.start_transcoding(ptr, size); diff --git a/modules/bmp/image_loader_bmp.cpp b/modules/bmp/image_loader_bmp.cpp index 89947d1ef9..ac4e534983 100644 --- a/modules/bmp/image_loader_bmp.cpp +++ b/modules/bmp/image_loader_bmp.cpp @@ -37,8 +37,9 @@ Error ImageLoaderBMP::convert_to_image(Ref<Image> p_image, const bmp_header_s &p_header) { Error err = OK; - if (p_buffer == nullptr) + if (p_buffer == nullptr) { err = FAILED; + } if (err == OK) { size_t index = 0; diff --git a/modules/bullet/area_bullet.cpp b/modules/bullet/area_bullet.cpp index d5b03015a9..79d8e252f0 100644 --- a/modules/bullet/area_bullet.cpp +++ b/modules/bullet/area_bullet.cpp @@ -52,19 +52,22 @@ AreaBullet::AreaBullet() : /// In order to use collision objects as trigger, you have to disable the collision response. set_collision_enabled(false); - for (int i = 0; i < 5; ++i) + for (int i = 0; i < 5; ++i) { call_event_res_ptr[i] = &call_event_res[i]; + } } AreaBullet::~AreaBullet() { // signal are handled by godot, so just clear without notify - for (int i = overlappingObjects.size() - 1; 0 <= i; --i) + for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { overlappingObjects[i].object->on_exit_area(this); + } } void AreaBullet::dispatch_callbacks() { - if (!isScratched) + if (!isScratched) { return; + } isScratched = false; // Reverse order because I've to remove EXIT objects @@ -109,15 +112,17 @@ void AreaBullet::call_event(CollisionObjectBullet *p_otherObject, PhysicsServer3 } void AreaBullet::scratch() { - if (isScratched) + if (isScratched) { return; + } isScratched = true; } void AreaBullet::clear_overlaps(bool p_notify) { for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { - if (p_notify) + if (p_notify) { call_event(overlappingObjects[i].object, PhysicsServer3D::AREA_BODY_REMOVED); + } overlappingObjects[i].object->on_exit_area(this); } overlappingObjects.clear(); @@ -126,8 +131,9 @@ void AreaBullet::clear_overlaps(bool p_notify) { void AreaBullet::remove_overlap(CollisionObjectBullet *p_object, bool p_notify) { for (int i = overlappingObjects.size() - 1; 0 <= i; --i) { if (overlappingObjects[i].object == p_object) { - if (p_notify) + if (p_notify) { call_event(overlappingObjects[i].object, PhysicsServer3D::AREA_BODY_REMOVED); + } overlappingObjects[i].object->on_exit_area(this); overlappingObjects.remove(i); break; diff --git a/modules/bullet/btRayShape.cpp b/modules/bullet/btRayShape.cpp index ee84354315..a754ca6a89 100644 --- a/modules/bullet/btRayShape.cpp +++ b/modules/bullet/btRayShape.cpp @@ -68,10 +68,11 @@ btVector3 btRayShape::localGetSupportingVertex(const btVector3 &vec) const { } btVector3 btRayShape::localGetSupportingVertexWithoutMargin(const btVector3 &vec) const { - if (vec.z() > 0) + if (vec.z() > 0) { return m_shapeAxis * m_cacheScaledLength; - else + } else { return btVector3(0, 0, 0); + } } void btRayShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3 *vectors, btVector3 *supportVerticesOut, int numVectors) const { diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index c20fade011..55686543f3 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -326,8 +326,9 @@ void BulletPhysicsServer3D::area_clear_shapes(RID p_area) { AreaBullet *area = area_owner.getornull(p_area); ERR_FAIL_COND(!area); - for (int i = area->get_shape_count(); 0 < i; --i) + for (int i = area->get_shape_count(); 0 < i; --i) { area->remove_shape_full(0); + } } void BulletPhysicsServer3D::area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) { @@ -443,8 +444,9 @@ RID BulletPhysicsServer3D::body_create(BodyMode p_mode, bool p_init_sleeping) { body->set_mode(p_mode); body->set_collision_layer(1); body->set_collision_mask(1); - if (p_init_sleeping) + if (p_init_sleeping) { body->set_state(BODY_STATE_SLEEPING, p_init_sleeping); + } CreateThenReturnRID(rigid_body_owner, body); } @@ -458,8 +460,9 @@ void BulletPhysicsServer3D::body_set_space(RID p_body, RID p_space) { ERR_FAIL_COND(!space); } - if (body->get_space() == space) + if (body->get_space() == space) { return; //pointles + } body->set_space(space); } @@ -469,8 +472,9 @@ RID BulletPhysicsServer3D::body_get_space(RID p_body) const { ERR_FAIL_COND_V(!body, RID()); SpaceBullet *space = body->get_space(); - if (!space) + if (!space) { return RID(); + } return space->get_self(); } @@ -870,8 +874,9 @@ RID BulletPhysicsServer3D::soft_body_create(bool p_init_sleeping) { SoftBodyBullet *body = bulletnew(SoftBodyBullet); body->set_collision_layer(1); body->set_collision_mask(1); - if (p_init_sleeping) + if (p_init_sleeping) { body->set_activation_state(false); + } CreateThenReturnRID(soft_body_owner, body); } @@ -892,8 +897,9 @@ void BulletPhysicsServer3D::soft_body_set_space(RID p_body, RID p_space) { ERR_FAIL_COND(!space); } - if (body->get_space() == space) + if (body->get_space() == space) { return; //pointles + } body->set_space(space); } @@ -903,8 +909,9 @@ RID BulletPhysicsServer3D::soft_body_get_space(RID p_body) const { ERR_FAIL_COND_V(!body, RID()); SpaceBullet *space = body->get_space(); - if (!space) + if (!space) { return RID(); + } return space->get_self(); } @@ -1535,8 +1542,9 @@ void BulletPhysicsServer3D::init() { } void BulletPhysicsServer3D::step(float p_deltaTime) { - if (!active) + if (!active) { return; + } BulletPhysicsDirectBodyState3D::singleton_setDeltaTime(p_deltaTime); diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp index 0d456a155a..a3158a15e5 100644 --- a/modules/bullet/collision_object_bullet.cpp +++ b/modules/bullet/collision_object_bullet.cpp @@ -80,10 +80,11 @@ btTransform CollisionObjectBullet::ShapeWrapper::get_adjusted_transform() const void CollisionObjectBullet::ShapeWrapper::claim_bt_shape(const btVector3 &body_scale) { if (!bt_shape) { - if (active) + if (active) { bt_shape = shape->create_bt_shape(scale * body_scale); - else + } else { bt_shape = ShapeBullet::create_shape_empty(); + } } } @@ -136,18 +137,21 @@ void CollisionObjectBullet::setupBulletCollisionObject(btCollisionObject *p_coll void CollisionObjectBullet::add_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject) { exceptions.insert(p_ignoreCollisionObject->get_self()); - if (!bt_collision_object) + if (!bt_collision_object) { return; + } bt_collision_object->setIgnoreCollisionCheck(p_ignoreCollisionObject->bt_collision_object, true); - if (space) + if (space) { space->get_broadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bt_collision_object->getBroadphaseHandle(), space->get_dispatcher()); + } } void CollisionObjectBullet::remove_collision_exception(const CollisionObjectBullet *p_ignoreCollisionObject) { exceptions.erase(p_ignoreCollisionObject->get_self()); bt_collision_object->setIgnoreCollisionCheck(p_ignoreCollisionObject->bt_collision_object, false); - if (space) + if (space) { space->get_broadphase()->getOverlappingPairCache()->cleanProxyFromPairs(bt_collision_object->getBroadphaseHandle(), space->get_dispatcher()); + } } bool CollisionObjectBullet::has_collision_exception(const CollisionObjectBullet *p_otherCollisionObject) const { @@ -249,8 +253,9 @@ btCollisionShape *RigidCollisionObjectBullet::get_bt_shape(int p_index) const { int RigidCollisionObjectBullet::find_shape(ShapeBullet *p_shape) const { const int size = shapes.size(); for (int i = 0; i < size; ++i) { - if (shapes[i].shape == p_shape) + if (shapes[i].shape == p_shape) { return i; + } } return -1; } @@ -280,8 +285,9 @@ void RigidCollisionObjectBullet::remove_all_shapes(bool p_permanentlyFromThisBod internal_shape_destroy(i, p_permanentlyFromThisBody); } shapes.clear(); - if (!p_force_not_reload) + if (!p_force_not_reload) { reload_shapes(); + } } void RigidCollisionObjectBullet::set_shape_transform(int p_index, const Transform &p_transform) { @@ -302,8 +308,9 @@ Transform RigidCollisionObjectBullet::get_shape_transform(int p_index) const { } void RigidCollisionObjectBullet::set_shape_disabled(int p_index, bool p_disabled) { - if (shapes[p_index].active != p_disabled) + if (shapes[p_index].active != p_disabled) { return; + } shapes.write[p_index].active = !p_disabled; shape_changed(p_index); } diff --git a/modules/bullet/godot_ray_world_algorithm.cpp b/modules/bullet/godot_ray_world_algorithm.cpp index fbb336ca56..a84f3511ba 100644 --- a/modules/bullet/godot_ray_world_algorithm.cpp +++ b/modules/bullet/godot_ray_world_algorithm.cpp @@ -98,12 +98,13 @@ void GodotRayWorldAlgorithm::processCollision(const btCollisionObjectWrapper *bo if (btResult.hasHit()) { btScalar depth(ray_shape->getScaledLength() * (btResult.m_closestHitFraction - 1)); - if (depth > -RAY_PENETRATION_DEPTH_EPSILON) + if (depth > -RAY_PENETRATION_DEPTH_EPSILON) { depth = 0.0; + } - if (ray_shape->getSlipsOnSlope()) + if (ray_shape->getSlipsOnSlope()) { resultOut->addContactPoint(btResult.m_hitNormalWorld, btResult.m_hitPointWorld, depth); - else { + } else { resultOut->addContactPoint((ray_transform.getOrigin() - to.getOrigin()).normalize(), btResult.m_hitPointWorld, depth); } } diff --git a/modules/bullet/godot_ray_world_algorithm.h b/modules/bullet/godot_ray_world_algorithm.h index 45344186f5..9786732d40 100644 --- a/modules/bullet/godot_ray_world_algorithm.h +++ b/modules/bullet/godot_ray_world_algorithm.h @@ -56,8 +56,9 @@ public: virtual void getAllContactManifolds(btManifoldArray &manifoldArray) { ///should we use m_ownManifold to avoid adding duplicates? - if (m_manifoldPtr && m_ownManifold) + if (m_manifoldPtr && m_ownManifold) { manifoldArray.push_back(m_manifoldPtr); + } } struct CreateFunc : public btCollisionAlgorithmCreateFunc { const btDiscreteDynamicsWorld *m_world; diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index b9c2a00b34..f82648d6ff 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -62,11 +62,13 @@ bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) co CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_pickRay && !gObj->is_ray_pickable()) { @@ -84,8 +86,9 @@ bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) co } bool GodotAllConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - if (count >= m_resultMax) + if (count >= m_resultMax) { return false; + } const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); if (needs) { @@ -102,8 +105,9 @@ bool GodotAllConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) con } btScalar GodotAllConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) { - if (count >= m_resultMax) + if (count >= m_resultMax) { return 1; // not used by bullet + } CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(convexResult.m_hitCollisionObject->getUserPointer()); @@ -127,14 +131,17 @@ bool GodotKinClosestConvexResultCallback::needsCollision(btBroadphaseProxy *prox 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()) + if (m_infinite_inertia && !btObj->isStaticOrKinematicObject()) { return false; + } - if (gObj->getType() == CollisionObjectBullet::TYPE_AREA) + if (gObj->getType() == CollisionObjectBullet::TYPE_AREA) { return false; + } - if (m_self_object->has_collision_exception(gObj) || gObj->has_collision_exception(m_self_object)) + if (m_self_object->has_collision_exception(gObj) || gObj->has_collision_exception(m_self_object)) { return false; + } } return true; } else { @@ -149,11 +156,13 @@ bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_exclude->has(gObj->get_self())) { @@ -166,16 +175,18 @@ bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) } btScalar GodotClosestConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) { - if (convexResult.m_localShapeInfo) + if (convexResult.m_localShapeInfo) { m_shapeId = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID - else + } else { m_shapeId = 0; + } return btCollisionWorld::ClosestConvexResultCallback::addSingleResult(convexResult, normalInWorldSpace); } bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - if (m_count >= m_resultMax) + if (m_count >= m_resultMax) { return false; + } const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); if (needs) { @@ -183,11 +194,13 @@ bool GodotAllContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) co CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_exclude->has(gObj->get_self())) { @@ -200,8 +213,9 @@ 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) + if (m_count >= m_resultMax) { return cp.getDistance(); + } if (cp.getDistance() <= 0) { PhysicsDirectSpaceState3D::ShapeResult &result = m_results[m_count]; @@ -226,8 +240,9 @@ btScalar GodotAllContactResultCallback::addSingleResult(btManifoldPoint &cp, con } bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { - if (m_count >= m_resultMax) + if (m_count >= m_resultMax) { return false; + } const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); if (needs) { @@ -235,11 +250,13 @@ bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *pr CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_exclude->has(gObj->get_self())) { @@ -252,8 +269,9 @@ bool GodotContactPairContactResultCallback::needsCollision(btBroadphaseProxy *pr } btScalar GodotContactPairContactResultCallback::addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1) { - if (m_count >= m_resultMax) + if (m_count >= m_resultMax) { return 1; // not used by bullet + } if (m_self_object == colObj0Wrap->getCollisionObject()) { B_TO_G(cp.m_localPointA, m_results[m_count * 2 + 0]); // Local contact @@ -275,11 +293,13 @@ bool GodotRestInfoContactResultCallback::needsCollision(btBroadphaseProxy *proxy CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); if (CollisionObjectBullet::TYPE_AREA == gObj->getType()) { - if (!collide_with_areas) + if (!collide_with_areas) { return false; + } } else { - if (!collide_with_bodies) + if (!collide_with_bodies) { return false; + } } if (m_exclude->has(gObj->get_self())) { diff --git a/modules/bullet/godot_result_callbacks.h b/modules/bullet/godot_result_callbacks.h index 8636ca8eb6..1325542973 100644 --- a/modules/bullet/godot_result_callbacks.h +++ b/modules/bullet/godot_result_callbacks.h @@ -72,10 +72,11 @@ public: virtual bool needsCollision(btBroadphaseProxy *proxy0) const; virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult &rayResult, bool normalInWorldSpace) { - if (rayResult.m_localShapeInfo) + if (rayResult.m_localShapeInfo) { m_shapeId = rayResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID - else + } else { m_shapeId = 0; + } return btCollisionWorld::ClosestRayResultCallback::addSingleResult(rayResult, normalInWorldSpace); } }; diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index f263893287..2fca7fe633 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -283,8 +283,9 @@ RigidBodyBullet::RigidBodyBullet() : RigidBodyBullet::~RigidBodyBullet() { bulletdelete(godotMotionState); - if (force_integration_callback) + if (force_integration_callback) { memdelete(force_integration_callback); + } destroy_kinematic_utilities(); } @@ -309,8 +310,9 @@ void RigidBodyBullet::main_shape_changed() { void RigidBodyBullet::reload_body() { if (space) { space->remove_rigid_body(this); - if (get_main_shape()) + if (get_main_shape()) { space->add_rigid_body(this); + } } } @@ -336,8 +338,9 @@ 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) + if (omit_forces_integration) { btBody->clearForces(); + } BulletPhysicsDirectBodyState3D *bodyDirect = BulletPhysicsDirectBodyState3D::get_singleton(this); @@ -431,8 +434,9 @@ bool RigidBodyBullet::add_collision_object(RigidBodyBullet *p_otherObject, const bool RigidBodyBullet::was_colliding(RigidBodyBullet *p_other_object) { for (int i = prev_collision_count - 1; 0 <= i; --i) { - if ((*prev_collision_traces)[i] == p_other_object) + if ((*prev_collision_traces)[i] == p_other_object) { return true; + } } return false; } @@ -607,8 +611,9 @@ Variant RigidBodyBullet::get_state(PhysicsServer3D::BodyState p_state) const { void RigidBodyBullet::apply_central_impulse(const Vector3 &p_impulse) { btVector3 btImpu; G_TO_B(p_impulse, btImpu); - if (Vector3() != p_impulse) + if (Vector3() != p_impulse) { btBody->activate(); + } btBody->applyCentralImpulse(btImpu); } @@ -617,16 +622,18 @@ void RigidBodyBullet::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impul btVector3 btPos; G_TO_B(p_impulse, btImpu); G_TO_B(p_pos, btPos); - if (Vector3() != p_impulse) + if (Vector3() != p_impulse) { btBody->activate(); + } btBody->applyImpulse(btImpu, btPos); } void RigidBodyBullet::apply_torque_impulse(const Vector3 &p_impulse) { btVector3 btImp; G_TO_B(p_impulse, btImp); - if (Vector3() != p_impulse) + if (Vector3() != p_impulse) { btBody->activate(); + } btBody->applyTorqueImpulse(btImp); } @@ -635,32 +642,36 @@ void RigidBodyBullet::apply_force(const Vector3 &p_force, const Vector3 &p_pos) btVector3 btPos; G_TO_B(p_force, btForce); G_TO_B(p_pos, btPos); - if (Vector3() != p_force) + if (Vector3() != p_force) { btBody->activate(); + } btBody->applyForce(btForce, btPos); } void RigidBodyBullet::apply_central_force(const Vector3 &p_force) { btVector3 btForce; G_TO_B(p_force, btForce); - if (Vector3() != p_force) + if (Vector3() != p_force) { btBody->activate(); + } btBody->applyCentralForce(btForce); } void RigidBodyBullet::apply_torque(const Vector3 &p_torque) { btVector3 btTorq; G_TO_B(p_torque, btTorq); - if (Vector3() != p_torque) + if (Vector3() != p_torque) { btBody->activate(); + } btBody->applyTorque(btTorq); } void RigidBodyBullet::set_applied_force(const Vector3 &p_force) { btVector3 btVec = btBody->getTotalTorque(); - if (Vector3() != p_force) + if (Vector3() != p_force) { btBody->activate(); + } btBody->clearForces(); btBody->applyTorque(btVec); @@ -678,8 +689,9 @@ Vector3 RigidBodyBullet::get_applied_force() const { void RigidBodyBullet::set_applied_torque(const Vector3 &p_torque) { btVector3 btVec = btBody->getTotalForce(); - if (Vector3() != p_torque) + if (Vector3() != p_torque) { btBody->activate(); + } btBody->clearForces(); btBody->applyCentralForce(btVec); @@ -747,8 +759,9 @@ bool RigidBodyBullet::is_continuous_collision_detection_enabled() const { void RigidBodyBullet::set_linear_velocity(const Vector3 &p_velocity) { btVector3 btVec; G_TO_B(p_velocity, btVec); - if (Vector3() != p_velocity) + if (Vector3() != p_velocity) { btBody->activate(); + } btBody->setLinearVelocity(btVec); } @@ -761,8 +774,9 @@ Vector3 RigidBodyBullet::get_linear_velocity() const { void RigidBodyBullet::set_angular_velocity(const Vector3 &p_velocity) { btVector3 btVec; G_TO_B(p_velocity, btVec); - if (Vector3() != p_velocity) + if (Vector3() != p_velocity) { btBody->activate(); + } btBody->setAngularVelocity(btVec); } @@ -774,8 +788,9 @@ Vector3 RigidBodyBullet::get_angular_velocity() const { void RigidBodyBullet::set_transform__bullet(const btTransform &p_global_transform) { if (mode == PhysicsServer3D::BODY_MODE_KINEMATIC) { - if (space && space->get_delta_time() != 0) + if (space && space->get_delta_time() != 0) { btBody->setLinearVelocity((p_global_transform.getOrigin() - btBody->getWorldTransform().getOrigin()) / space->get_delta_time()); + } // The kinematic use MotionState class godotMotionState->moveBody(p_global_transform); } else { @@ -804,8 +819,9 @@ void RigidBodyBullet::reload_shapes() { // shapes incorrectly do not set the vector in calculateLocalIntertia. // Arbitrary zero is preferable to undefined behaviour. btVector3 inertia(0, 0, 0); - if (EMPTY_SHAPE_PROXYTYPE != mainShape->getShapeType()) // Necessary to avoid assertion of the empty shape + if (EMPTY_SHAPE_PROXYTYPE != mainShape->getShapeType()) { // Necessary to avoid assertion of the empty shape mainShape->calculateLocalInertia(mass, inertia); + } btBody->setMassProps(mass, inertia); } btBody->updateInertiaTensor(); @@ -879,8 +895,9 @@ void RigidBodyBullet::on_exit_area(AreaBullet *p_area) { void RigidBodyBullet::reload_space_override_modificator() { // Make sure that kinematic bodies have their total gravity calculated - if (!is_active() && PhysicsServer3D::BODY_MODE_KINEMATIC != mode) + if (!is_active() && PhysicsServer3D::BODY_MODE_KINEMATIC != mode) { return; + } Vector3 newGravity(0.0, 0.0, 0.0); real_t newLinearDamp = MAX(0.0, linearDamp); @@ -1001,12 +1018,14 @@ 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) + if (PhysicsServer3D::BODY_MODE_RIGID != mode && PhysicsServer3D::BODY_MODE_CHARACTER != mode) { return; + } m_isStatic = false; - if (mainShape) + if (mainShape) { mainShape->calculateLocalInertia(p_mass, localInertia); + } if (PhysicsServer3D::BODY_MODE_RIGID == mode) { btBody->setCollisionFlags(clearedCurrentFlags); // Just set the flags without Kin and Static @@ -1020,8 +1039,9 @@ 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) + if (PhysicsServer3D::BODY_MODE_STATIC != mode && PhysicsServer3D::BODY_MODE_KINEMATIC != mode) { return; + } m_isStatic = true; if (PhysicsServer3D::BODY_MODE_STATIC == mode) { diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp index 424daf7726..d53f1e7d17 100644 --- a/modules/bullet/shape_bullet.cpp +++ b/modules/bullet/shape_bullet.cpp @@ -80,8 +80,9 @@ void ShapeBullet::add_owner(ShapeOwnerBullet *p_owner) { void ShapeBullet::remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody) { Map<ShapeOwnerBullet *, int>::Element *E = owners.find(p_owner); - if (!E) + if (!E) { return; + } E->get()--; if (p_permanentlyFromThisBody || 0 >= E->get()) { owners.erase(E); @@ -150,8 +151,9 @@ btHeightfieldTerrainShape *ShapeBullet::create_shape_height_field(Vector<real_t> btHeightfieldTerrainShape *heightfield = bulletnew(btHeightfieldTerrainShape(p_width, p_depth, heightsPtr, ignoredHeightScale, p_min_height, p_max_height, YAxis, PHY_FLOAT, flipQuadEdges)); // The shape can be created without params when you do PhysicsServer3D.shape_create(PhysicsServer3D.SHAPE_HEIGHTMAP) - if (heightsPtr) + if (heightsPtr) { heightfield->buildAccelerator(16); + } return heightfield; } @@ -348,9 +350,10 @@ void ConvexPolygonShapeBullet::setup(const Vector<Vector3> &p_vertices) { } btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { - if (!vertices.size()) + if (!vertices.size()) { // This is necessary since 0 vertices return prepare(ShapeBullet::create_shape_empty()); + } btCollisionShape *cs(ShapeBullet::create_shape_convex(vertices)); cs->setLocalScaling(p_implicit_scale); prepare(cs); @@ -430,9 +433,10 @@ void ConcavePolygonShapeBullet::setup(Vector<Vector3> p_faces) { btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btCollisionShape *cs = ShapeBullet::create_shape_concave(meshShape); - if (!cs) + if (!cs) { // This is necessary since if 0 faces the creation of concave return null cs = ShapeBullet::create_shape_empty(); + } cs->setLocalScaling(p_implicit_scale); prepare(cs); cs->setMargin(0); @@ -455,10 +459,12 @@ void HeightMapShapeBullet::set_data(const Variant &p_data) { real_t l_max_height = 0.0; // If specified, min and max height will be used as precomputed values - if (d.has("min_height")) + if (d.has("min_height")) { l_min_height = d["min_height"]; - if (d.has("max_height")) + } + if (d.has("max_height")) { l_max_height = d["max_height"]; + } ERR_FAIL_COND(l_min_height > l_max_height); diff --git a/modules/bullet/soft_body_bullet.cpp b/modules/bullet/soft_body_bullet.cpp index 3047a3eed1..6794d6c313 100644 --- a/modules/bullet/soft_body_bullet.cpp +++ b/modules/bullet/soft_body_bullet.cpp @@ -66,8 +66,9 @@ void SoftBodyBullet::on_enter_area(AreaBullet *p_area) {} void SoftBodyBullet::on_exit_area(AreaBullet *p_area) {} void SoftBodyBullet::update_rendering_server(SoftBodyRenderingServerHandler *p_rendering_server_handler) { - if (!bt_soft_body) + if (!bt_soft_body) { return; + } /// Update visual server vertices const btSoftBody::tNodeArray &nodes(bt_soft_body->m_nodes); @@ -105,10 +106,11 @@ void SoftBodyBullet::update_rendering_server(SoftBodyRenderingServerHandler *p_r } void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) { - if (p_mesh.is_null()) + if (p_mesh.is_null()) { soft_mesh.unref(); - else + } else { soft_mesh = p_mesh; + } if (soft_mesh.is_null()) { destroy_soft_body(); @@ -121,8 +123,9 @@ void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) { } void SoftBodyBullet::destroy_soft_body() { - if (!bt_soft_body) + if (!bt_soft_body) { return; + } if (space) { /// Remove from world before deletion @@ -139,8 +142,9 @@ void SoftBodyBullet::set_soft_transform(const Transform &p_transform) { } void SoftBodyBullet::move_all_nodes(const Transform &p_transform) { - if (!bt_soft_body) + if (!bt_soft_body) { return; + } btTransform bt_transf; G_TO_B(p_transform, bt_transf); bt_soft_body->transform(bt_transf); @@ -166,8 +170,9 @@ void SoftBodyBullet::get_node_position(int p_node_index, Vector3 &r_position) co } void SoftBodyBullet::get_node_offset(int p_node_index, Vector3 &r_offset) const { - if (soft_mesh.is_null()) + if (soft_mesh.is_null()) { return; + } Array arrays = soft_mesh->surface_get_arrays(0); Vector<Vector3> vertices(arrays[RS::ARRAY_VERTEX]); @@ -212,8 +217,9 @@ void SoftBodyBullet::reset_all_node_mass() { } void SoftBodyBullet::reset_all_node_positions() { - if (soft_mesh.is_null()) + if (soft_mesh.is_null()) { return; + } Array arrays = soft_mesh->surface_get_arrays(0); Vector<Vector3> vs_vertices(arrays[RS::ARRAY_VERTEX]); @@ -382,8 +388,9 @@ void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector } void SoftBodyBullet::setup_soft_body() { - if (!bt_soft_body) + if (!bt_soft_body) { return; + } // Soft body setup setupBulletCollisionObject(bt_soft_body); diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index 433f1109c9..99f58e7059 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -63,8 +63,9 @@ 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) + if (p_result_max <= 0) { return 0; + } btVector3 bt_point; G_TO_B(p_point, bt_point); @@ -117,8 +118,9 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V } int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, 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) + if (p_result_max <= 0) { return 0; + } ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); @@ -202,8 +204,9 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf /// Returns the list of contacts pairs in this order: Local contact, other body contact bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, 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) + if (p_result_max <= 0) { return false; + } ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); @@ -650,8 +653,9 @@ void SpaceBullet::check_ghost_overlaps() { btVector3 area_scale(area->get_bt_body_scale()); - if (!area->is_monitoring()) + if (!area->is_monitoring()) { continue; + } /// 1. Reset all states for (i = area->overlappingObjects.size() - 1; 0 <= i; --i) { @@ -680,15 +684,18 @@ void SpaceBullet::check_ghost_overlaps() { } if (overlapped_bt_co->getUserIndex() == CollisionObjectBullet::TYPE_AREA) { - if (!static_cast<AreaBullet *>(overlapped_bt_co->getUserPointer())->is_monitorable()) + if (!static_cast<AreaBullet *>(overlapped_bt_co->getUserPointer())->is_monitorable()) { continue; - } else if (overlapped_bt_co->getUserIndex() != CollisionObjectBullet::TYPE_RIGID_BODY) + } + } else if (overlapped_bt_co->getUserIndex() != CollisionObjectBullet::TYPE_RIGID_BODY) { continue; + } // For each area shape for (y = area->get_shape_count() - 1; 0 <= y; --y) { - if (!area->get_bt_shape(y)->isConvex()) + if (!area->get_bt_shape(y)->isConvex()) { continue; + } btTransform area_shape_treansform(area->get_bt_shape_transform(y)); area_shape_treansform.getOrigin() *= area_scale; @@ -730,8 +737,9 @@ void SpaceBullet::check_ghost_overlaps() { btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, nullptr, BT_CONTACT_POINT_ALGORITHMS); - if (!algorithm) + if (!algorithm) { continue; + } GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB); algorithm->processCollision(&obA, &obB, dynamicsWorld->getDispatchInfo(), &contactPointResult); @@ -749,8 +757,9 @@ void SpaceBullet::check_ghost_overlaps() { } // ~For each area shape collision_found: - if (!hasOverlap) + if (!hasOverlap) { continue; + } indexOverlap = area->find_overlapping_object(otherObject); if (-1 == indexOverlap) { @@ -1195,8 +1204,9 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran if (p_infinite_inertia && !otherObject->isStaticOrKinematicObject()) { otherObject->activate(); // Force activation of hitten rigid, soft body continue; - } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) + } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) { continue; + } if (otherObject->getCollisionShape()->isCompound()) { const btCompoundShape *cs = static_cast<const btCompoundShape *>(otherObject->getCollisionShape()); @@ -1384,8 +1394,9 @@ int SpaceBullet::recover_from_penetration_ray(RigidBodyBullet *p_body, const btT if (p_infinite_inertia && !otherObject->isStaticOrKinematicObject()) { otherObject->activate(); // Force activation of hitten rigid, soft body continue; - } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) + } else if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) { continue; + } if (otherObject->getCollisionShape()->isCompound()) { const btCompoundShape *cs = static_cast<const btCompoundShape *>(otherObject->getCollisionShape()); diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h index 2dad965de8..5ff421ef52 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -169,8 +169,9 @@ public: contactDebugCount = 0; } _FORCE_INLINE_ void add_debug_contact(const Vector3 &p_contact) { - if (contactDebugCount < contactDebug.size()) + if (contactDebugCount < contactDebug.size()) { contactDebug.write[contactDebugCount++] = p_contact; + } } _FORCE_INLINE_ Vector<Vector3> get_debug_contacts() { return contactDebug; } _FORCE_INLINE_ int get_debug_contact_count() { return contactDebugCount; } diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index ccd1b89fb5..df798623f9 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -42,8 +42,9 @@ inline static bool is_snapable(const Vector3 &p_point1, const Vector3 &p_point2, inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2], const Vector2 p_uvs[2], const Vector2 &p_interpolation_point) { float segment_length = (p_segement_points[1] - p_segement_points[0]).length(); - if (segment_length < CMP_EPSILON) + if (segment_length < CMP_EPSILON) { return p_uvs[0]; + } float distance = (p_interpolation_point - p_segement_points[0]).length(); float fraction = distance / segment_length; @@ -52,12 +53,15 @@ inline static Vector2 interpolate_segment_uv(const Vector2 p_segement_points[2], } inline static Vector2 interpolate_triangle_uv(const Vector2 p_vertices[3], const Vector2 p_uvs[3], const Vector2 &p_interpolation_point) { - if (p_interpolation_point.distance_squared_to(p_vertices[0]) < CMP_EPSILON2) + if (p_interpolation_point.distance_squared_to(p_vertices[0]) < CMP_EPSILON2) { return p_uvs[0]; - if (p_interpolation_point.distance_squared_to(p_vertices[1]) < CMP_EPSILON2) + } + if (p_interpolation_point.distance_squared_to(p_vertices[1]) < CMP_EPSILON2) { return p_uvs[1]; - if (p_interpolation_point.distance_squared_to(p_vertices[2]) < CMP_EPSILON2) + } + if (p_interpolation_point.distance_squared_to(p_vertices[2]) < CMP_EPSILON2) { return p_uvs[2]; + } Vector2 edge1 = p_vertices[1] - p_vertices[0]; Vector2 edge2 = p_vertices[2] - p_vertices[0]; @@ -69,8 +73,9 @@ inline static Vector2 interpolate_triangle_uv(const Vector2 p_vertices[3], const float inter_on_edge1 = interpolation.dot(edge1); float inter_on_edge2 = interpolation.dot(edge2); float scale = (edge1_on_edge1 * edge2_on_edge2 - edge1_on_edge2 * edge1_on_edge2); - if (scale == 0) + if (scale == 0) { return p_uvs[0]; + } float v = (edge2_on_edge2 * inter_on_edge1 - edge1_on_edge2 * inter_on_edge2) / scale; float w = (edge1_on_edge1 * inter_on_edge2 - edge1_on_edge2 * inter_on_edge1) / scale; @@ -85,19 +90,22 @@ static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3 Vector3 h = p_dir.cross(edge2); real_t a = edge1.dot(h); // Check if ray is parallel to triangle. - if (Math::is_zero_approx(a)) + if (Math::is_zero_approx(a)) { return false; + } real_t f = 1.0 / a; Vector3 s = p_from - p_vertices[0]; real_t u = f * s.dot(h); - if (u < 0.0 - p_tolerance || u > 1.0 + p_tolerance) + if (u < 0.0 - p_tolerance || u > 1.0 + p_tolerance) { return false; + } Vector3 q = s.cross(edge1); real_t v = f * p_dir.dot(q); - if (v < 0.0 - p_tolerance || u + v > 1.0 + p_tolerance) + if (v < 0.0 - p_tolerance || u + v > 1.0 + p_tolerance) { return false; + } // Ray intersects triangle. // Calculate distance. @@ -106,8 +114,9 @@ static inline bool ray_intersects_triangle(const Vector3 &p_from, const Vector3 if (t >= p_tolerance) { r_intersection_point = p_from + p_dir * t; return true; - } else + } else { return false; + } } inline bool is_point_in_triangle(const Vector3 &p_point, const Vector3 p_vertices[3], int p_shifted = 0) { @@ -133,12 +142,14 @@ inline bool is_point_in_triangle(const Vector3 &p_point, const Vector3 p_vertice lambda[2] = p_vertices[0].cross(p_vertices[1]).dot(p_point) / det; // Point is in the plane if all lambdas sum to 1. - if (!Math::is_equal_approx(lambda[0] + lambda[1] + lambda[2], 1)) + if (!Math::is_equal_approx(lambda[0] + lambda[1] + lambda[2], 1)) { return false; + } // Point is inside the triangle if all lambdas are positive. - if (lambda[0] < 0 || lambda[1] < 0 || lambda[2] < 0) + if (lambda[0] < 0 || lambda[1] < 0 || lambda[2] < 0) { return false; + } return true; } @@ -150,8 +161,9 @@ inline static bool are_segements_parallel(const Vector2 p_segment1_points[2], co real_t segment2_length2 = segment2.dot(segment2); real_t segment_onto_segment = segment2.dot(segment1); - if (segment1_length2 < p_vertex_snap2 || segment2_length2 < p_vertex_snap2) + if (segment1_length2 < p_vertex_snap2 || segment2_length2 < p_vertex_snap2) { return true; + } real_t max_separation2; if (segment1_length2 > segment2_length2) { @@ -207,15 +219,17 @@ void CSGBrush::build_from_faces(const Vector<Vector3> &p_vertices, const Vector< f.uvs[2] = ruv[i * 3 + 2]; } - if (sc == vc / 3) + if (sc == vc / 3) { f.smooth = rs[i]; - else + } else { f.smooth = false; + } - if (ic == vc / 3) + if (ic == vc / 3) { f.invert = ri[i]; - else + } else { f.invert = false; + } if (mc == vc / 3) { Ref<Material> mat = rm[i]; @@ -322,8 +336,9 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b int outside_count = 0; for (int i = 0; i < mesh_merge.faces.size(); i++) { - if (mesh_merge.faces[i].inside) + if (mesh_merge.faces[i].inside) { continue; + } outside_count++; } @@ -332,8 +347,9 @@ 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) + if (mesh_merge.faces[i].inside) { continue; + } for (int j = 0; j < 3; j++) { r_merged_brush.faces.write[outside_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]]; @@ -354,8 +370,9 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b int inside_count = 0; for (int i = 0; i < mesh_merge.faces.size(); i++) { - if (!mesh_merge.faces[i].inside) + if (!mesh_merge.faces[i].inside) { continue; + } inside_count++; } @@ -364,8 +381,9 @@ 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) + if (!mesh_merge.faces[i].inside) { continue; + } for (int j = 0; j < 3; j++) { r_merged_brush.faces.write[inside_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]]; @@ -386,10 +404,12 @@ void CSGBrushOperation::merge_brushes(Operation p_operation, const CSGBrush &p_b int 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) + 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) + } + if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside) { continue; + } face_count++; } @@ -398,10 +418,12 @@ 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) + 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) + } + if (!mesh_merge.faces[i].from_b && mesh_merge.faces[i].inside) { continue; + } for (int j = 0; j < 3; j++) { r_merged_brush.faces.write[face_count].vertices[j] = mesh_merge.points[mesh_merge.faces[i].points[j]]; @@ -500,9 +522,11 @@ void CSGBrushOperation::MeshMerge::_add_distance(List<real_t> &r_intersectionsA, List<real_t> &intersections = p_from_B ? r_intersectionsB : r_intersectionsA; // Check if distance exists. - for (const List<real_t>::Element *E = intersections.front(); E; E = E->next()) - if (Math::abs(**E - p_distance) < vertex_snap) + for (const List<real_t>::Element *E = intersections.front(); E; E = E->next()) { + if (Math::abs(**E - p_distance) < vertex_snap) { return; + } + } intersections.push_back(p_distance); } @@ -560,8 +584,9 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de if ((current_normal - face_normal).length_squared() < CMP_EPSILON2 && is_point_in_triangle(face_center, current_points)) { // Only add an intersection if checking a B face. - if (face.from_b) + if (face.from_b) { _add_distance(intersectionsA, intersectionsB, current_face.from_b, 0); + } } else if (ray_intersects_triangle(face_center, face_normal, current_points, CMP_EPSILON, intersection_point)) { real_t distance = (intersection_point - face_center).length(); _add_distance(intersectionsA, intersectionsB, current_face.from_b, distance); @@ -607,14 +632,16 @@ bool CSGBrushOperation::MeshMerge::_bvh_inside(FaceBVH *facebvhptr, int p_max_de if (level == 0) { done = true; break; - } else + } else { level--; + } continue; } } - if (done) + if (done) { break; + } } // Inside if face normal intersects other faces an odd number of times. @@ -667,8 +694,9 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() { AABB intersection_aabb = aabb_a.intersection(aabb_b); // Check if shape AABBs intersect. - if (intersection_aabb.size == Vector3()) + if (intersection_aabb.size == Vector3()) { return; + } Vector<FaceBVH *> bvhtrvec; bvhtrvec.resize(faces.size()); @@ -683,11 +711,13 @@ void CSGBrushOperation::MeshMerge::mark_inside_faces() { for (int i = 0; i < faces.size(); i++) { // Check if face AABB intersects the intersection AABB. - if (!intersection_aabb.intersects_inclusive(facebvh[i].aabb)) + if (!intersection_aabb.intersects_inclusive(facebvh[i].aabb)) { continue; + } - if (_bvh_inside(facebvh, max_depth, max_alloc - 1, i)) + if (_bvh_inside(facebvh, max_depth, max_alloc - 1, i)) { faces.write[i].inside = true; + } } } @@ -710,8 +740,9 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vect } // Don't add degenerate faces. - if (indices[0] == indices[2] || indices[0] == indices[1] || indices[1] == indices[2]) + if (indices[0] == indices[2] || indices[0] == indices[1] || indices[1] == indices[2]) { return; + } MeshMerge::Face face; face.from_b = p_from_b; @@ -742,8 +773,9 @@ void CSGBrushOperation::MeshMerge::add_face(const Vector3 p_points[], const Vect int CSGBrushOperation::Build2DFaces::_get_point_idx(const Vector2 &p_point) { for (int vertex_idx = 0; vertex_idx < vertices.size(); ++vertex_idx) { - if ((p_point - vertices[vertex_idx].point).length_squared() < vertex_snap2) + if ((p_point - vertices[vertex_idx].point).length_squared() < vertex_snap2) { return vertex_idx; + } } return -1; } @@ -751,8 +783,9 @@ 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) + if (vertex_id != -1) { return vertex_id; + } vertices.push_back(p_vertex); return vertices.size() - 1; @@ -776,14 +809,16 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert // Sort along the axis with the greatest difference. int axis = 0; - if (Math::abs(new_point.x - first_point.x) < Math::abs(new_point.y - first_point.y)) + if (Math::abs(new_point.x - first_point.x) < Math::abs(new_point.y - first_point.y)) { axis = 1; + } // Add it to the beginning or the end appropriately. - if (new_point[axis] < first_point[axis]) + if (new_point[axis] < first_point[axis]) { r_vertex_indices.insert(0, p_new_vertex_index); - else + } else { r_vertex_indices.push_back(p_new_vertex_index); + } return; } @@ -795,8 +830,9 @@ void CSGBrushOperation::Build2DFaces::_add_vertex_idx_sorted(Vector<int> &r_vert // Determine axis being sorted against i.e. the axis with the greatest difference. int axis = 0; - if (Math::abs(last_point.x - first_point.x) < Math::abs(last_point.y - first_point.y)) + if (Math::abs(last_point.x - first_point.x) < Math::abs(last_point.y - first_point.y)) { axis = 1; + } // Insert the point at the appropriate index. for (int insert_idx = 0; insert_idx < r_vertex_indices.size(); ++insert_idx) { @@ -814,8 +850,9 @@ 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) + 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) { @@ -853,8 +890,9 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ // Skip flattened faces. if (outer_edge_idx[0] == p_segment_indices[closest_idx] || - outer_edge_idx[1] == p_segment_indices[closest_idx]) + outer_edge_idx[1] == p_segment_indices[closest_idx]) { continue; + } //Don't create degenerate triangles. Vector2 edge1[2] = { @@ -882,11 +920,13 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ // Delete the old faces in reverse index order. merge_faces_idx.sort(); merge_faces_idx.invert(); - for (int i = 0; i < merge_faces_idx.size(); ++i) + for (int i = 0; i < merge_faces_idx.size(); ++i) { faces.remove(merge_faces_idx[i]); + } - if (degenerate_points.size() == 0) + if (degenerate_points.size() == 0) { continue; + } // Split faces using degenerate points. for (int face_idx = 0; face_idx < faces.size(); ++face_idx) { @@ -914,8 +954,9 @@ void CSGBrushOperation::Build2DFaces::_merge_faces(const Vector<int> &p_segment_ break; } } - if (existing) + if (existing) { continue; + } // Check if point is on an each edge. for (int face_edge_idx = 0; face_edge_idx < 3; ++face_edge_idx) { @@ -998,12 +1039,14 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s 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) + (intersection_point - edge_points[1]).length_squared() < vertex_snap2) { continue; + } // Check if edge exists, by checking if the intersecting segment is parallel to the edge. - if (are_segements_parallel(p_segment_points, edge_points, vertex_snap2)) + if (are_segements_parallel(p_segment_points, edge_points, vertex_snap2)) { continue; + } // Add the intersection point as a new vertex. Vertex2D new_vertex; @@ -1032,8 +1075,9 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s // If opposite point is on the segemnt, add its index to segment indices too. Vector2 closest_point = Geometry::get_closest_point_to_segment_2d(vertices[opposite_vertex_idx].point, p_segment_points); - if ((closest_point - vertices[opposite_vertex_idx].point).length_squared() < vertex_snap2) + if ((closest_point - vertices[opposite_vertex_idx].point).length_squared() < vertex_snap2) { _add_vertex_idx_sorted(r_segment_indices, opposite_vertex_idx); + } // Create two new faces around the new edge and remove this face. // The new edge is the last edge. @@ -1080,8 +1124,9 @@ int CSGBrushOperation::Build2DFaces::_insert_point(const Vector2 &p_point) { // Check if point is existing face vertex. for (int i = 0; i < 3; ++i) { - if ((p_point - face_vertices[i].point).length_squared() < vertex_snap2) + if ((p_point - face_vertices[i].point).length_squared() < vertex_snap2) { return face.vertex_idx[i]; + } } // Check if point is on an each edge. @@ -1202,10 +1247,12 @@ void CSGBrushOperation::Build2DFaces::insert(const CSGBrush &p_brush, int p_face } else { Vector3 next_point_3D = p_brush.faces[p_face_idx].vertices[(i + 1) % 3]; - if (plane.has_point(next_point_3D)) + if (plane.has_point(next_point_3D)) { continue; // Next point is in plane, it will be added separately. - if (plane.is_point_over(point_3D) == plane.is_point_over(next_point_3D)) + } + if (plane.is_point_over(point_3D) == plane.is_point_over(next_point_3D)) { continue; // Both points on the same side of the plane, ignore. + } // Edge crosses the plane, find and add the intersection point. Vector3 point_2D; @@ -1330,8 +1377,9 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face p_collection.build2DFacesB[p_face_idx_b] = Build2DFaces(); has_degenerate = true; } - if (has_degenerate) + if (has_degenerate) { return; + } // Ensure B has points either side of or in the plane of A. int in_plane_count = 0, over_count = 0, under_count = 0; @@ -1339,16 +1387,18 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face ERR_FAIL_COND_MSG(plane_a.normal == Vector3(), "Couldn't form plane from Brush A face."); for (int i = 0; i < 3; i++) { - if (plane_a.has_point(vertices_b[i])) + if (plane_a.has_point(vertices_b[i])) { in_plane_count++; - else if (plane_a.is_point_over(vertices_b[i])) + } else if (plane_a.is_point_over(vertices_b[i])) { over_count++; - else + } else { under_count++; + } } // If all points under or over the plane, there is no intesection. - if (over_count == 3 || under_count == 3) + if (over_count == 3 || under_count == 3) { return; + } // Ensure A has points either side of or in the plane of B. in_plane_count = 0; @@ -1358,16 +1408,18 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face ERR_FAIL_COND_MSG(plane_b.normal == Vector3(), "Couldn't form plane from Brush B face."); for (int i = 0; i < 3; i++) { - if (plane_b.has_point(vertices_a[i])) + if (plane_b.has_point(vertices_a[i])) { in_plane_count++; - else if (plane_b.is_point_over(vertices_a[i])) + } else if (plane_b.is_point_over(vertices_a[i])) { over_count++; - else + } else { under_count++; + } } // If all points under or over the plane, there is no intesection. - if (over_count == 3 || under_count == 3) + if (over_count == 3 || under_count == 3) { return; + } // Check for intersection using the SAT theorem. { @@ -1379,8 +1431,9 @@ void CSGBrushOperation::update_faces(const CSGBrush &p_brush_a, const int p_face Vector3 axis_b = (vertices_b[j] - vertices_b[(j + 1) % 3]).normalized(); Vector3 sep_axis = axis_a.cross(axis_b); - if (sep_axis == Vector3()) + if (sep_axis == Vector3()) { continue; //colineal + } sep_axis.normalize(); real_t min_a = 1e20, max_a = -1e20; diff --git a/modules/csg/csg_gizmos.cpp b/modules/csg/csg_gizmos.cpp index c9569a6d9c..9fa7dc1340 100644 --- a/modules/csg/csg_gizmos.cpp +++ b/modules/csg/csg_gizmos.cpp @@ -126,8 +126,9 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } s->set_radius(d); } @@ -144,8 +145,9 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } switch (p_idx) { case 0: @@ -172,13 +174,15 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } - if (p_idx == 0) + if (p_idx == 0) { s->set_radius(d); - else if (p_idx == 1) + } else if (p_idx == 1) { s->set_height(d * 2.0); + } } if (Object::cast_to<CSGTorus3D>(cs)) { @@ -193,13 +197,15 @@ void CSGShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Ca d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap()); } - if (d < 0.001) + if (d < 0.001) { d = 0.001; + } - if (p_idx == 0) + if (p_idx == 0) { s->set_inner_radius(d); - else if (p_idx == 1) + } else if (p_idx == 1) { s->set_outer_radius(d); + } } } @@ -261,10 +267,11 @@ void CSGShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, if (Object::cast_to<CSGCylinder3D>(cs)) { CSGCylinder3D *s = Object::cast_to<CSGCylinder3D>(cs); if (p_cancel) { - if (p_idx == 0) + if (p_idx == 0) { s->set_radius(p_restore); - else + } else { s->set_height(p_restore); + } return; } @@ -285,10 +292,11 @@ void CSGShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, if (Object::cast_to<CSGTorus3D>(cs)) { CSGTorus3D *s = Object::cast_to<CSGTorus3D>(cs); if (p_cancel) { - if (p_idx == 0) + if (p_idx == 0) { s->set_inner_radius(p_restore); - else + } else { s->set_outer_radius(p_restore); + } return; } diff --git a/modules/csg/csg_shape.cpp b/modules/csg/csg_shape.cpp index a5ebb1f437..7df65b04c4 100644 --- a/modules/csg/csg_shape.cpp +++ b/modules/csg/csg_shape.cpp @@ -32,13 +32,15 @@ #include "scene/3d/path_3d.h" void CSGShape3D::set_use_collision(bool p_enable) { - if (use_collision == p_enable) + if (use_collision == p_enable) { return; + } use_collision = p_enable; - if (!is_inside_tree() || !is_root_shape()) + if (!is_inside_tree() || !is_root_shape()) { return; + } if (use_collision) { root_collision_shape.instance(); @@ -86,10 +88,11 @@ uint32_t CSGShape3D::get_collision_mask() const { void CSGShape3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -99,10 +102,11 @@ bool CSGShape3D::get_collision_mask_bit(int p_bit) const { void CSGShape3D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_layer(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_layer(mask); } @@ -123,8 +127,9 @@ float CSGShape3D::get_snap() const { } void CSGShape3D::_make_dirty() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } if (dirty) { return; @@ -151,14 +156,17 @@ CSGBrush *CSGShape3D::_get_brush() { for (int i = 0; i < get_child_count(); i++) { CSGShape3D *child = Object::cast_to<CSGShape3D>(get_child(i)); - if (!child) + if (!child) { continue; - if (!child->is_visible_in_tree()) + } + if (!child->is_visible_in_tree()) { continue; + } CSGBrush *n2 = child->_get_brush(); - if (!n2) + if (!n2) { continue; + } if (!n) { n = memnew(CSGBrush); @@ -192,10 +200,11 @@ CSGBrush *CSGShape3D::_get_brush() { AABB aabb; for (int i = 0; i < n->faces.size(); i++) { for (int j = 0; j < 3; j++) { - if (i == 0 && j == 0) + if (i == 0 && j == 0) { aabb.position = n->faces[i].vertices[j]; - else + } else { aabb.expand_to(n->faces[i].vertices[j]); + } } } node_aabb = aabb; @@ -266,8 +275,9 @@ void CSGShape3D::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const } void CSGShape3D::_update_shape() { - if (parent) + if (parent) { return; + } set_base(RID()); root_mesh.unref(); //byebye root mesh @@ -422,8 +432,9 @@ void CSGShape3D::_update_shape() { have_tangents = genTangSpaceDefault(&msc); } - if (surfaces[i].last_added == 0) + if (surfaces[i].last_added == 0) { continue; + } // and convert to surface array Array array; @@ -512,8 +523,9 @@ void CSGShape3D::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - if (parent) + if (parent) { parent->_make_dirty(); + } parent = nullptr; if (use_collision && is_root_shape() && root_collision_instance.is_valid()) { @@ -666,8 +678,9 @@ void CSGPrimitive3D::_bind_methods() { } void CSGPrimitive3D::set_invert_faces(bool p_invert) { - if (invert_faces == p_invert) + if (invert_faces == p_invert) { return; + } invert_faces = p_invert; @@ -685,8 +698,9 @@ CSGPrimitive3D::CSGPrimitive3D() { ///////////////////// CSGBrush *CSGMesh3D::_build_brush() { - if (!mesh.is_valid()) + if (!mesh.is_valid()) { return nullptr; + } Vector<Vector3> vertices; Vector<bool> smooth; @@ -707,8 +721,9 @@ CSGBrush *CSGMesh3D::_build_brush() { } Vector<Vector3> avertices = arrays[Mesh::ARRAY_VERTEX]; - if (avertices.size() == 0) + if (avertices.size() == 0) { continue; + } const Vector3 *vr = avertices.ptr(); @@ -822,8 +837,9 @@ CSGBrush *CSGMesh3D::_build_brush() { } } - if (vertices.size() == 0) + if (vertices.size() == 0) { return nullptr; + } return _create_brush_from_arrays(vertices, uvs, smooth, materials); } @@ -834,8 +850,9 @@ void CSGMesh3D::_mesh_changed() { } void CSGMesh3D::set_material(const Ref<Material> &p_material) { - if (material == p_material) + if (material == p_material) { return; + } material = p_material; _make_dirty(); } @@ -856,8 +873,9 @@ void CSGMesh3D::_bind_methods() { } void CSGMesh3D::set_mesh(const Ref<Mesh> &p_mesh) { - if (mesh == p_mesh) + if (mesh == p_mesh) { return; + } if (mesh.is_valid()) { mesh->disconnect("changed", callable_mp(this, &CSGMesh3D::_mesh_changed)); } @@ -1119,10 +1137,11 @@ CSGBrush *CSGBox3D::_build_brush() { v[2] = v[1] * (1 - 2 * (j & 1)); for (int k = 0; k < 3; k++) { - if (i < 3) + if (i < 3) { face_points[j][(i + k) % 3] = v[k]; - else + } else { face_points[3 - j][(i + k) % 3] = -v[k]; + } } } @@ -1480,8 +1499,9 @@ CSGBrush *CSGTorus3D::_build_brush() { float min_radius = inner_radius; float max_radius = outer_radius; - if (min_radius == max_radius) + if (min_radius == max_radius) { return nullptr; //sorry, can't + } if (min_radius > max_radius) { SWAP(min_radius, max_radius); @@ -1698,8 +1718,9 @@ CSGTorus3D::CSGTorus3D() { CSGBrush *CSGPolygon3D::_build_brush() { // set our bounding box - if (polygon.size() < 3) + if (polygon.size() < 3) { return nullptr; + } Vector<Point2> final_polygon = polygon; @@ -1709,8 +1730,9 @@ CSGBrush *CSGPolygon3D::_build_brush() { Vector<int> triangles = Geometry::triangulate_polygon(final_polygon); - if (triangles.size() < 3) + if (triangles.size() < 3) { return nullptr; + } Path3D *path = nullptr; Ref<Curve3D> curve; @@ -1724,28 +1746,35 @@ CSGBrush *CSGPolygon3D::_build_brush() { final_polygon_min = p; final_polygon_max = final_polygon_min; } else { - if (p.x < final_polygon_min.x) + if (p.x < final_polygon_min.x) { final_polygon_min.x = p.x; - if (p.y < final_polygon_min.y) + } + if (p.y < final_polygon_min.y) { final_polygon_min.y = p.y; + } - if (p.x > final_polygon_max.x) + if (p.x > final_polygon_max.x) { final_polygon_max.x = p.x; - if (p.y > final_polygon_max.y) + } + if (p.y > final_polygon_max.y) { final_polygon_max.y = p.y; + } } } Vector2 final_polygon_size = final_polygon_max - final_polygon_min; if (mode == MODE_PATH) { - if (!has_node(path_node)) + if (!has_node(path_node)) { return nullptr; + } Node *n = get_node(path_node); - if (!n) + if (!n) { return nullptr; + } path = Object::cast_to<Path3D>(n); - if (!path) + if (!path) { return nullptr; + } if (path != path_cache) { if (path_cache) { @@ -1761,10 +1790,12 @@ CSGBrush *CSGPolygon3D::_build_brush() { path_cache = nullptr; } curve = path->get_curve(); - if (curve.is_null()) + if (curve.is_null()) { return nullptr; - if (curve->get_baked_length() <= 0) + } + if (curve->get_baked_length() <= 0) { return nullptr; + } } CSGBrush *brush = memnew(CSGBrush); diff --git a/modules/cvtt/image_compress_cvtt.cpp b/modules/cvtt/image_compress_cvtt.cpp index 40e0f1a08f..2a4f836478 100644 --- a/modules/cvtt/image_compress_cvtt.cpp +++ b/modules/cvtt/image_compress_cvtt.cpp @@ -137,8 +137,9 @@ 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) + if (p_image->get_format() >= Image::FORMAT_BPTC_RGBA) { return; //do not compress, already compressed + } int w = p_image->get_width(); int h = p_image->get_height(); @@ -153,16 +154,17 @@ void image_compress_cvtt(Image *p_image, float p_lossy_quality, Image::UsedChann cvtt::Options options; uint32_t flags = cvtt::Flags::Fastest; - if (p_lossy_quality > 0.85) + if (p_lossy_quality > 0.85) { flags = cvtt::Flags::Ultra; - else if (p_lossy_quality > 0.75) + } else if (p_lossy_quality > 0.75) { flags = cvtt::Flags::Better; - else if (p_lossy_quality > 0.55) + } else if (p_lossy_quality > 0.55) { flags = cvtt::Flags::Default; - else if (p_lossy_quality > 0.35) + } else if (p_lossy_quality > 0.35) { flags = cvtt::Flags::Fast; - else if (p_lossy_quality > 0.15) + } else if (p_lossy_quality > 0.15) { flags = cvtt::Flags::Faster; + } flags |= cvtt::Flags::BC7_RespectPunchThrough; diff --git a/modules/dds/texture_loader_dds.cpp b/modules/dds/texture_loader_dds.cpp index 052f2c5e01..ba425371a8 100644 --- a/modules/dds/texture_loader_dds.cpp +++ b/modules/dds/texture_loader_dds.cpp @@ -95,17 +95,20 @@ 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) + if (r_error) { *r_error = ERR_CANT_OPEN; + } Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (!f) + if (!f) { return RES(); + } FileAccessRef fref(f); - if (r_error) + if (r_error) { *r_error = ERR_FILE_CORRUPT; + } ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open DDS texture file '" + p_path + "'."); @@ -119,8 +122,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, uint32_t mipmaps = f->get_32(); //skip 11 - for (int i = 0; i < 11; i++) + for (int i = 0; i < 11; i++) { f->get_32(); + } //validate @@ -155,8 +159,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, */ //must avoid this later - while (f->get_position() < 128) + while (f->get_position() < 128) { f->get_8(); + } DDSFormat dds_format; @@ -200,8 +205,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, ERR_FAIL_V_MSG(RES(), "Unrecognized or unsupported color layout in DDS '" + p_path + "'."); } - if (!(flags & DDSD_MIPMAPCOUNT)) + if (!(flags & DDSD_MIPMAPCOUNT)) { mipmaps = 1; + } Vector<uint8_t> src_data; @@ -241,8 +247,9 @@ 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) + if (palette[i * 4 + 3] < 255) { colsize = 4; + } } int w2 = width; @@ -264,8 +271,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, wb[dst_ofs + 0] = palette[src_ofs + 2]; wb[dst_ofs + 1] = palette[src_ofs + 1]; wb[dst_ofs + 2] = palette[src_ofs + 0]; - if (colsize == 4) + if (colsize == 4) { wb[dst_ofs + 3] = palette[src_ofs + 3]; + } } } else { //uncompressed generic... @@ -278,10 +286,11 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, size += w * h * info.block_size; } - if (dds_format == DDS_BGR565) + if (dds_format == DDS_BGR565) { size = size * 3 / 2; - else if (dds_format == DDS_BGR5A1) + } else if (dds_format == DDS_BGR5A1) { size = size * 2; + } src_data.resize(size); uint8_t *wb = src_data.ptrw(); @@ -404,8 +413,9 @@ RES ResourceFormatDDS::load(const String &p_path, const String &p_original_path, Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(img); - if (r_error) + if (r_error) { *r_error = OK; + } return texture; } @@ -419,7 +429,8 @@ bool ResourceFormatDDS::handles_type(const String &p_type) const { } String ResourceFormatDDS::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "dds") + if (p_path.get_extension().to_lower() == "dds") { return "ImageTexture"; + } return ""; } diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index a53c2a2364..4e7698b67c 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -214,8 +214,9 @@ 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 + if (!host || !active) { // Might have been disconnected while emitting a notification return; + } int ret = enet_host_service(host, &event, 0); @@ -259,13 +260,15 @@ void NetworkedMultiplayerENet::poll() { if (server) { // Do not notify other peers when server_relay is disabled. - if (!server_relay) + if (!server_relay) { break; + } // 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) + if (E->key() == *new_id) { continue; + } // Send existing peers to new peer ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE); encode_uint32(SYSMSG_ADD_PEER, &packet->data[0]); @@ -303,8 +306,9 @@ void NetworkedMultiplayerENet::poll() { } 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) + if (E->key() == *id) { continue; + } ENetPacket *packet = enet_packet_create(nullptr, 8, ENET_PACKET_FLAG_RELIABLE); encode_uint32(SYSMSG_REMOVE_PEER, &packet->data[0]); @@ -373,8 +377,9 @@ 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 + if (uint32_t(E->key()) == source) { // Do not resend to self continue; + } ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, packet.packet->flags); @@ -386,8 +391,9 @@ 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 + if (uint32_t(E->key()) == source || E->key() == -target) { // Do not resend to self, also do not send to excluded continue; + } ENetPacket *packet2 = enet_packet_create(packet.packet->data, packet.packet->dataLength, packet.packet->flags); @@ -485,8 +491,9 @@ void NetworkedMultiplayerENet::disconnect_peer(int p_peer, bool now) { } } - if (id) + if (id) { memdelete(id); + } emit_signal("peer_disconnected", p_peer); peer_map.erase(p_peer); @@ -522,10 +529,11 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer switch (transfer_mode) { case TRANSFER_MODE_UNRELIABLE: { - if (always_ordered) + if (always_ordered) { packet_flags = 0; - else + } else { packet_flags = ENET_PACKET_FLAG_UNSEQUENCED; + } channel = SYSCH_UNRELIABLE; } break; case TRANSFER_MODE_UNRELIABLE_ORDERED: { @@ -538,8 +546,9 @@ Error NetworkedMultiplayerENet::put_packet(const uint8_t *p_buffer, int p_buffer } break; } - if (transfer_channel > SYSCH_CONFIG) + if (transfer_channel > SYSCH_CONFIG) { channel = transfer_channel; + } Map<int, ENetPeer *>::Element *E = nullptr; @@ -563,8 +572,9 @@ 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 + if (F->key() == exclude) { // Exclude packet continue; + } ENetPacket *packet2 = enet_packet_create(packet->data, packet->dataLength, packet_flags); @@ -685,11 +695,13 @@ size_t NetworkedMultiplayerENet::enet_compress(void *context, const ENetBuffer * } int ret = Compression::compress(enet->dst_compressor_mem.ptrw(), enet->src_compressor_mem.ptr(), ofs, mode); - if (ret < 0) + if (ret < 0) { return 0; + } - if (ret > int(outLimit)) + if (ret > int(outLimit)) { return 0; // Do not bother + } copymem(outData, enet->dst_compressor_mem.ptr(), ret); diff --git a/modules/enet/register_types.cpp b/modules/enet/register_types.cpp index e5e9628c26..18051f756a 100644 --- a/modules/enet/register_types.cpp +++ b/modules/enet/register_types.cpp @@ -45,6 +45,7 @@ void register_enet_types() { } void unregister_enet_types() { - if (enet_ok) + if (enet_ok) { enet_deinitialize(); + } } diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp index 6bf4a7ef47..9b6d8a2d35 100644 --- a/modules/etc/image_etc.cpp +++ b/modules/etc/image_etc.cpp @@ -127,8 +127,9 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f Ref<Image> img = p_img->duplicate(); - if (img->get_format() != Image::FORMAT_RGBA8) + if (img->get_format() != Image::FORMAT_RGBA8) { img->convert(Image::FORMAT_RGBA8); //still uses RGBA to convert + } if (img->has_mipmaps()) { if (next_power_of_2(imgw) != imgw || next_power_of_2(imgh) != imgh) { @@ -165,12 +166,13 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f int encoding_time = 0; float effort = 0.0; //default, reasonable time - if (p_lossy_quality > 0.75) + if (p_lossy_quality > 0.75) { effort = 0.4; - else if (p_lossy_quality > 0.85) + } else if (p_lossy_quality > 0.85) { effort = 0.6; - else if (p_lossy_quality > 0.95) + } else if (p_lossy_quality > 0.95) { effort = 0.8; + } Etc::ErrorMetric error_metric = Etc::ErrorMetric::RGBX; // NOTE: we can experiment with other error metrics Etc::Image::Format etc2comp_etc_format = _image_format_to_etc2comp_format(etc_format); diff --git a/modules/etc/texture_loader_pkm.cpp b/modules/etc/texture_loader_pkm.cpp index 78768c5ba9..c40e9612a8 100644 --- a/modules/etc/texture_loader_pkm.cpp +++ b/modules/etc/texture_loader_pkm.cpp @@ -43,17 +43,20 @@ 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) + if (r_error) { *r_error = ERR_CANT_OPEN; + } Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (!f) + if (!f) { return RES(); + } FileAccessRef fref(f); - if (r_error) + if (r_error) { *r_error = ERR_FILE_CORRUPT; + } ERR_FAIL_COND_V_MSG(err != OK, RES(), "Unable to open PKM texture file '" + p_path + "'."); @@ -86,8 +89,9 @@ RES ResourceFormatPKM::load(const String &p_path, const String &p_original_path, Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(img); - if (r_error) + if (r_error) { *r_error = OK; + } f->close(); memdelete(f); @@ -103,7 +107,8 @@ bool ResourceFormatPKM::handles_type(const String &p_type) const { } String ResourceFormatPKM::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "pkm") + if (p_path.get_extension().to_lower() == "pkm") { return "ImageTexture"; + } return ""; } diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 7a231ac903..3d747ba41e 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -114,8 +114,9 @@ void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const { // set entries List<String> entry_key_list; - if (config_file->has_section("entry")) + if (config_file->has_section("entry")) { config_file->get_section_keys("entry", &entry_key_list); + } for (List<String>::Element *E = entry_key_list.front(); E; E = E->next()) { String key = E->get(); @@ -131,8 +132,9 @@ void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const { // set dependencies List<String> dependency_key_list; - if (config_file->has_section("dependencies")) + if (config_file->has_section("dependencies")) { config_file->get_section_keys("dependencies", &dependency_key_list); + } for (List<String>::Element *E = dependency_key_list.front(); E; E = E->next()) { String key = E->get(); @@ -156,8 +158,9 @@ void GDNativeLibrary::set_config_file(Ref<ConfigFile> p_config_file) { { List<String> entry_keys; - if (p_config_file->has_section("entry")) + if (p_config_file->has_section("entry")) { p_config_file->get_section_keys("entry", &entry_keys); + } for (List<String>::Element *E = entry_keys.front(); E; E = E->next()) { String key = E->get(); @@ -187,8 +190,9 @@ void GDNativeLibrary::set_config_file(Ref<ConfigFile> p_config_file) { { List<String> dependency_keys; - if (p_config_file->has_section("dependencies")) + if (p_config_file->has_section("dependencies")) { p_config_file->get_section_keys("dependencies", &dependency_keys); + } for (List<String>::Element *E = dependency_keys.front(); E; E = E->next()) { String key = E->get(); @@ -513,8 +517,9 @@ bool GDNativeLibraryResourceLoader::handles_type(const String &p_type) const { String GDNativeLibraryResourceLoader::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "gdnlib") + if (el == "gdnlib") { return "GDNativeLibrary"; + } return ""; } diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp index 234dbe9534..6b2b5b80a4 100644 --- a/modules/gdnative/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative/gdnative.cpp @@ -91,8 +91,9 @@ godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, god godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname) { ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname)); - if (class_info) + if (class_info) { return (godot_class_constructor)class_info->creation_func; + } return nullptr; } @@ -175,8 +176,9 @@ void *godot_get_class_tag(const godot_string_name *p_class) { } godot_object *godot_object_cast_to(const godot_object *p_object, void *p_class_tag) { - if (!p_object) + if (!p_object) { return nullptr; + } Object *o = (Object *)p_object; return o->is_class_ptr(p_class_tag) ? (godot_object *)o : nullptr; diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp index 278bc7217d..2a9836329e 100644 --- a/modules/gdnative/gdnative_library_editor_plugin.cpp +++ b/modules/gdnative/gdnative_library_editor_plugin.cpp @@ -128,8 +128,9 @@ void GDNativeLibraryEditor::_on_item_button(Object *item, int column, int id) { if (id == BUTTON_SELECT_LIBRARY || id == BUTTON_SELECT_DEPENDENCES) { EditorFileDialog::FileMode mode = EditorFileDialog::FILE_MODE_OPEN_FILE; - if (id == BUTTON_SELECT_DEPENDENCES) + if (id == BUTTON_SELECT_DEPENDENCES) { mode = EditorFileDialog::FILE_MODE_OPEN_FILES; + } file_dialog->set_meta("target", target); file_dialog->set_meta("section", section); @@ -192,10 +193,11 @@ void GDNativeLibraryEditor::_on_create_new_entry() { } void GDNativeLibraryEditor::_set_target_value(const String §ion, const String &target, Variant file) { - if (section == "entry") + if (section == "entry") { entry_configs[target].library = file; - else if (section == "dependencies") + } else if (section == "dependencies") { entry_configs[target].dependencies = file; + } _translate_to_config_file(); _update_tree(); } @@ -237,8 +239,9 @@ void GDNativeLibraryEditor::_translate_to_config_file() { 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()) + if (entry_configs[target].library.empty() && entry_configs[target].dependencies.empty()) { continue; + } config->set_value("entry", target, entry_configs[target].library); config->set_value("dependencies", target, entry_configs[target].dependencies); @@ -371,8 +374,9 @@ GDNativeLibraryEditor::GDNativeLibraryEditor() { void GDNativeLibraryEditorPlugin::edit(Object *p_node) { Ref<GDNativeLibrary> new_library = Object::cast_to<GDNativeLibrary>(p_node); - if (new_library.is_valid()) + if (new_library.is_valid()) { library_editor->edit(new_library); + } } bool GDNativeLibraryEditorPlugin::handles(Object *p_node) const { @@ -385,8 +389,9 @@ void GDNativeLibraryEditorPlugin::make_visible(bool p_visible) { EditorNode::get_singleton()->make_bottom_panel_item_visible(library_editor); } else { - if (library_editor->is_visible_in_tree()) + if (library_editor->is_visible_in_tree()) { EditorNode::get_singleton()->hide_bottom_panel(); + } button->hide(); } } diff --git a/modules/gdnative/gdnative_library_singleton_editor.cpp b/modules/gdnative/gdnative_library_singleton_editor.cpp index 27f18c91a8..409b6cbffe 100644 --- a/modules/gdnative/gdnative_library_singleton_editor.cpp +++ b/modules/gdnative/gdnative_library_singleton_editor.cpp @@ -135,19 +135,22 @@ void GDNativeLibrarySingletonEditor::_update_libraries() { } // The singletons list changed, we must update the settings - if (updated_disabled.size() != singletons_disabled.size()) + if (updated_disabled.size() != singletons_disabled.size()) { ProjectSettings::get_singleton()->set("gdnative/singletons_disabled", updated_disabled); + } updating = false; } void GDNativeLibrarySingletonEditor::_item_edited() { - if (updating) + if (updating) { return; + } TreeItem *item = libraries->get_edited(); - if (!item) + if (!item) { return; + } bool enabled = item->get_range(1); String path = item->get_metadata(0); @@ -165,8 +168,9 @@ void GDNativeLibrarySingletonEditor::_item_edited() { if (enabled) { disabled_paths.erase(path); } else { - if (disabled_paths.find(path) == -1) + if (disabled_paths.find(path) == -1) { disabled_paths.push_back(path); + } } undo_redo->create_action(enabled ? TTR("Enabled GDNative Singleton") : TTR("Disabled GDNative Singleton")); diff --git a/modules/gdnative/nativescript/godot_nativescript.cpp b/modules/gdnative/nativescript/godot_nativescript.cpp index ee944ee7cb..1bdac0dcb2 100644 --- a/modules/gdnative/nativescript/godot_nativescript.cpp +++ b/modules/gdnative/nativescript/godot_nativescript.cpp @@ -204,8 +204,9 @@ void GDAPI godot_nativescript_register_signal(void *p_gdnative_handle, const cha void GDAPI *godot_nativescript_get_userdata(godot_object *p_instance) { Object *instance = (Object *)p_instance; - if (!instance) + if (!instance) { return nullptr; + } if (instance->get_script_instance() && instance->get_script_instance()->get_language() == NativeScriptLanguage::get_singleton()) { return ((NativeScriptInstance *)instance->get_script_instance())->userdata; } @@ -320,8 +321,9 @@ const void GDAPI *godot_nativescript_get_type_tag(const godot_object *p_object) return nullptr; } - if (script->get_script_desc()) + if (script->get_script_desc()) { return script->get_script_desc()->type_tag; + } } return nullptr; diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index fe9496702a..f3dfd0b68e 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -184,8 +184,9 @@ bool NativeScript::can_instance() const { Ref<Script> NativeScript::get_base_script() const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return Ref<Script>(); + } NativeScript *script = (NativeScript *)NSL->create_script(); Ref<NativeScript> ns = Ref<NativeScript>(script); @@ -199,8 +200,9 @@ Ref<Script> NativeScript::get_base_script() const { StringName NativeScript::get_instance_base_type() const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return ""; + } return script_data->base_native_type; } @@ -272,8 +274,9 @@ bool NativeScript::has_method(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - if (script_data->methods.has(p_method)) + if (script_data->methods.has(p_method)) { return true; + } script_data = script_data->base_data; } @@ -283,14 +286,16 @@ bool NativeScript::has_method(const StringName &p_method) const { MethodInfo NativeScript::get_method_info(const StringName &p_method) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return MethodInfo(); + } while (script_data) { Map<StringName, NativeScriptDesc::Method>::Element *M = script_data->methods.find(p_method); - if (M) + if (M) { return M->get().info; + } script_data = script_data->base_data; } @@ -304,8 +309,9 @@ bool NativeScript::is_valid() const { bool NativeScript::is_tool() const { NativeScriptDesc *script_data = get_script_desc(); - if (script_data) + if (script_data) { return script_data->is_tool; + } return false; } @@ -318,8 +324,9 @@ bool NativeScript::has_script_signal(const StringName &p_signal) const { NativeScriptDesc *script_data = get_script_desc(); while (script_data) { - if (script_data->signals_.has(p_signal)) + if (script_data->signals_.has(p_signal)) { return true; + } script_data = script_data->base_data; } return false; @@ -328,8 +335,9 @@ bool NativeScript::has_script_signal(const StringName &p_signal) const { void NativeScript::get_script_signal_list(List<MethodInfo> *r_signals) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return; + } Set<MethodInfo> signals_; @@ -354,8 +362,9 @@ bool NativeScript::get_property_default_value(const StringName &p_property, Vari P = script_data->properties.find(p_property); script_data = script_data->base_data; } - if (!P) + if (!P) { return false; + } r_value = P.get().default_value; return true; @@ -367,8 +376,9 @@ void NativeScript::update_exports() { void NativeScript::get_script_method_list(List<MethodInfo> *p_list) const { NativeScriptDesc *script_data = get_script_desc(); - if (!script_data) + if (!script_data) { return; + } Set<MethodInfo> methods; @@ -990,17 +1000,20 @@ String NativeScriptInstance::to_string(bool *r_valid) { Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK) { if (ret.get_type() != Variant::STRING) { - if (r_valid) + if (r_valid) { *r_valid = false; + } ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret.operator String(); } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } @@ -1102,8 +1115,9 @@ void NativeScriptInstance::call_multilevel_reversed(const StringName &p_method, NativeScriptInstance::~NativeScriptInstance() { NativeScriptDesc *script_data = GET_SCRIPT_DESC(); - if (!script_data) + if (!script_data) { return; + } script_data->destroy_func.destroy_func((godot_object *)owner, script_data->destroy_func.method_data, userdata); @@ -1155,25 +1169,30 @@ 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) + if (P.get().getter.free_func) { P.get().getter.free_func(P.get().getter.method_data); + } - if (P.get().setter.free_func) + if (P.get().setter.free_func) { P.get().setter.free_func(P.get().setter.method_data); + } } // free method stuff for (Map<StringName, NativeScriptDesc::Method>::Element *M = C->get().methods.front(); M; M = M->next()) { - if (M->get().method.free_func) + if (M->get().method.free_func) { M->get().method.free_func(M->get().method.method_data); + } } // free constructor/destructor - if (C->get().create_func.free_func) + if (C->get().create_func.free_func) { C->get().create_func.free_func(C->get().create_func.method_data); + } - if (C->get().destroy_func.free_func) + if (C->get().destroy_func.free_func) { C->get().destroy_func.free_func(C->get().destroy_func.method_data); + } } erase_and_unload.insert(lib_path, gdn); @@ -1407,8 +1426,9 @@ int NativeScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_a int current = 0; for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { - if (current >= p_info_max) + if (current >= p_info_max) { break; + } p_info_arr[current].call_count = d->get().call_count; p_info_arr[current].self_time = d->get().self_time; @@ -1430,8 +1450,9 @@ int NativeScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, in int current = 0; for (Map<StringName, ProfileData>::Element *d = profile_data.front(); d; d = d->next()) { - if (current >= p_info_max) + if (current >= p_info_max) { break; + } if (d->get().last_frame_call_count) { p_info_arr[current].call_count = d->get().last_frame_call_count; @@ -1508,14 +1529,16 @@ void NativeScriptLanguage::unregister_binding_functions(int p_idx) { for (Set<Vector<void *> *>::Element *E = binding_instances.front(); E; E = E->next()) { Vector<void *> &binding_data = *E->get(); - if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data) + if (p_idx < binding_data.size() && binding_data[p_idx] && binding_functions[p_idx].second.free_instance_binding_data) { binding_functions[p_idx].second.free_instance_binding_data(binding_functions[p_idx].second.data, binding_data[p_idx]); + } } binding_functions.write[p_idx].first = false; - if (binding_functions[p_idx].second.free_func) + if (binding_functions[p_idx].second.free_func) { binding_functions[p_idx].second.free_func(binding_functions[p_idx].second.data); + } } void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_object) { @@ -1525,8 +1548,9 @@ void *NativeScriptLanguage::get_instance_binding_data(int p_idx, Object *p_objec Vector<void *> *binding_data = (Vector<void *> *)p_object->get_script_instance_binding(lang_idx); - if (!binding_data) + if (!binding_data) { return nullptr; // should never happen. + } if (binding_data->size() <= p_idx) { // okay, add new elements here. @@ -1564,14 +1588,16 @@ void *NativeScriptLanguage::alloc_instance_binding_data(Object *p_object) { } void NativeScriptLanguage::free_instance_binding_data(void *p_data) { - if (!p_data) + if (!p_data) { return; + } Vector<void *> &binding_data = *(Vector<void *> *)p_data; for (int i = 0; i < binding_data.size(); i++) { - if (!binding_data[i]) + if (!binding_data[i]) { continue; + } if (binding_functions[i].first && binding_functions[i].second.free_instance_binding_data) { binding_functions[i].second.free_instance_binding_data(binding_functions[i].second.data, binding_data[i]); @@ -1586,17 +1612,20 @@ 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) + if (!data) { return; + } Vector<void *> &binding_data = *(Vector<void *> *)data; for (int i = 0; i < binding_data.size(); i++) { - if (!binding_data[i]) + if (!binding_data[i]) { continue; + } - if (!binding_functions[i].first) + if (!binding_functions[i].first) { continue; + } if (binding_functions[i].second.refcount_incremented_instance_binding) { binding_functions[i].second.refcount_incremented_instance_binding(binding_data[i], p_object); @@ -1607,19 +1636,22 @@ 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) + if (!data) { return true; + } Vector<void *> &binding_data = *(Vector<void *> *)data; bool can_die = true; for (int i = 0; i < binding_data.size(); i++) { - if (!binding_data[i]) + if (!binding_data[i]) { continue; + } - if (!binding_functions[i].first) + if (!binding_functions[i].first) { continue; + } if (binding_functions[i].second.refcount_decremented_instance_binding) { can_die = can_die && binding_functions[i].second.refcount_decremented_instance_binding(binding_data[i], p_object); @@ -1640,13 +1672,15 @@ void NativeScriptLanguage::set_global_type_tag(int p_idx, StringName p_class_nam } const void *NativeScriptLanguage::get_global_type_tag(int p_idx, StringName p_class_name) const { - if (!global_type_tags.has(p_idx)) + if (!global_type_tags.has(p_idx)) { return nullptr; + } const HashMap<StringName, const void *> &tags = global_type_tags[p_idx]; - if (!tags.has(p_class_name)) + if (!tags.has(p_class_name)) { return nullptr; + } const void *tag = tags.get(p_class_name); @@ -1682,8 +1716,9 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { library_classes.insert(lib_path, Map<StringName, NativeScriptDesc>()); - if (!library_script_users.has(lib_path)) + if (!library_script_users.has(lib_path)) { library_script_users.insert(lib_path, Set<NativeScript *>()); + } void *proc_ptr; @@ -1792,16 +1827,20 @@ String NativeScriptLanguage::get_global_class_name(const String &p_path, String if (!p_path.empty()) { Ref<NativeScript> script = ResourceLoader::load(p_path, "NativeScript"); if (script.is_valid()) { - if (r_base_type) + if (r_base_type) { *r_base_type = script->get_instance_base_type(); - if (r_icon_path) + } + if (r_icon_path) { *r_icon_path = script->get_script_class_icon_path(); + } return script->get_script_class_name(); } - if (r_base_type) + if (r_base_type) { *r_base_type = String(); - if (r_icon_path) + } + if (r_icon_path) { *r_icon_path = String(); + } } return String(); } @@ -1815,8 +1854,9 @@ void NativeReloadNode::_notification(int p_what) { switch (p_what) { case NOTIFICATION_WM_FOCUS_OUT: { - if (unloaded) + if (unloaded) { break; + } MutexLock lock(NSL->mutex); NSL->_unload_stuff(true); @@ -1848,8 +1888,9 @@ void NativeReloadNode::_notification(int p_what) { } break; case NOTIFICATION_WM_FOCUS_IN: { - if (!unloaded) + if (!unloaded) { break; + } MutexLock lock(NSL->mutex); Set<StringName> libs_to_remove; @@ -1891,8 +1932,9 @@ void NativeReloadNode::_notification(int p_what) { for (Set<NativeScript *>::Element *S = U->get().front(); S; S = S->next()) { NativeScript *script = S->get(); - if (script->placeholders.size() == 0) + if (script->placeholders.size() == 0) { continue; + } for (Set<PlaceHolderScriptInstance *>::Element *P = script->placeholders.front(); P; P = P->next()) { script->_update_placeholder(P->get()); @@ -1928,8 +1970,9 @@ bool ResourceFormatLoaderNativeScript::handles_type(const String &p_type) const String ResourceFormatLoaderNativeScript::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "gdns") + if (el == "gdns") { return "NativeScript"; + } return ""; } diff --git a/modules/gdnative/pluginscript/pluginscript_loader.cpp b/modules/gdnative/pluginscript/pluginscript_loader.cpp index 7ce124c16a..4feee4f4a5 100644 --- a/modules/gdnative/pluginscript/pluginscript_loader.cpp +++ b/modules/gdnative/pluginscript/pluginscript_loader.cpp @@ -40,8 +40,9 @@ ResourceFormatLoaderPluginScript::ResourceFormatLoaderPluginScript(PluginScriptL } RES ResourceFormatLoaderPluginScript::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) + if (r_error) { *r_error = ERR_FILE_CANT_OPEN; + } PluginScript *script = memnew(PluginScript); script->init(_language); @@ -55,8 +56,9 @@ RES ResourceFormatLoaderPluginScript::load(const String &p_path, const String &p script->reload(); - if (r_error) + if (r_error) { *r_error = OK; + } return scriptres; } @@ -71,8 +73,9 @@ bool ResourceFormatLoaderPluginScript::handles_type(const String &p_type) const String ResourceFormatLoaderPluginScript::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == _language->get_extension()) + if (el == _language->get_extension()) { return _language->get_type(); + } return ""; } diff --git a/modules/gdnative/pluginscript/pluginscript_script.cpp b/modules/gdnative/pluginscript/pluginscript_script.cpp index d659ade876..87c6288806 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.cpp +++ b/modules/gdnative/pluginscript/pluginscript_script.cpp @@ -154,10 +154,12 @@ Ref<Script> PluginScript::get_base_script() const { } StringName PluginScript::get_instance_base_type() const { - if (_native_parent) + if (_native_parent) { return _native_parent; - if (_ref_base_parent.is_valid()) + } + if (_ref_base_parent.is_valid()) { return _ref_base_parent->get_instance_base_type(); + } return StringName(); } @@ -226,8 +228,9 @@ String PluginScript::get_source_code() const { } void PluginScript::set_source_code(const String &p_code) { - if (_source == p_code) + if (_source == p_code) { return; + } _source = p_code; } @@ -241,11 +244,13 @@ Error PluginScript::reload(bool p_keep_state) { _valid = false; String basedir = _path; - if (basedir == "") + if (basedir == "") { basedir = get_path(); + } - if (basedir != "") + if (basedir != "") { basedir = basedir.get_base_dir(); + } if (_data) { _desc->finish(_data); @@ -471,11 +476,11 @@ void PluginScript::get_script_signal_list(List<MethodInfo> *r_signals) const { int PluginScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED - if (_member_lines.has(p_member)) + if (_member_lines.has(p_member)) { return _member_lines[p_member]; - else + } #endif - return -1; + return -1; } Vector<ScriptNetData> PluginScript::get_rpc_methods() const { @@ -494,15 +499,17 @@ uint16_t PluginScript::get_rpc_method_id(const StringName &p_method) const { StringName PluginScript::get_rpc_method(const uint16_t p_rpc_method_id) const { ASSERT_SCRIPT_VALID_V(StringName()); - if (p_rpc_method_id >= _rpc_methods.size()) + if (p_rpc_method_id >= _rpc_methods.size()) { return StringName(); + } return _rpc_methods[p_rpc_method_id].name; } MultiplayerAPI::RPCMode PluginScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const { ASSERT_SCRIPT_VALID_V(MultiplayerAPI::RPC_MODE_DISABLED); - if (p_rpc_method_id >= _rpc_methods.size()) + if (p_rpc_method_id >= _rpc_methods.size()) { return MultiplayerAPI::RPC_MODE_DISABLED; + } return _rpc_methods[p_rpc_method_id].mode; } @@ -527,15 +534,17 @@ uint16_t PluginScript::get_rset_property_id(const StringName &p_property) const StringName PluginScript::get_rset_property(const uint16_t p_rset_property_id) const { ASSERT_SCRIPT_VALID_V(StringName()); - if (p_rset_property_id >= _rpc_variables.size()) + if (p_rset_property_id >= _rpc_variables.size()) { return StringName(); + } return _rpc_variables[p_rset_property_id].name; } MultiplayerAPI::RPCMode PluginScript::get_rset_mode_by_id(const uint16_t p_rset_property_id) const { ASSERT_SCRIPT_VALID_V(MultiplayerAPI::RPC_MODE_DISABLED); - if (p_rset_property_id >= _rpc_variables.size()) + if (p_rset_property_id >= _rpc_variables.size()) { return MultiplayerAPI::RPC_MODE_DISABLED; + } return _rpc_variables[p_rset_property_id].mode; } diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index bffbb86526..136af5bd1e 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -254,8 +254,9 @@ void register_gdnative_types() { for (int i = 0; i < singletons.size(); i++) { String path = singletons[i]; - if (excluded.has(path)) + if (excluded.has(path)) { continue; + } Ref<GDNativeLibrary> lib = ResourceLoader::load(path); Ref<GDNative> singleton; diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.cpp b/modules/gdnative/videodecoder/video_stream_gdnative.cpp index 476f44b185..9d9c5b6473 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.cpp +++ b/modules/gdnative/videodecoder/video_stream_gdnative.cpp @@ -208,10 +208,12 @@ VideoStreamPlaybackGDNative::~VideoStreamPlaybackGDNative() { } void VideoStreamPlaybackGDNative::cleanup() { - if (data_struct) + if (data_struct) { interface->destructor(data_struct); - if (pcm) + } + if (pcm) { memfree(pcm); + } pcm = nullptr; time = 0; num_channels = -1; @@ -257,8 +259,9 @@ void VideoStreamPlaybackGDNative::stop() { void VideoStreamPlaybackGDNative::seek(float p_time) { ERR_FAIL_COND(interface == nullptr); interface->seek(data_struct, p_time); - if (p_time < time) + if (p_time < time) { seek_backward = true; + } time = p_time; // reset audio buffers memset(pcm, 0, num_channels * AUX_BUFFER_SIZE * sizeof(float)); @@ -320,12 +323,14 @@ int VideoStreamPlaybackGDNative::get_mix_rate() const { Ref<VideoStreamPlayback> VideoStreamGDNative::instance_playback() { Ref<VideoStreamPlaybackGDNative> pb = memnew(VideoStreamPlaybackGDNative); VideoDecoderGDNative *decoder = decoder_server.get_decoder(file.get_extension().to_lower()); - if (decoder == nullptr) + if (decoder == nullptr) { return nullptr; + } pb->set_interface(decoder->interface); pb->set_audio_track(audio_track); - if (pb->open_file(file)) + if (pb->open_file(file)) { return pb; + } return nullptr; } @@ -382,7 +387,8 @@ bool ResourceFormatLoaderVideoStreamGDNative::handles_type(const String &p_type) String ResourceFormatLoaderVideoStreamGDNative::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (VideoDecoderServer::get_instance()->get_extensions().has(el)) + if (VideoDecoderServer::get_instance()->get_extensions().has(el)) { return "VideoStreamGDNative"; + } return ""; } diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.h b/modules/gdnative/videodecoder/video_stream_gdnative.h index 2da63e96d6..53017a6a97 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.h +++ b/modules/gdnative/videodecoder/video_stream_gdnative.h @@ -86,8 +86,9 @@ public: } VideoDecoderGDNative *get_decoder(const String &extension) { - if (extensions.size() == 0 || !extensions.has(extension)) + if (extensions.size() == 0 || !extensions.has(extension)) { return nullptr; + } return decoders[extensions[extension]]; } diff --git a/modules/gdnavigation/gd_navigation_server.cpp b/modules/gdnavigation/gd_navigation_server.cpp index 5aea9f8b9f..c80cdcfeab 100644 --- a/modules/gdnavigation/gd_navigation_server.cpp +++ b/modules/gdnavigation/gd_navigation_server.cpp @@ -249,8 +249,9 @@ 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) + if (region->get_map()->get_self() == p_map) { return; // Pointless + } region->get_map()->remove_region(region); region->set_map(nullptr); @@ -303,8 +304,9 @@ COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) { ERR_FAIL_COND(agent == nullptr); if (agent->get_map()) { - if (agent->get_map()->get_self() == p_map) + if (agent->get_map()->get_self() == p_map) { return; // Pointless + } agent->get_map()->remove_agent(agent); } diff --git a/modules/gdnavigation/nav_map.cpp b/modules/gdnavigation/nav_map.cpp index e55a3deb8f..c7df6dc1fb 100644 --- a/modules/gdnavigation/nav_map.cpp +++ b/modules/gdnavigation/nav_map.cpp @@ -145,8 +145,9 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p gd::NavigationPoly *least_cost_poly = &navigation_polys[least_cost_id]; const gd::Edge &edge = least_cost_poly->poly->edges[i]; - if (!edge.other_polygon) + if (!edge.other_polygon) { continue; + } #ifdef USE_ENTRY_POINT Vector3 edge_line[2] = { @@ -343,15 +344,17 @@ Vector<Vector3> NavMap::get_path(Vector3 p_origin, Vector3 p_destination, bool p } } - if (p->prev_navigation_poly_id != -1) + if (p->prev_navigation_poly_id != -1) { p = &navigation_polys[p->prev_navigation_poly_id]; - else + } else { // The end p = nullptr; + } } - if (path[path.size() - 1] != begin_point) + if (path[path.size() - 1] != begin_point) { path.push_back(begin_point); + } path.invert(); @@ -711,8 +714,9 @@ void NavMap::sync() { if (agents_dirty) { std::vector<RVO::Agent *> raw_agents; raw_agents.reserve(agents.size()); - for (size_t i(0); i < agents.size(); i++) + for (size_t i(0); i < agents.size(); i++) { raw_agents.push_back(agents[i]->get_agent()); + } rvo.buildAgentTree(raw_agents); } @@ -746,12 +750,14 @@ void NavMap::dispatch_callbacks() { void NavMap::clip_path(const std::vector<gd::NavigationPoly> &p_navigation_polys, Vector<Vector3> &path, const gd::NavigationPoly *from_poly, const Vector3 &p_to_point, const gd::NavigationPoly *p_to_poly) const { Vector3 from = path[path.size() - 1]; - if (from.distance_to(p_to_point) < CMP_EPSILON) + if (from.distance_to(p_to_point) < CMP_EPSILON) { return; + } Plane cut_plane; cut_plane.normal = (from - p_to_point).cross(up); - if (cut_plane.normal == Vector3()) + if (cut_plane.normal == Vector3()) { return; + } cut_plane.normal.normalize(); cut_plane.d = cut_plane.normal.dot(from); diff --git a/modules/gdnavigation/nav_region.cpp b/modules/gdnavigation/nav_region.cpp index 3dff19cd65..51fba67cc3 100644 --- a/modules/gdnavigation/nav_region.cpp +++ b/modules/gdnavigation/nav_region.cpp @@ -70,13 +70,15 @@ void NavRegion::update_polygons() { return; } - if (mesh.is_null()) + if (mesh.is_null()) { return; + } Vector<Vector3> vertices = mesh->get_vertices(); int len = vertices.size(); - if (len == 0) + if (len == 0) { return; + } const Vector3 *vertices_r = vertices.ptr(); diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp index 379131864e..5fe1060aae 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.cpp +++ b/modules/gdnavigation/navigation_mesh_editor_plugin.cpp @@ -69,8 +69,9 @@ void NavigationMeshEditor::_bake_pressed() { } void NavigationMeshEditor::_clear_pressed() { - if (node) + if (node) { NavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh()); + } button_bake->set_pressed(false); bake_info->set_text(""); diff --git a/modules/gdnavigation/navigation_mesh_generator.cpp b/modules/gdnavigation/navigation_mesh_generator.cpp index 78818fd990..7dc08fbf29 100644 --- a/modules/gdnavigation/navigation_mesh_generator.cpp +++ b/modules/gdnavigation/navigation_mesh_generator.cpp @@ -74,8 +74,9 @@ void NavigationMeshGenerator::_add_mesh(const Ref<Mesh> &p_mesh, const Transform for (int i = 0; i < p_mesh->get_surface_count(); i++) { current_vertex_count = p_verticies.size() / 3; - if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) + if (p_mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { continue; + } int index_count = 0; if (p_mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_INDEX) { @@ -314,8 +315,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( rcContext ctx; #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Setting up Configuration..."), 1); + } #endif const float *verts = vertices.ptr(); @@ -351,14 +353,16 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( cfg.bmax[2] = bmax[2]; #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Calculating grid size..."), 2); + } #endif rcCalcGridSize(cfg.bmin, cfg.bmax, cfg.cs, &cfg.width, &cfg.height); #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Creating heightfield..."), 3); + } #endif hf = rcAllocHeightfield(); @@ -366,8 +370,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( ERR_FAIL_COND(!rcCreateHeightfield(&ctx, *hf, cfg.width, cfg.height, cfg.bmin, cfg.bmax, cfg.cs, cfg.ch)); #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Marking walkable triangles..."), 4); + } #endif { Vector<unsigned char> tri_areas; @@ -381,16 +386,20 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( ERR_FAIL_COND(!rcRasterizeTriangles(&ctx, verts, nverts, tris, tri_areas.ptr(), ntris, *hf, cfg.walkableClimb)); } - if (p_nav_mesh->get_filter_low_hanging_obstacles()) + if (p_nav_mesh->get_filter_low_hanging_obstacles()) { rcFilterLowHangingWalkableObstacles(&ctx, cfg.walkableClimb, *hf); - if (p_nav_mesh->get_filter_ledge_spans()) + } + if (p_nav_mesh->get_filter_ledge_spans()) { rcFilterLedgeSpans(&ctx, cfg.walkableHeight, cfg.walkableClimb, *hf); - if (p_nav_mesh->get_filter_walkable_low_height_spans()) + } + if (p_nav_mesh->get_filter_walkable_low_height_spans()) { rcFilterWalkableLowHeightSpans(&ctx, cfg.walkableHeight, *hf); + } #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Constructing compact heightfield..."), 5); + } #endif chf = rcAllocCompactHeightfield(); @@ -402,15 +411,17 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( hf = nullptr; #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Eroding walkable area..."), 6); + } #endif ERR_FAIL_COND(!rcErodeWalkableArea(&ctx, cfg.walkableRadius, *chf)); #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Partitioning..."), 7); + } #endif if (p_nav_mesh->get_sample_partition_type() == NavigationMesh::SAMPLE_PARTITION_WATERSHED) { @@ -423,8 +434,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( } #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Creating contours..."), 8); + } #endif cset = rcAllocContourSet(); @@ -433,8 +445,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( ERR_FAIL_COND(!rcBuildContours(&ctx, *chf, cfg.maxSimplificationError, cfg.maxEdgeLen, *cset)); #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Creating polymesh..."), 9); + } #endif poly_mesh = rcAllocPolyMesh(); @@ -451,8 +464,9 @@ void NavigationMeshGenerator::_build_recast_navigation_mesh( cset = nullptr; #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Converting to native navigation mesh..."), 10); + } #endif _convert_detail_mesh_to_native_navigation_mesh(detail_mesh, p_nav_mesh); @@ -483,8 +497,9 @@ void NavigationMeshGenerator::bake(Ref<NavigationMesh> p_nav_mesh, Node *p_node) ep = memnew(EditorProgress("bake", TTR("Navigation Mesh Generator Setup:"), 11)); } - if (ep) + if (ep) { ep->step(TTR("Parsing Geometry..."), 0); + } #endif Vector<float> vertices; @@ -543,11 +558,13 @@ void NavigationMeshGenerator::bake(Ref<NavigationMesh> p_nav_mesh, Node *p_node) } #ifdef TOOLS_ENABLED - if (ep) + if (ep) { ep->step(TTR("Done!"), 11); + } - if (ep) + if (ep) { memdelete(ep); + } #endif } diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index c3091a56a6..d0f27b632b 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -178,8 +178,9 @@ 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])) + while (to < str.length() && _is_text_char(str[to])) { to++; + } String word = str.substr(j, to - j); Color col = Color(); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 1d26e2148e..632407c61f 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -180,10 +180,12 @@ Ref<Script> GDScript::get_base_script() const { } StringName GDScript::get_instance_base_type() const { - if (native.is_valid()) + if (native.is_valid()) { return native->get_name(); - if (base.is_valid() && base->is_valid()) + } + if (base.is_valid() && base->is_valid()) { return base->get_instance_base_type(); + } return StringName(); } @@ -253,8 +255,9 @@ bool GDScript::has_method(const StringName &p_method) const { MethodInfo GDScript::get_method_info(const StringName &p_method) const { const Map<StringName, GDScriptFunction *>::Element *E = member_functions.find(p_method); - if (!E) + if (!E) { return MethodInfo(); + } GDScriptFunction *func = E->get(); MethodInfo mi; @@ -285,8 +288,9 @@ bool GDScript::get_property_default_value(const StringName &p_property, Variant ScriptInstance *GDScript::instance_create(Object *p_this) { GDScript *top = this; - while (top->_base) + 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())) { @@ -327,8 +331,9 @@ String GDScript::get_source_code() const { } void GDScript::set_source_code(const String &p_code) { - if (source == p_code) + if (source == p_code) { return; + } source = p_code; #ifdef TOOLS_ENABLED source_changed_cache = true; @@ -355,8 +360,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { #ifdef TOOLS_ENABLED static Vector<GDScript *> base_caches; - if (!p_recursive_call) + if (!p_recursive_call) { base_caches.clear(); + } base_caches.append(this); bool changed = false; @@ -367,11 +373,13 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { String basedir = path; - if (basedir == "") + if (basedir == "") { basedir = get_path(); + } - if (basedir != "") + if (basedir != "") { basedir = basedir.get_base_dir(); + } GDScriptParser parser; Error err = parser.parse(source, basedir, true, path); @@ -402,8 +410,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { } else if (c->extends_class.size() != 0) { String base = c->extends_class[0]; - if (ScriptServer::is_global_class(base)) + if (ScriptServer::is_global_class(base)) { path = ScriptServer::get_global_class_path(base); + } } if (path != "") { @@ -424,8 +433,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { member_default_values_cache.clear(); for (int i = 0; i < c->variables.size(); i++) { - if (c->variables[i]._export.type == Variant::NIL) + if (c->variables[i]._export.type == Variant::NIL) { continue; + } members_cache.push_back(c->variables[i]._export); member_default_values_cache[c->variables[i].identifier] = c->variables[i].default_value; @@ -449,8 +459,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { if (base_cache.is_valid() && base_cache->is_valid()) { for (int i = 0; i < base_caches.size(); i++) { if (base_caches[i] == base_cache.ptr()) { - if (r_err) + if (r_err) { *r_err = true; + } valid = false; // to show error in the editor base_cache->valid = false; base_cache->inheriters_cache.clear(); // to prevent future stackoverflows @@ -461,8 +472,9 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) { } } if (base_cache->_update_exports(r_err, true)) { - if (r_err && *r_err) + if (r_err && *r_err) { return false; + } changed = true; } } @@ -491,16 +503,18 @@ void GDScript::update_exports() { bool cyclic_error = false; _update_exports(&cyclic_error); - if (cyclic_error) + if (cyclic_error) { return; + } Set<ObjectID> copy = inheriters_cache; //might get modified for (Set<ObjectID>::Element *E = copy.front(); E; E = E->next()) { Object *id = ObjectDB::get_instance(E->get()); GDScript *s = Object::cast_to<GDScript>(id); - if (!s) + if (!s) { continue; + } s->update_exports(); } @@ -526,11 +540,13 @@ Error GDScript::reload(bool p_keep_state) { String basedir = path; - if (basedir == "") + if (basedir == "") { basedir = get_path(); + } - if (basedir != "") + if (basedir != "") { basedir = basedir.get_base_dir(); + } if (source.find("%BASE%") != -1) { //loading a template, don't parse @@ -619,14 +635,16 @@ uint16_t GDScript::get_rpc_method_id(const StringName &p_method) const { } StringName GDScript::get_rpc_method(const uint16_t p_rpc_method_id) const { - if (p_rpc_method_id >= rpc_functions.size()) + if (p_rpc_method_id >= rpc_functions.size()) { return StringName(); + } return rpc_functions[p_rpc_method_id].name; } MultiplayerAPI::RPCMode GDScript::get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const { - if (p_rpc_method_id >= rpc_functions.size()) + if (p_rpc_method_id >= rpc_functions.size()) { return MultiplayerAPI::RPC_MODE_DISABLED; + } return rpc_functions[p_rpc_method_id].mode; } @@ -648,14 +666,16 @@ uint16_t GDScript::get_rset_property_id(const StringName &p_variable) const { } StringName GDScript::get_rset_property(const uint16_t p_rset_member_id) const { - if (p_rset_member_id >= rpc_variables.size()) + if (p_rset_member_id >= rpc_variables.size()) { return StringName(); + } return rpc_variables[p_rset_member_id].name; } MultiplayerAPI::RPCMode GDScript::get_rset_mode_by_id(const uint16_t p_rset_member_id) const { - if (p_rset_member_id >= rpc_variables.size()) + if (p_rset_member_id >= rpc_variables.size()) { return MultiplayerAPI::RPC_MODE_DISABLED; + } return rpc_variables[p_rset_member_id].mode; } @@ -715,8 +735,9 @@ 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 + } else { return false; + } return true; } @@ -776,11 +797,13 @@ Error GDScript::load_byte_code(const String &p_path) { String basedir = path; - if (basedir == "") + if (basedir == "") { basedir = get_path(); + } - if (basedir != "") + if (basedir != "") { basedir = basedir.get_base_dir(); + } valid = false; GDScriptParser parser; @@ -845,8 +868,9 @@ const Map<StringName, GDScriptFunction *> &GDScript::debug_get_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) + if (E->get().index == p_idx) { return E->key(); + } } return "<error>"; @@ -875,8 +899,9 @@ bool GDScript::inherits_script(const Ref<Script> &p_script) const { } bool GDScript::has_script_signal(const StringName &p_signal) const { - if (_signals.has(p_signal)) + if (_signals.has(p_signal)) { return true; + } if (base.is_valid()) { return base->has_script_signal(p_signal); } @@ -957,8 +982,9 @@ void GDScript::_save_orphaned_subclasses() { for (int i = 0; i < weak_subclasses.size(); i++) { ClassRefWithName subclass = weak_subclasses[i]; Object *obj = ObjectDB::get_instance(subclass.id); - if (!obj) + if (!obj) { continue; + } // subclass is not released GDScriptLanguage::get_singleton()->add_orphan_subclass(subclass.fully_qualified_name, subclass.id); } @@ -999,13 +1025,15 @@ void GDScript::_init_rpc_methods_properties() { } } - if (cscript != this) + if (cscript != this) { sub_E = sub_E->next(); + } - if (sub_E) + if (sub_E) { cscript = sub_E->get().ptr(); - else + } else { cscript = nullptr; + } } // Sort so we are 100% that they are always the same. @@ -1084,8 +1112,9 @@ bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { Callable::CallError err; Variant ret = E->get()->call(this, (const Variant **)args, 2, err); - if (err.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool()) + if (err.error == Callable::CallError::CALL_OK && ret.get_type() == Variant::BOOL && ret.operator bool()) { return true; + } } sptr = sptr->_base; } @@ -1147,15 +1176,17 @@ Variant::Type GDScriptInstance::get_property_type(const StringName &p_name, bool const GDScript *sptr = script.ptr(); while (sptr) { if (sptr->member_info.has(p_name)) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return sptr->member_info[p_name].type; } sptr = sptr->_base; } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = false; + } return Variant::NIL; } @@ -1183,12 +1214,15 @@ void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const ERR_CONTINUE(pinfo.type < 0 || pinfo.type >= Variant::VARIANT_MAX); pinfo.name = d["name"]; ERR_CONTINUE(pinfo.name == ""); - if (d.has("hint")) + if (d.has("hint")) { pinfo.hint = PropertyHint(d["hint"].operator int()); - if (d.has("hint_string")) + } + if (d.has("hint_string")) { pinfo.hint_string = d["hint_string"]; - if (d.has("usage")) + } + if (d.has("usage")) { pinfo.usage = d["usage"]; + } props.push_back(pinfo); } @@ -1227,8 +1261,9 @@ void GDScriptInstance::get_method_list(List<MethodInfo> *p_list) const { MethodInfo mi; mi.name = E->key(); mi.flags |= METHOD_FLAG_FROM_SCRIPT; - for (int i = 0; i < E->get()->get_argument_count(); i++) + for (int i = 0; i < E->get()->get_argument_count(); i++) { mi.arguments.push_back(PropertyInfo(Variant::NIL, "arg" + itos(i))); + } p_list->push_back(mi); } sptr = sptr->_base; @@ -1239,8 +1274,9 @@ 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); - if (E) + if (E) { return true; + } sptr = sptr->_base; } @@ -1274,8 +1310,9 @@ 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) + if (sptr->_base) { _ml_call_reversed(sptr->_base, p_method, p_args, p_argcount); + } Callable::CallError ce; @@ -1316,17 +1353,20 @@ String GDScriptInstance::to_string(bool *r_valid) { Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK) { if (ret.get_type() != Variant::STRING) { - if (r_valid) + if (r_valid) { *r_valid = false; + } ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret.operator String(); } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } @@ -1477,11 +1517,13 @@ void GDScriptLanguage::init() { for (List<StringName>::Element *E = class_list.front(); E; E = E->next()) { StringName n = E->get(); String s = String(n); - if (s.begins_with("_")) + if (s.begins_with("_")) { n = s.substr(1, s.length()); + } - if (globals.has(n)) + if (globals.has(n)) { continue; + } Ref<GDScriptNativeClass> nc = memnew(GDScriptNativeClass(E->get())); _add_global(n, nc); } @@ -1549,8 +1591,9 @@ int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, SelfList<GDScriptFunction> *elem = function_list.first(); while (elem) { - if (current >= p_info_max) + if (current >= p_info_max) { break; + } p_info_arr[current].call_count = elem->self()->profile.call_count; p_info_arr[current].self_time = elem->self()->profile.self_time; p_info_arr[current].total_time = elem->self()->profile.total_time; @@ -1571,8 +1614,9 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_ SelfList<GDScriptFunction> *elem = function_list.first(); while (elem) { - if (current >= p_info_max) + if (current >= p_info_max) { break; + } if (elem->self()->profile.last_frame_call_count > 0) { p_info_arr[current].call_count = elem->self()->profile.last_frame_call_count; p_info_arr[current].self_time = elem->self()->profile.last_frame_self_time; @@ -1590,8 +1634,9 @@ 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) + if (A == B) { return false; //shouldn't happen but.. + } const GDScript *I = B->get_base().ptr(); while (I) { if (I == A.ptr()) { @@ -1662,8 +1707,9 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so 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) + if (!reload) { continue; + } to_reload.insert(E->get(), Map<ObjectID, List<Pair<StringName, Variant>>>()); @@ -1717,8 +1763,9 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so List<Pair<StringName, Variant>> &saved_state = F->get(); Object *obj = ObjectDB::get_instance(F->key()); - if (!obj) + if (!obj) { continue; + } if (!p_soft_reload) { //clear it just in case (may be a pending reload state) @@ -1872,10 +1919,11 @@ String GDScriptLanguage::get_global_class_name(const String &p_path, String *r_b 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()) + if (c->icon_path.empty() || c->icon_path.is_abs_path()) { *r_icon_path = c->icon_path; - else if (c->icon_path.is_rel_path()) + } else if (c->icon_path.is_rel_path()) { *r_icon_path = p_path.get_base_dir().plus_file(c->icon_path).simplify_path(); + } } if (r_base_type) { const GDScriptParser::ClassNode *subclass = c; @@ -2175,21 +2223,24 @@ void GDScriptLanguage::add_orphan_subclass(const String &p_qualified_name, const Ref<GDScript> GDScriptLanguage::get_orphan_subclass(const String &p_qualified_name) { Map<String, ObjectID>::Element *orphan_subclass_element = orphan_subclasses.find(p_qualified_name); - if (!orphan_subclass_element) + if (!orphan_subclass_element) { return Ref<GDScript>(); + } ObjectID orphan_subclass = orphan_subclass_element->get(); Object *obj = ObjectDB::get_instance(orphan_subclass); orphan_subclasses.erase(orphan_subclass_element); - if (!obj) + if (!obj) { return Ref<GDScript>(); + } return Ref<GDScript>(Object::cast_to<GDScript>(obj)); } /*************** 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) + if (r_error) { *r_error = ERR_FILE_CANT_OPEN; + } GDScript *script = memnew(GDScript); @@ -2210,8 +2261,9 @@ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_ori script->reload(); } - if (r_error) + if (r_error) { *r_error = OK; + } return scriptres; } @@ -2228,8 +2280,9 @@ bool ResourceFormatLoaderGDScript::handles_type(const String &p_type) const { 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") + if (el == "gd" || el == "gdc" || el == "gde") { return "GDScript"; + } return ""; } diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index ecaa2257ca..e770dc3abd 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -209,11 +209,11 @@ public: virtual int get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED - if (member_lines.has(p_member)) + if (member_lines.has(p_member)) { return member_lines[p_member]; - else + } #endif - return -1; + return -1; } virtual void get_constants(Map<StringName, Variant> *p_constants); @@ -396,11 +396,13 @@ 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()) + if (Thread::get_main_id() != Thread::get_caller_id()) { return; //no support for other threads than main for now + } - if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) { EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1); + } if (_debug_call_stack_pos >= _debug_max_call_stack) { //stack overflow @@ -418,11 +420,13 @@ public: } _FORCE_INLINE_ void exit_function() { - if (Thread::get_main_id() != Thread::get_caller_id()) + if (Thread::get_main_id() != Thread::get_caller_id()) { return; //no support for other threads than main for now + } - if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) { 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)"; @@ -434,8 +438,9 @@ public: } virtual Vector<StackInfo> debug_get_current_stack_info() { - if (Thread::get_main_id() != Thread::get_caller_id()) + if (Thread::get_main_id() != Thread::get_caller_id()) { return Vector<StackInfo>(); + } Vector<StackInfo> csi; csi.resize(_debug_call_stack_pos); diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index deb725ea81..bc095ae1f9 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -33,11 +33,13 @@ #include "gdscript.h" bool GDScriptCompiler::_is_class_member_property(CodeGen &codegen, const StringName &p_name) { - if (codegen.function_node && codegen.function_node->_static) + if (codegen.function_node && codegen.function_node->_static) { return false; + } - if (codegen.stack_identifiers.has(p_name)) + if (codegen.stack_identifiers.has(p_name)) { return false; //shadowed + } return _is_class_member_property(codegen.script, p_name); } @@ -46,8 +48,9 @@ bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringNa GDScript *scr = owner; GDScriptNativeClass *nc = nullptr; while (scr) { - if (scr->native.is_valid()) + if (scr->native.is_valid()) { nc = scr->native.ptr(); + } scr = scr->_base; } @@ -57,8 +60,9 @@ 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 != "") + if (error != "") { return; + } error = p_error; if (p_node) { @@ -74,8 +78,9 @@ bool GDScriptCompiler::_create_unary_operator(CodeGen &codegen, const GDScriptPa ERR_FAIL_COND_V(on->arguments.size() != 1, false); int src_address_a = _parse_expression(codegen, on->arguments[0], p_stack_level); - if (src_address_a < 0) + if (src_address_a < 0) { return false; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_OPERATOR); // perform operator codegen.opcodes.push_back(op); //which operator @@ -89,14 +94,17 @@ bool GDScriptCompiler::_create_binary_operator(CodeGen &codegen, const GDScriptP 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); - if (src_address_a < 0) + if (src_address_a < 0) { return false; - if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) + } + if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { p_stack_level++; //uses stack for return, increase stack + } int src_address_b = _parse_expression(codegen, on->arguments[1], p_stack_level, false, p_initializer); - if (src_address_b < 0) + if (src_address_b < 0) { return false; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_OPERATOR); // perform operator codegen.opcodes.push_back(op); //which operator @@ -214,8 +222,9 @@ int GDScriptCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDS return _parse_expression(codegen, p_expression->arguments[1], p_stack_level, false, initializer); } - if (!_create_binary_operator(codegen, p_expression, var_op, p_stack_level, initializer, p_index_addr)) + if (!_create_binary_operator(codegen, p_expression, var_op, p_stack_level, initializer, p_index_addr)) { return -1; + } int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode @@ -276,8 +285,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int idx = codegen.get_name_map_pos(identifier); return idx | (GDScriptFunction::ADDR_TYPE_CLASS_CONSTANT << GDScriptFunction::ADDR_BITS); //argument (stack root) } - if (scr->native.is_valid()) + if (scr->native.is_valid()) { nc = scr->native.ptr(); + } scr = scr->_base; } @@ -394,8 +404,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: for (int i = 0; i < an->elements.size(); i++) { int ret = _parse_expression(codegen, an->elements[i], slevel); - if (ret < 0) + if (ret < 0) { return ret; + } if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) { slevel++; codegen.alloc_stack(slevel); @@ -406,8 +417,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.push_back(GDScriptFunction::OPCODE_CONSTRUCT_ARRAY); codegen.opcodes.push_back(values.size()); - for (int i = 0; i < values.size(); i++) + for (int i = 0; i < values.size(); i++) { codegen.opcodes.push_back(values[i]); + } int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode @@ -423,8 +435,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: for (int i = 0; i < dn->elements.size(); i++) { int ret = _parse_expression(codegen, dn->elements[i].key, slevel); - if (ret < 0) + if (ret < 0) { return ret; + } if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) { slevel++; codegen.alloc_stack(slevel); @@ -433,8 +446,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: values.push_back(ret); ret = _parse_expression(codegen, dn->elements[i].value, slevel); - if (ret < 0) + if (ret < 0) { return ret; + } if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) { slevel++; codegen.alloc_stack(slevel); @@ -445,8 +459,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.push_back(GDScriptFunction::OPCODE_CONSTRUCT_DICTIONARY); codegen.opcodes.push_back(dn->elements.size()); - for (int i = 0; i < values.size(); i++) + for (int i = 0; i < values.size(); i++) { codegen.opcodes.push_back(values[i]); + } int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode @@ -459,8 +474,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int slevel = p_stack_level; int src_addr = _parse_expression(codegen, cn->source_node, slevel); - if (src_addr < 0) + if (src_addr < 0) { return src_addr; + } if (src_addr & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); @@ -522,8 +538,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: 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) + if (ret < 0) { return ret; + } if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) { slevel++; codegen.alloc_stack(slevel); @@ -537,8 +554,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.push_back(codegen.get_name_map_pos(in->name)); //instance codegen.opcodes.push_back(arguments.size()); //argument count codegen.alloc_call(arguments.size()); - for (int i = 0; i < arguments.size(); i++) + for (int i = 0; i < arguments.size(); i++) { codegen.opcodes.push_back(arguments[i]); //arguments + } } break; case GDScriptParser::OperatorNode::OP_CALL: { @@ -553,8 +571,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: 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) + if (ret < 0) { return ret; + } if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) { slevel++; codegen.alloc_stack(slevel); @@ -567,8 +586,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.push_back(vtype); //instance codegen.opcodes.push_back(arguments.size()); //argument count codegen.alloc_call(arguments.size()); - for (int i = 0; i < arguments.size(); i++) + for (int i = 0; i < arguments.size(); i++) { codegen.opcodes.push_back(arguments[i]); //arguments + } } else if (on->arguments[0]->type == GDScriptParser::Node::TYPE_BUILT_IN_FUNCTION) { //built in function @@ -579,8 +599,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: 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) + if (ret < 0) { return ret; + } if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) { slevel++; @@ -594,8 +615,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.push_back(static_cast<const GDScriptParser::BuiltInFunctionNode *>(on->arguments[0])->function); codegen.opcodes.push_back(on->arguments.size() - 1); codegen.alloc_call(on->arguments.size() - 1); - for (int i = 0; i < arguments.size(); i++) + for (int i = 0; i < arguments.size(); i++) { codegen.opcodes.push_back(arguments[i]); + } } else { //regular function @@ -626,8 +648,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } else { ret = _parse_expression(codegen, on->arguments[i], slevel); - if (ret < 0) + if (ret < 0) { return ret; + } if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) { slevel++; codegen.alloc_stack(slevel); @@ -639,8 +662,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.push_back(p_root ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN); // perform operator codegen.opcodes.push_back(on->arguments.size() - 2); codegen.alloc_call(on->arguments.size() - 2); - for (int i = 0; i < arguments.size(); i++) + for (int i = 0; i < arguments.size(); i++) { codegen.opcodes.push_back(arguments[i]); + } } } break; case GDScriptParser::OperatorNode::OP_YIELD: { @@ -650,8 +674,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: 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) + if (ret < 0) { return ret; + } if ((ret >> GDScriptFunction::ADDR_BITS & GDScriptFunction::ADDR_TYPE_STACK) == GDScriptFunction::ADDR_TYPE_STACK) { slevel++; codegen.alloc_stack(slevel); @@ -661,8 +686,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: //push call bytecode codegen.opcodes.push_back(arguments.size() == 0 ? GDScriptFunction::OPCODE_YIELD : GDScriptFunction::OPCODE_YIELD_SIGNAL); // basic type constructor - for (int i = 0; i < arguments.size(); i++) + for (int i = 0; i < arguments.size(); i++) { codegen.opcodes.push_back(arguments[i]); //arguments + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_YIELD_RESUME); //next will be where to place the result :) @@ -677,8 +703,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: bool named = (on->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED); int from = _parse_expression(codegen, on->arguments[0], slevel); - if (from < 0) + if (from < 0) { return from; + } int index; if (p_index_addr != 0) { @@ -719,8 +746,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } index = _parse_expression(codegen, on->arguments[1], slevel); - if (index < 0) + if (index < 0) { return index; + } } } @@ -733,16 +761,18 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: // AND operator with early out on failure int res = _parse_expression(codegen, on->arguments[0], p_stack_level); - if (res < 0) + if (res < 0) { return res; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(res); int jump_fail_pos = codegen.opcodes.size(); codegen.opcodes.push_back(0); res = _parse_expression(codegen, on->arguments[1], p_stack_level); - if (res < 0) + if (res < 0) { return res; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(res); @@ -765,16 +795,18 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: // OR operator with early out on success int res = _parse_expression(codegen, on->arguments[0], p_stack_level); - if (res < 0) + if (res < 0) { return res; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF); codegen.opcodes.push_back(res); int jump_success_pos = codegen.opcodes.size(); codegen.opcodes.push_back(0); res = _parse_expression(codegen, on->arguments[1], p_stack_level); - if (res < 0) + if (res < 0) { return res; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF); codegen.opcodes.push_back(res); @@ -798,16 +830,18 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: // x IF a ELSE y operator with early out on failure int res = _parse_expression(codegen, on->arguments[0], p_stack_level); - if (res < 0) + if (res < 0) { return res; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(res); int jump_fail_pos = codegen.opcodes.size(); codegen.opcodes.push_back(0); res = _parse_expression(codegen, on->arguments[1], p_stack_level); - if (res < 0) + if (res < 0) { return res; + } codegen.alloc_stack(p_stack_level); //it will be used.. codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN); @@ -819,8 +853,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: codegen.opcodes.write[jump_fail_pos] = codegen.opcodes.size(); res = _parse_expression(codegen, on->arguments[2], p_stack_level); - if (res < 0) + if (res < 0) { return res; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN); codegen.opcodes.push_back(p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); @@ -833,92 +868,113 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } break; //unary operators case GDScriptParser::OperatorNode::OP_NEG: { - if (!_create_unary_operator(codegen, on, Variant::OP_NEGATE, p_stack_level)) + if (!_create_unary_operator(codegen, on, Variant::OP_NEGATE, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_POS: { - if (!_create_unary_operator(codegen, on, Variant::OP_POSITIVE, p_stack_level)) + if (!_create_unary_operator(codegen, on, Variant::OP_POSITIVE, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_NOT: { - if (!_create_unary_operator(codegen, on, Variant::OP_NOT, p_stack_level)) + if (!_create_unary_operator(codegen, on, Variant::OP_NOT, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_BIT_INVERT: { - if (!_create_unary_operator(codegen, on, Variant::OP_BIT_NEGATE, p_stack_level)) + if (!_create_unary_operator(codegen, on, Variant::OP_BIT_NEGATE, p_stack_level)) { return -1; + } } break; //binary operators (in precedence order) case GDScriptParser::OperatorNode::OP_IN: { - if (!_create_binary_operator(codegen, on, Variant::OP_IN, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_IN, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_EQUAL: { - if (!_create_binary_operator(codegen, on, Variant::OP_EQUAL, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_EQUAL, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_NOT_EQUAL: { - if (!_create_binary_operator(codegen, on, Variant::OP_NOT_EQUAL, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_NOT_EQUAL, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_LESS: { - if (!_create_binary_operator(codegen, on, Variant::OP_LESS, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_LESS, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_LESS_EQUAL: { - if (!_create_binary_operator(codegen, on, Variant::OP_LESS_EQUAL, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_LESS_EQUAL, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_GREATER: { - if (!_create_binary_operator(codegen, on, Variant::OP_GREATER, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_GREATER, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_GREATER_EQUAL: { - if (!_create_binary_operator(codegen, on, Variant::OP_GREATER_EQUAL, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_GREATER_EQUAL, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_ADD: { - if (!_create_binary_operator(codegen, on, Variant::OP_ADD, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_ADD, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_SUB: { - if (!_create_binary_operator(codegen, on, Variant::OP_SUBTRACT, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_SUBTRACT, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_MUL: { - if (!_create_binary_operator(codegen, on, Variant::OP_MULTIPLY, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_MULTIPLY, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_DIV: { - if (!_create_binary_operator(codegen, on, Variant::OP_DIVIDE, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_DIVIDE, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_MOD: { - if (!_create_binary_operator(codegen, on, Variant::OP_MODULE, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_MODULE, p_stack_level)) { return -1; + } } break; //case GDScriptParser::OperatorNode::OP_SHIFT_LEFT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_LEFT,p_stack_level)) return -1;} break; //case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_RIGHT,p_stack_level)) return -1;} break; case GDScriptParser::OperatorNode::OP_BIT_AND: { - if (!_create_binary_operator(codegen, on, Variant::OP_BIT_AND, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_BIT_AND, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_BIT_OR: { - if (!_create_binary_operator(codegen, on, Variant::OP_BIT_OR, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_BIT_OR, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_BIT_XOR: { - if (!_create_binary_operator(codegen, on, Variant::OP_BIT_XOR, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_BIT_XOR, p_stack_level)) { return -1; + } } break; //shift case GDScriptParser::OperatorNode::OP_SHIFT_LEFT: { - if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_LEFT, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_LEFT, p_stack_level)) { return -1; + } } break; case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT: { - if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_RIGHT, p_stack_level)) + if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_RIGHT, p_stack_level)) { return -1; + } } break; //assignment operators case GDScriptParser::OperatorNode::OP_ASSIGN_ADD: @@ -978,8 +1034,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: break; } n = static_cast<GDScriptParser::OperatorNode *>(n->arguments[0]); - if (n->op != GDScriptParser::OperatorNode::OP_INDEX && n->op != GDScriptParser::OperatorNode::OP_INDEX_NAMED) + if (n->op != GDScriptParser::OperatorNode::OP_INDEX && n->op != GDScriptParser::OperatorNode::OP_INDEX_NAMED) { break; + } } } @@ -987,8 +1044,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: //get at (potential) root stack pos, so it can be returned int prev_pos = _parse_expression(codegen, chain.back()->get()->arguments[0], slevel); - if (prev_pos < 0) + if (prev_pos < 0) { return prev_pos; + } int retval = prev_pos; if (retval & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { @@ -1008,8 +1066,9 @@ 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 + if (E == chain.front()) { //ignore first break; + } bool named = E->get()->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED; int key_idx; @@ -1031,8 +1090,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: //stack was raised here if retval was stack but.. } - if (key_idx < 0) //error + if (key_idx < 0) { //error return key_idx; + } codegen.opcodes.push_back(named ? GDScriptFunction::OPCODE_GET_NAMED : GDScriptFunction::OPCODE_GET); codegen.opcodes.push_back(prev_pos); @@ -1066,8 +1126,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: named = false; } - if (set_index < 0) //error + if (set_index < 0) { //error return set_index; + } if (set_index & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; @@ -1075,8 +1136,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } int set_value = _parse_assign_right_expression(codegen, on, slevel + 1, named ? 0 : set_index); - if (set_value < 0) //error + if (set_value < 0) { //error return set_value; + } codegen.opcodes.push_back(named ? GDScriptFunction::OPCODE_SET_NAMED : GDScriptFunction::OPCODE_SET); codegen.opcodes.push_back(prev_pos); @@ -1095,8 +1157,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int slevel = p_stack_level; int src_address = _parse_assign_right_expression(codegen, on, slevel); - if (src_address < 0) + if (src_address < 0) { return -1; + } StringName name = static_cast<GDScriptParser::IdentifierNode *>(on->arguments[0])->name; @@ -1111,8 +1174,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int slevel = p_stack_level; int dst_address_a = _parse_expression(codegen, on->arguments[0], slevel, false, on->op == GDScriptParser::OperatorNode::OP_INIT_ASSIGN); - if (dst_address_a < 0) + if (dst_address_a < 0) { return -1; + } if (dst_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; @@ -1120,8 +1184,9 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: } int src_address_b = _parse_assign_right_expression(codegen, on, slevel); - if (src_address_b < 0) + if (src_address_b < 0) { return -1; + } GDScriptDataType assign_type = _gdtype_from_datatype(on->arguments[0]->get_datatype()); @@ -1183,15 +1248,18 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int slevel = p_stack_level; int src_address_a = _parse_expression(codegen, on->arguments[0], slevel); - if (src_address_a < 0) + if (src_address_a < 0) { return -1; + } - if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) + if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; //uses stack for return, increase stack + } int src_address_b = _parse_expression(codegen, on->arguments[1], slevel); - if (src_address_b < 0) + if (src_address_b < 0) { return -1; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_EXTENDS_TEST); // perform operator codegen.opcodes.push_back(src_address_a); // argument 1 @@ -1205,11 +1273,13 @@ int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser:: int slevel = p_stack_level; int src_address_a = _parse_expression(codegen, on->arguments[0], slevel); - if (src_address_a < 0) + if (src_address_a < 0) { return -1; + } - if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) + if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; //uses stack for return, increase stack + } const GDScriptParser::TypeNode *tn = static_cast<const GDScriptParser::TypeNode *>(on->arguments[1]); @@ -1332,8 +1402,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo case GDScriptParser::ControlFlowNode::CF_IF: { int ret2 = _parse_expression(codegen, cf->arguments[0], p_stack_level, false); - if (ret2 < 0) + if (ret2 < 0) { return ERR_PARSE_ERROR; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(ret2); @@ -1341,8 +1412,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo codegen.opcodes.push_back(0); //temporary Error err = _parse_block(codegen, cf->body, p_stack_level, p_break_addr, p_continue_addr); - if (err) + if (err) { return err; + } if (cf->body_else) { codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); @@ -1351,8 +1423,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo codegen.opcodes.write[else_addr] = codegen.opcodes.size(); Error err2 = _parse_block(codegen, cf->body_else, p_stack_level, p_break_addr, p_continue_addr); - if (err2) + if (err2) { return err2; + } codegen.opcodes.write[end_addr] = codegen.opcodes.size(); } else { @@ -1373,8 +1446,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo codegen.add_stack_identifier(static_cast<const GDScriptParser::IdentifierNode *>(cf->arguments[0])->name, iter_stack_pos); int ret2 = _parse_expression(codegen, cf->arguments[1], slevel, false); - if (ret2 < 0) + if (ret2 < 0) { return ERR_COMPILATION_FAILED; + } //assign container codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN); @@ -1402,8 +1476,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo codegen.opcodes.push_back(iterator_pos); Error err = _parse_block(codegen, cf->body, slevel, break_pos, continue_pos); - if (err) + if (err) { return err; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(continue_pos); @@ -1421,14 +1496,16 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo int continue_addr = codegen.opcodes.size(); int ret2 = _parse_expression(codegen, cf->arguments[0], p_stack_level, false); - if (ret2 < 0) + if (ret2 < 0) { return ERR_PARSE_ERROR; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(ret2); codegen.opcodes.push_back(break_addr); Error err = _parse_block(codegen, cf->body, p_stack_level, break_addr, continue_addr); - if (err) + if (err) { return err; + } codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(continue_addr); @@ -1459,8 +1536,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo if (cf->arguments.size()) { ret2 = _parse_expression(codegen, cf->arguments[0], p_stack_level, false); - if (ret2 < 0) + if (ret2 < 0) { return ERR_PARSE_ERROR; + } } else { ret2 = GDScriptFunction::ADDR_TYPE_NIL << GDScriptFunction::ADDR_BITS; @@ -1479,14 +1557,16 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo const GDScriptParser::AssertNode *as = static_cast<const GDScriptParser::AssertNode *>(s); int ret2 = _parse_expression(codegen, as->condition, p_stack_level, false); - if (ret2 < 0) + if (ret2 < 0) { return ERR_PARSE_ERROR; + } int message_ret = 0; if (as->message) { message_ret = _parse_expression(codegen, as->message, p_stack_level + 1, false); - if (message_ret < 0) + if (message_ret < 0) { return ERR_PARSE_ERROR; + } } codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSERT); @@ -1518,8 +1598,9 @@ Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::Blo default: { //expression int ret2 = _parse_expression(codegen, s, p_stack_level, true); - if (ret2 < 0) + if (ret2 < 0) { return ERR_PARSE_ERROR; + } } break; } } @@ -1575,8 +1656,9 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser codegen.opcodes.push_back((GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) | 0); } Error err = _parse_block(codegen, p_class->initializer, stack_level); - if (err) + if (err) { return err; + } is_initializer = true; } @@ -1584,8 +1666,9 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser //parse initializer for class members if (p_class->ready->statements.size()) { Error err = _parse_block(codegen, p_class->ready, stack_level); - if (err) + if (err) { return err; + } } } @@ -1607,15 +1690,17 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser } Error err = _parse_block(codegen, p_func->body, stack_level); - if (err) + if (err) { return err; + } func_name = p_func->name; } else { - if (p_for_ready) + if (p_for_ready) { func_name = "_ready"; - else + } else { func_name = "_init"; + } } codegen.opcodes.push_back(GDScriptFunction::OPCODE_END); @@ -1716,8 +1801,9 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser if (EngineDebugger::is_active()) { String signature; //path - if (p_script->get_path() != String()) + if (p_script->get_path() != String()) { signature += p_script->get_path(); + } //loc if (p_func) { signature += "::" + itos(p_func->body->line); @@ -1757,11 +1843,13 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser gdfunc->_initial_line = 0; } - if (codegen.debug_stack) + if (codegen.debug_stack) { gdfunc->stack_debug = codegen.stack_debug; + } - if (is_initializer) + if (is_initializer) { p_script->initializer = gdfunc; + } return OK; } @@ -1931,8 +2019,9 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, const GDScriptPar // Subclass might still be parsing, just skip it if (!parsed_classes.has(subclass_ptr) && !parsing_classes.has(subclass_ptr)) { Error err = _parse_class_level(subclass_ptr, p_class->subclasses[i], p_keep_state); - if (err) + if (err) { return err; + } } #ifdef TOOLS_ENABLED @@ -1953,35 +2042,41 @@ 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") + if (!has_initializer && p_class->functions[i]->name == "_init") { has_initializer = true; - if (!has_ready && p_class->functions[i]->name == "_ready") + } + if (!has_ready && p_class->functions[i]->name == "_ready") { has_ready = true; + } Error err = _parse_function(p_script, p_class, p_class->functions[i]); - if (err) + if (err) { return err; + } } //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) + if (err) { return err; + } } if (!has_initializer) { //create a constructor Error err = _parse_function(p_script, p_class, nullptr); - if (err) + if (err) { return err; + } } if (!has_ready && p_class->ready->statements.size()) { //create a constructor Error err = _parse_function(p_script, p_class, nullptr, true); - if (err) + if (err) { return err; + } } #ifdef DEBUG_ENABLED @@ -2101,13 +2196,15 @@ Error GDScriptCompiler::compile(const GDScriptParser *p_parser, GDScript *p_scri p_script->_owner = nullptr; Error err = _parse_class_level(p_script, static_cast<const GDScriptParser::ClassNode *>(root), p_keep_state); - if (err) + if (err) { return err; + } err = _parse_class_blocks(p_script, static_cast<const GDScriptParser::ClassNode *>(root), p_keep_state); - if (err) + if (err) { return err; + } return OK; } diff --git a/modules/gdscript/gdscript_compiler.h b/modules/gdscript/gdscript_compiler.h index 3a362c75bc..315d4f1842 100644 --- a/modules/gdscript/gdscript_compiler.h +++ b/modules/gdscript/gdscript_compiler.h @@ -110,8 +110,9 @@ class GDScriptCompiler { } int get_constant_pos(const Variant &p_constant) { - if (constant_map.has(p_constant)) + if (constant_map.has(p_constant)) { return constant_map[p_constant]; + } int pos = constant_map.size(); constant_map[p_constant] = pos; return pos; @@ -119,12 +120,14 @@ class GDScriptCompiler { Vector<int> opcodes; void alloc_stack(int p_level) { - if (p_level >= stack_max) + if (p_level >= stack_max) { stack_max = p_level + 1; + } } void alloc_call(int p_params) { - if (p_params >= call_max) + if (p_params >= call_max) { call_max = p_params; + } } int current_line; diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 8aa7809347..7433c4a5bc 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -232,15 +232,17 @@ String GDScriptLanguage::debug_get_error() const { } int GDScriptLanguage::debug_get_stack_level_count() const { - if (_debug_parse_err_line >= 0) + 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) + if (_debug_parse_err_line >= 0) { return _debug_parse_err_line; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1); @@ -250,8 +252,9 @@ int GDScriptLanguage::debug_get_stack_level_line(int p_level) const { } String GDScriptLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return ""; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, ""); int l = _debug_call_stack_pos - p_level - 1; @@ -259,8 +262,9 @@ String GDScriptLanguage::debug_get_stack_level_function(int p_level) const { } String GDScriptLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return _debug_parse_err_file; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, ""); int l = _debug_call_stack_pos - p_level - 1; @@ -268,8 +272,9 @@ String GDScriptLanguage::debug_get_stack_level_source(int p_level) const { } 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) + if (_debug_parse_err_line >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); int l = _debug_call_stack_pos - p_level - 1; @@ -286,16 +291,18 @@ void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p } 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) + if (_debug_parse_err_line >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); int l = _debug_call_stack_pos - p_level - 1; GDScriptInstance *instance = _call_stack[l].instance; - if (!instance) + if (!instance) { return; + } Ref<GDScript> script = instance->get_script(); ERR_FAIL_COND(script.is_null()); @@ -309,8 +316,9 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> * } ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return nullptr; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, nullptr); @@ -328,8 +336,9 @@ 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())) + if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key())) { continue; + } bool is_script_constant = false; for (List<Pair<String, Variant>>::Element *CE = cinfo.front(); CE; CE = CE->next()) { @@ -338,13 +347,15 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> break; } } - if (is_script_constant) + if (is_script_constant) { continue; + } const Variant &var = globals[E->value()]; if (Object *obj = var) { - if (Object::cast_to<GDScriptNativeClass>(obj)) + if (Object::cast_to<GDScriptNativeClass>(obj)) { continue; + } } bool skip = false; @@ -354,8 +365,9 @@ void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> break; } } - if (skip) + if (skip) { continue; + } p_globals->push_back(E->key()); p_values->push_back(var); @@ -436,8 +448,9 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na String s = "func " + p_name + "("; if (p_args.size()) { for (int i = 0; i < p_args.size(); i++) { - if (i > 0) + if (i > 0) { s += ", "; + } s += p_args[i].get_slice(":", 0); if (th) { String type = p_args[i].get_slice(":", 1); @@ -2994,8 +3007,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t } String st = l.substr(tc, l.length()).strip_edges(); - if (st == "" || st.begins_with("#")) + if (st == "" || st.begins_with("#")) { continue; //ignore! + } int ilevel = 0; if (indent_stack.size()) { @@ -3009,8 +3023,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t indent_stack.pop_back(); } - if (indent_stack.size() && indent_stack.back()->get() != tc) + if (indent_stack.size() && indent_stack.back()->get() != tc) { indent_stack.push_back(tc); //this is not right but gets the job done + } } if (i >= p_from_line) { @@ -3029,8 +3044,9 @@ void GDScriptLanguage::auto_indent_code(String &p_code, int p_from_line, int p_t p_code = ""; for (int i = 0; i < lines.size(); i++) { - if (i > 0) + if (i > 0) { p_code += "\n"; + } p_code += lines[i]; } } @@ -3349,8 +3365,9 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { String s = E->get().name; - if (!s.begins_with("autoload/")) + if (!s.begins_with("autoload/")) { continue; + } String name = s.get_slice("/", 1); if (name == String(p_symbol)) { String path = ProjectSettings::get_singleton()->get(s); diff --git a/modules/gdscript/gdscript_function.cpp b/modules/gdscript/gdscript_function.cpp index aa2ea149f5..92e07ab874 100644 --- a/modules/gdscript/gdscript_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -140,10 +140,11 @@ static String _get_var_type(const Variant *p_var) { basestr = "previously freed"; } } else { - if (bobj->get_script_instance()) + if (bobj->get_script_instance()) { basestr = bobj->get_class() + " (" + bobj->get_script_instance()->get_script()->get_path().get_file() + ")"; - else + } else { basestr = bobj->get_class(); + } } } else { @@ -366,8 +367,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #ifdef DEBUG_ENABLED - if (EngineDebugger::is_active()) + if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->enter_function(p_instance, this, stack, &ip, &line); + } #define GD_ERR_BREAK(m_cond) \ { \ @@ -1149,8 +1151,9 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a while (gds->base.ptr()) { gds = gds->base.ptr(); E = gds->member_functions.find(*methodname); - if (E) + if (E) { break; + } } Callable::CallError err; @@ -1466,14 +1469,17 @@ 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) + 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) + } + if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) { do_break = true; + } } - if (EngineDebugger::get_script_debugger()->is_breakpoint(line, source)) + if (EngineDebugger::get_script_debugger()->is_breakpoint(line, source)) { do_break = true; + } if (do_break) { GDScriptLanguage::get_singleton()->debug_break("Breakpoint", true); @@ -1501,20 +1507,24 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODES_END #ifdef DEBUG_ENABLED - if (exit_ok) + if (exit_ok) { OPCODE_OUT; + } //error // function, file, line, error, explanation String err_file; - if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "") + if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->path != "") { err_file = p_instance->script->path; - else if (script) + } else if (script) { err_file = script->path; - if (err_file == "") + } + if (err_file == "") { err_file = "<built-in>"; + } String err_func = name; - if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "") + if (p_instance && ObjectDB::get_instance(p_instance->owner_id) != nullptr && p_instance->script->is_valid() && p_instance->script->name != "") { err_func = p_instance->script->name + "." + err_func; + } int err_line = line; if (err_text == "") { err_text = "Internal Script Error! - opcode #" + itos(last_opcode) + " (report please)."; @@ -1546,14 +1556,16 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a // When it's the last resume it will postpone the exit from stack, // so the debugger knows which function triggered the resume of the next function (if any) if (!p_state || yielded) { - if (EngineDebugger::is_active()) + if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->exit_function(); + } #endif if (_stack_size) { //free stack - for (int i = 0; i < _stack_size; i++) + for (int i = 0; i < _stack_size; i++) { stack[i].~Variant(); + } } #ifdef DEBUG_ENABLED @@ -1627,8 +1639,9 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String 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) + if (sd.line > p_line) { break; + } if (sd.added) { if (!sdmap.has(sd.identifier)) { @@ -1644,8 +1657,9 @@ void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<String ERR_CONTINUE(!sdmap.has(sd.identifier)); sdmap[sd.identifier].pos.pop_back(); - if (sdmap[sd.identifier].pos.empty()) + if (sdmap[sd.identifier].pos.empty()) { sdmap.erase(sd.identifier); + } } } @@ -1740,8 +1754,9 @@ Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_ar } bool GDScriptFunctionState::is_valid(bool p_extended_check) const { - if (function == nullptr) + if (function == nullptr) { return false; + } if (p_extended_check) { MutexLock lock(GDScriptLanguage::get_singleton()->lock); @@ -1812,8 +1827,9 @@ Variant GDScriptFunctionState::resume(const Variant &p_arg) { } #ifdef DEBUG_ENABLED - if (EngineDebugger::is_active()) + if (EngineDebugger::is_active()) { GDScriptLanguage::get_singleton()->exit_function(); + } #endif } @@ -1823,8 +1839,9 @@ 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++) + for (int i = 0; i < state.stack_size; i++) { stack[i].~Variant(); + } state.stack_size = 0; } } diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 490da102c0..583eab744a 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -59,8 +59,9 @@ struct GDScriptDataType { Ref<Script> script_type; bool is_type(const Variant &p_variant, bool p_allow_implicit_conversion = false) const { - if (!has_type) + if (!has_type) { return true; // Can't type check + } switch (kind) { case UNINITIALIZED: diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index 5df2c79df5..d4258c385e 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -672,10 +672,11 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ for (int i = 0; i < p_arg_count; i++) { String os = p_args[i]->operator String(); - if (i == 0) + if (i == 0) { str = os; - else + } else { str += os; + } } r_ret = str; @@ -694,8 +695,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case TEXT_PRINT_TABBED: { String str; for (int i = 0; i < p_arg_count; i++) { - if (i) + if (i) { str += "\t"; + } str += p_args[i]->operator String(); } @@ -706,8 +708,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ case TEXT_PRINT_SPACED: { String str; for (int i = 0; i < p_arg_count; i++) { - if (i) + if (i) { str += " "; + } str += p_args[i]->operator String(); } @@ -936,8 +939,9 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ r_ret = Variant(); return; } - for (int i = from; i < to; i++) + for (int i = from; i < to; i++) { arr[i - from] = i; + } r_ret = arr; } break; case 3: { diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 09f5b13e22..d8f2c16638 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -47,8 +47,9 @@ T *GDScriptParser::alloc_node() { t->next = list; list = t; - if (!head) + if (!head) { head = t; + } t->line = tokenizer->get_token_line(); t->column = tokenizer->get_token_column(); @@ -269,8 +270,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s parenthesis++; Node *subexpr = _parse_expression(p_parent, p_static, p_allow_assign, p_parsing_constant); parenthesis--; - if (!subexpr) + if (!subexpr) { return nullptr; + } if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' in expression"); @@ -463,8 +465,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s return nullptr; } - if (!path.is_abs_path() && base_path != "") + if (!path.is_abs_path() && base_path != "") { path = base_path.plus_file(path); + } path = path.replace("///", "//").simplify_path(); if (path == self_path) { _set_error("Can't preload itself (use 'get_script()')."); @@ -543,8 +546,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s parenthesis++; Node *object = _parse_and_reduce_expression(p_parent, p_static); - if (!object) + if (!object) { return nullptr; + } yield->arguments.push_back(object); if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { @@ -568,8 +572,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } Node *signal = _parse_and_reduce_expression(p_parent, p_static); - if (!signal) + if (!signal) { return nullptr; + } yield->arguments.push_back(signal); if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { @@ -628,8 +633,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s id->name = identifier; op->arguments.push_back(id); - if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) + if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) { return nullptr; + } expr = op; } else { @@ -724,8 +730,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } } if (!replaced) { - if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) + if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) { return nullptr; + } expr = op; } } else if (tokenizer->is_token_literal(0, true)) { @@ -961,8 +968,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s return nullptr; } Node *n = _parse_expression(arr, p_static, p_allow_assign, p_parsing_constant); - if (!n) + if (!n) { return nullptr; + } arr->elements.push_back(n); expecting_comma = true; } @@ -1063,16 +1071,18 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s } else { //python/js style more flexible key = _parse_expression(dict, p_static, p_allow_assign, p_parsing_constant); - if (!key) + if (!key) { return nullptr; + } expecting = DICT_EXPECT_COLON; } } if (expecting == DICT_EXPECT_VALUE) { Node *value = _parse_expression(dict, p_static, p_allow_assign, p_parsing_constant); - if (!value) + if (!value) { return nullptr; + } expecting = DICT_EXPECT_COMMA; if (key->type == GDScriptParser::Node::TYPE_CONSTANT) { @@ -1183,8 +1193,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s _make_completable_call(0); completion_node = op; } - if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) + if (!_parse_arguments(op, op->arguments, p_static, true, p_parsing_constant)) { return nullptr; + } expr = op; } else { @@ -1235,8 +1246,9 @@ GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_s tokenizer->advance(1); expr = op; - } else + } else { break; + } } /*****************/ @@ -1720,8 +1732,9 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to 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) + if (an->elements[i]->type != Node::TYPE_CONSTANT) { all_constants = false; + } } if (all_constants && p_to_const) { @@ -1748,11 +1761,13 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to 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) + if (dn->elements[i].key->type != Node::TYPE_CONSTANT) { all_constants = false; + } dn->elements.write[i].value = _reduce_expression(dn->elements[i].value, p_to_const); - if (dn->elements[i].value->type != Node::TYPE_CONSTANT) + if (dn->elements[i].value->type != Node::TYPE_CONSTANT) { all_constants = false; + } } if (all_constants && p_to_const) { @@ -1952,8 +1967,9 @@ GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to } } //now se if all are constants - if (!all_constants) + if (!all_constants) { return op; //nothing to reduce from here on + } #define _REDUCE_UNARY(m_vop) \ bool valid = false; \ Variant res; \ @@ -2075,11 +2091,13 @@ 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) + if (!expr || error_set) { return nullptr; + } expr = _reduce_expression(expr, p_reduce_const); - if (!expr || error_set) + if (!expr || error_set) { return nullptr; + } return expr; } @@ -2087,8 +2105,9 @@ 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++) { - if (!_reduce_export_var_type(arr[i], p_line)) + if (!_reduce_export_var_type(arr[i], p_line)) { return false; + } } return true; } @@ -2097,8 +2116,9 @@ bool GDScriptParser::_reduce_export_var_type(Variant &p_value, int p_line) { Dictionary dict = p_value; for (int i = 0; i < dict.size(); i++) { Variant value = dict.get_value_at_index(i); - if (!_reduce_export_var_type(value, p_line)) + if (!_reduce_export_var_type(value, p_line)) { return false; + } } return true; } @@ -2137,8 +2157,9 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) { PatternNode *pattern = alloc_node<PatternNode>(); GDScriptTokenizer::Token token = tokenizer->get_token(); - if (error_set) + if (error_set) { return nullptr; + } if (token == GDScriptTokenizer::TK_EOF) { return nullptr; @@ -2333,12 +2354,14 @@ 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()) + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) { ; + } // GDScriptTokenizer::Token token = tokenizer->get_token(); - if (error_set) + if (error_set) { return; + } if (current_level.indent > indent_level.back()->get().indent) { break; // go back a level @@ -2820,8 +2843,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { is_first_line = false; GDScriptTokenizer::Token token = tokenizer->get_token(); - if (error_set) + if (error_set) { return; + } if (current_level.indent > indent_level.back()->get().indent) { p_block->end_line = tokenizer->get_token_line(); @@ -3007,16 +3031,18 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { _parse_block(cf_if->body, p_static); current_block = p_block; - if (error_set) + if (error_set) { return; + } p_block->statements.push_back(cf_if); bool all_have_return = cf_if->body->has_return; bool have_else = false; while (true) { - while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) { ; + } if (indent_level.back()->get().indent < current_level.indent) { //not at current indent level p_block->end_line = tokenizer->get_token_line(); @@ -3064,8 +3090,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { current_block = cf_else->body; _parse_block(cf_else->body, p_static); current_block = p_block; - if (error_set) + if (error_set) { return; + } all_have_return = all_have_return && cf_else->body->has_return; @@ -3088,16 +3115,18 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { current_block = cf_if->body_else; _parse_block(cf_if->body_else, p_static); current_block = p_block; - if (error_set) + if (error_set) { return; + } all_have_return = all_have_return && cf_if->body_else->has_return; have_else = true; break; //after else, exit - } else + } else { break; + } } cf_if->body->has_return = all_have_return; @@ -3133,8 +3162,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { current_block = cf_while->body; _parse_block(cf_while->body, p_static); current_block = p_block; - if (error_set) + if (error_set) { return; + } p_block->has_return = cf_while->body->has_return; p_block->statements.push_back(cf_while); } break; @@ -3271,8 +3301,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { _parse_block(cf_for->body, p_static); current_block = p_block; - if (error_set) + if (error_set) { return; + } p_block->has_return = cf_for->body->has_return; p_block->statements.push_back(cf_for); } break; @@ -3358,8 +3389,9 @@ void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { _parse_pattern_block(compiled_branches, match_node->branches, p_static); - if (error_set) + if (error_set) { return; + } ControlFlowNode *match_cf_node = alloc_node<ControlFlowNode>(); match_cf_node->cf_type = ControlFlowNode::CF_MATCH; @@ -3538,8 +3570,9 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD) { return; - } else + } else { tokenizer->advance(); + } } while (true) { @@ -3576,8 +3609,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { while (true) { GDScriptTokenizer::Token token = tokenizer->get_token(); - if (error_set) + if (error_set) { return; + } if (current_level.indent > indent_level.back()->get().indent) { p_class->end_line = tokenizer->get_token_line(); @@ -3606,8 +3640,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { case GDScriptTokenizer::TK_PR_EXTENDS: { _mark_line_as_safe(tokenizer->get_token_line()); _parse_extends(p_class); - if (error_set) + if (error_set) { return; + } if (!_end_statement()) { _set_end_statement_error("extends"); return; @@ -3754,8 +3789,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_EXTENDS) { _parse_extends(newclass); - if (error_set) + if (error_set) { return; + } } if (!_enter_indent_block()) { @@ -3899,8 +3935,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { defaulting = true; tokenizer->advance(1); Node *defval = _parse_and_reduce_expression(p_class, _static); - if (!defval || error_set) + if (!defval || error_set) { return; + } OperatorNode *on = alloc_node<OperatorNode>(); on->op = OperatorNode::OP_ASSIGN; @@ -4025,10 +4062,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { function->return_type = return_type; - if (_static) + if (_static) { p_class->static_functions.push_back(function); - else + } else { p_class->functions.push_back(function); + } current_function = function; function->body = block; @@ -4160,16 +4198,18 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } String c = tokenizer->get_token_constant(); - if (!first) + if (!first) { current_export.hint_string += ","; - else + } else { first = false; + } current_export.hint_string += c.xml_escape(); _ADVANCE_AND_CONSUME_NEWLINES; - if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { break; + } if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); @@ -4234,16 +4274,18 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } String c = tokenizer->get_token_constant(); - if (!first) + if (!first) { current_export.hint_string += ","; - else + } else { first = false; + } current_export.hint_string += c.xml_escape(); _ADVANCE_AND_CONSUME_NEWLINES; - if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { break; + } if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); @@ -4275,15 +4317,16 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { current_export.hint = PROPERTY_HINT_EXP_RANGE; _ADVANCE_AND_CONSUME_NEWLINES; - if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { break; - else if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { + } else if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { _set_error("Expected \")\" or \",\" in the exponential range hint."); return; } _ADVANCE_AND_CONSUME_NEWLINES; - } else + } else { current_export.hint = PROPERTY_HINT_RANGE; + } float sign = 1.0; @@ -4328,8 +4371,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { current_export.hint_string += "," + rtos(sign * double(tokenizer->get_token_constant())); _ADVANCE_AND_CONSUME_NEWLINES; - if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { break; + } if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); @@ -4367,15 +4411,17 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } String c = tokenizer->get_token_constant(); - if (!first) + if (!first) { current_export.hint_string += ","; - else + } else { first = false; + } current_export.hint_string += c.xml_escape(); _ADVANCE_AND_CONSUME_NEWLINES; - if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { break; + } if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); @@ -4391,9 +4437,9 @@ 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) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { current_export.hint = PROPERTY_HINT_DIR; - else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { _ADVANCE_AND_CONSUME_NEWLINES; if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier() == "GLOBAL")) { @@ -4433,21 +4479,22 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { current_export.hint = PROPERTY_HINT_GLOBAL_FILE; _ADVANCE_AND_CONSUME_NEWLINES; - if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { break; - else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { _ADVANCE_AND_CONSUME_NEWLINES; - else { + } else { _set_error("Expected \")\" or \",\" in the hint."); return; } } if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { - if (current_export.hint == PROPERTY_HINT_GLOBAL_FILE) + if (current_export.hint == PROPERTY_HINT_GLOBAL_FILE) { _set_error("Expected string constant with filter."); - else + } else { _set_error("Expected \"GLOBAL\" or string constant with filter."); + } return; } current_export.hint_string = tokenizer->get_token_constant(); @@ -4559,10 +4606,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { bool first = true; for (List<Variant>::Element *E = keys.front(); E; E = E->next()) { if (enum_values[E->get()].get_type() == Variant::INT) { - if (!first) + if (!first) { current_export.hint_string += ","; - else + } else { first = false; + } current_export.hint_string += E->get().operator String().camelcase_to_underscore(true).capitalize().xml_escape(); if (!is_flags) { @@ -4678,10 +4726,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { //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) { - if (current_export.type) + if (current_export.type) { _set_error("Expected \"var\"."); - else + } else { _set_error("Expected \"var\" or \"func\"."); + } return; } @@ -4692,10 +4741,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { //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) { - if (current_export.type) + if (current_export.type) { _set_error("Expected \"var\"."); - else + } else { _set_error("Expected \"var\" or \"func\"."); + } return; } @@ -4706,10 +4756,11 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { //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) { - if (current_export.type) + if (current_export.type) { _set_error("Expected \"var\"."); - else + } else { _set_error("Expected \"var\" or \"func\"."); + } return; } @@ -4859,8 +4910,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { return; } - if (!_reduce_export_var_type(cn->value, member.line)) + if (!_reduce_export_var_type(cn->value, member.line)) { return; + } member._export.type = cn->value.get_type(); member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; @@ -4906,15 +4958,17 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { #ifdef DEBUG_ENABLED NewLineNode *nl2 = alloc_node<NewLineNode>(); nl2->line = line; - if (onready) + if (onready) { p_class->ready->statements.push_back(nl2); - else + } else { p_class->initializer->statements.push_back(nl2); + } #endif - if (onready) + if (onready) { p_class->ready->statements.push_back(op); - else + } else { p_class->initializer->statements.push_back(op); + } member.initial_assignment = op; @@ -5360,10 +5414,12 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive } } - if (base_class) + if (base_class) { break; - if (found) + } + if (found) { continue; + } if (p->constant_expressions.has(base)) { if (p->constant_expressions[base].expression->type != Node::TYPE_CONSTANT) { @@ -5457,12 +5513,14 @@ void GDScriptParser::_determine_inheritance(ClassNode *p_class, bool p_recursive } String GDScriptParser::DataType::to_string() const { - if (!has_type) + if (!has_type) { return "var"; + } switch (kind) { case BUILTIN: { - if (builtin_type == Variant::NIL) + if (builtin_type == Variant::NIL) { return "null"; + } return Variant::get_type_name(builtin_type); } break; case NATIVE: { @@ -5626,10 +5684,12 @@ bool GDScriptParser::_parse_type(DataType &r_type, bool p_can_be_void) { } GDScriptParser::DataType GDScriptParser::_resolve_type(const DataType &p_source, int p_line) { - if (!p_source.has_type) + if (!p_source.has_type) { return p_source; - if (p_source.kind != DataType::UNRESOLVED) + } + if (p_source.kind != DataType::UNRESOLVED) { return p_source; + } Vector<String> full_name = p_source.native_type.operator String().split(".", false); int name_part = 0; @@ -6861,8 +6921,9 @@ bool GDScriptParser::_get_function_signature(DataType &p_base_type, const String native = "_" + native.operator String(); } if (!ClassDB::class_exists(native)) { - if (!check_types) + if (!check_types) { return false; + } ERR_FAIL_V_MSG(false, "Parser bug: Class '" + String(native) + "' not found."); } @@ -6953,8 +7014,9 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat par_types.write[i - 1] = _reduce_node_type(p_call->arguments[i]); } - if (error_set) + if (error_set) { return DataType(); + } // Special case: check copy constructor. Those are defined implicitly in Variant. if (par_types.size() == 1) { @@ -7022,8 +7084,9 @@ GDScriptParser::DataType GDScriptParser::_reduce_function_call_type(const Operat err += "' matches the signature '"; err += Variant::get_type_name(tn->vtype) + "("; for (int i = 0; i < par_types.size(); i++) { - if (i > 0) + if (i > 0) { err += ", "; + } err += par_types[i].to_string(); } err += ")'."; @@ -7263,8 +7326,9 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN while (base) { if (base->constant_expressions.has(p_member)) { - if (r_is_const) + if (r_is_const) { *r_is_const = true; + } r_member_type = base->constant_expressions[p_member].expression->get_datatype(); return true; } @@ -7383,8 +7447,9 @@ bool GDScriptParser::_get_member_type(const DataType &p_base_type, const StringN native = "_" + native.operator String(); } if (!ClassDB::class_exists(native)) { - if (!check_types) + if (!check_types) { return false; + } ERR_FAIL_V_MSG(false, "Parser bug: Class \"" + String(native) + "\" not found."); } @@ -7680,14 +7745,16 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { // Function declarations for (int i = 0; i < p_class->static_functions.size(); i++) { _check_function_types(p_class->static_functions[i]); - if (error_set) + if (error_set) { return; + } } for (int i = 0; i < p_class->functions.size(); i++) { _check_function_types(p_class->functions[i]); - if (error_set) + if (error_set) { return; + } } // Class variables @@ -7763,8 +7830,9 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { } // Setter and getter - if (v.setter == StringName() && v.getter == StringName()) + if (v.setter == StringName() && v.getter == StringName()) { continue; + } bool found_getter = false; bool found_setter = false; @@ -7807,12 +7875,14 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { return; } } - if (found_getter && found_setter) + if (found_getter && found_setter) { break; + } } - if ((found_getter || v.getter == StringName()) && (found_setter || v.setter == StringName())) + if ((found_getter || v.getter == StringName()) && (found_setter || v.setter == StringName())) { continue; + } // Check for static functions for (int j = 0; j < p_class->static_functions.size(); j++) { @@ -7843,8 +7913,9 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { for (int i = 0; i < p_class->subclasses.size(); i++) { current_class = p_class->subclasses[i]; _check_class_level_types(current_class); - if (error_set) + if (error_set) { return; + } current_class = p_class; } } @@ -7979,8 +8050,9 @@ void GDScriptParser::_check_class_blocks_types(ClassNode *p_class) { _check_block_types(current_block); current_block = nullptr; current_function = nullptr; - if (error_set) + if (error_set) { return; + } } for (int i = 0; i < p_class->functions.size(); i++) { @@ -7990,8 +8062,9 @@ void GDScriptParser::_check_class_blocks_types(ClassNode *p_class) { _check_block_types(current_block); current_block = nullptr; current_function = nullptr; - if (error_set) + if (error_set) { return; + } } #ifdef DEBUG_ENABLED @@ -8012,8 +8085,9 @@ void GDScriptParser::_check_class_blocks_types(ClassNode *p_class) { for (int i = 0; i < p_class->subclasses.size(); i++) { current_class = p_class->subclasses[i]; _check_class_blocks_types(current_class); - if (error_set) + if (error_set) { return; + } current_class = p_class; } } @@ -8280,8 +8354,9 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) { _add_warning(GDScriptWarning::RETURN_VALUE_DISCARDED, op->line, func_name); } #endif // DEBUG_ENABLED - if (error_set) + if (error_set) { return; + } } break; case OperatorNode::OP_YIELD: { _mark_line_as_safe(op->line); @@ -8316,8 +8391,9 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) { } } - if (!function_type.has_type) + if (!function_type.has_type) { break; + } if (function_type.kind == DataType::BUILTIN && function_type.builtin_type == Variant::NIL) { // Return void, should not have arguments @@ -8377,8 +8453,9 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) { current_block = p_block->sub_blocks[i]; _check_block_types(current_block); current_block = p_block; - if (error_set) + if (error_set) { return; + } } #ifdef DEBUG_ENABLED @@ -8397,8 +8474,9 @@ 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) + if (error_set) { return; //allow no further errors + } error = p_error; error_line = p_line < 0 ? tokenizer->get_token_line() : p_line; @@ -8517,8 +8595,9 @@ Error GDScriptParser::_parse(const String &p_base_path) { current_function = nullptr; current_block = nullptr; - if (for_completion) + if (for_completion) { check_types = false; + } // Resolve all class-level stuff before getting into function blocks _check_class_level_types(main_class); diff --git a/modules/gdscript/gdscript_parser.h b/modules/gdscript/gdscript_parser.h index 4332fa7569..cfcca9584e 100644 --- a/modules/gdscript/gdscript_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -641,14 +641,16 @@ private: void _check_block_types(BlockNode *p_block); _FORCE_INLINE_ void _mark_line_as_safe(int p_line) const { #ifdef DEBUG_ENABLED - if (safe_lines) + if (safe_lines) { safe_lines->insert(p_line); + } #endif // DEBUG_ENABLED } _FORCE_INLINE_ void _mark_line_as_unsafe(int p_line) const { #ifdef DEBUG_ENABLED - if (safe_lines) + if (safe_lines) { safe_lines->erase(p_line); + } #endif // DEBUG_ENABLED } diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 9854b8d185..2db42601c6 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -574,8 +574,9 @@ void GDScriptTokenizerText::_advance() { _make_token(TK_OP_EQUAL); INCPOS(1); - } else + } else { _make_token(TK_OP_ASSIGN); + } } break; case '<': { @@ -590,8 +591,9 @@ void GDScriptTokenizerText::_advance() { _make_token(TK_OP_SHIFT_LEFT); } INCPOS(1); - } else + } else { _make_token(TK_OP_LESS); + } } break; case '>': { @@ -741,8 +743,9 @@ void GDScriptTokenizerText::_advance() { [[fallthrough]]; case '\'': case '"': { - if (GETCHAR(0) == '\'') + if (GETCHAR(0) == '\'') { string_mode = STRING_SINGLE_QUOTE; + } int i = 1; if (string_mode == STRING_DOUBLE_QUOTE && GETCHAR(i) == '"' && GETCHAR(i + 1) == '"') { @@ -851,8 +854,9 @@ void GDScriptTokenizerText::_advance() { } break; } - if (next != '\n') + if (next != '\n') { str += res; + } } else { if (CharType(GETCHAR(i)) == '\n') { @@ -933,8 +937,9 @@ void GDScriptTokenizerText::_advance() { } else if (GETCHAR(i) == '_') { i++; continue; // Included for readability, shouldn't be a part of the string - } else + } else { break; + } str += CharType(GETCHAR(i)); i++; @@ -1034,8 +1039,9 @@ void GDScriptTokenizerText::_advance() { } } - if (!found) + if (!found) { identifier = true; + } } if (identifier) { @@ -1073,8 +1079,9 @@ void GDScriptTokenizerText::set_code(const String &p_code) { ignore_warnings = false; #endif // DEBUG_ENABLED last_error = ""; - for (int i = 0; i < MAX_LOOKAHEAD + 1; i++) + for (int i = 0; i < MAX_LOOKAHEAD + 1; i++) { _advance(); + } } GDScriptTokenizerText::Token GDScriptTokenizerText::get_token(int p_offset) const { @@ -1166,8 +1173,9 @@ 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++) + for (int i = 0; i < p_amount; i++) { _advance(); + } } ////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1215,8 +1223,9 @@ Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) int len; // An object cannot be constant, never decode objects Error err = decode_variant(v, b, total_len, &len, false); - if (err) + if (err) { return err; + } b += len; total_len -= len; constants.write[i] = v; @@ -1311,8 +1320,9 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) token_array.push_back(token); - if (tt.get_token() == TK_EOF) + if (tt.get_token() == TK_EOF) { break; + } tt.advance(); } @@ -1352,8 +1362,9 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) CharString cs = String(E->get()).utf8(); int len = cs.length() + 1; int extra = 4 - (len % 4); - if (extra == 4) + if (extra == 4) { extra = 0; + } uint8_t ibuf[4]; encode_uint32(len + extra, ibuf); @@ -1382,8 +1393,9 @@ Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) uint8_t ibuf[8]; encode_uint32(E->key(), &ibuf[0]); encode_uint32(E->get(), &ibuf[4]); - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { buf.push_back(ibuf[i]); + } } for (int i = 0; i < token_array.size(); i++) { @@ -1406,8 +1418,9 @@ 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()) + if (offset < 0 || offset >= tokens.size()) { return TK_EOF; + } return GDScriptTokenizerBuffer::Token(tokens[offset] & TOKEN_MASK); } @@ -1439,10 +1452,12 @@ int GDScriptTokenizerBuffer::get_token_line(int p_offset) const { int offset = token + p_offset; int pos = lines.find_nearest(offset); - if (pos < 0) + if (pos < 0) { return -1; - if (pos >= lines.size()) + } + if (pos >= lines.size()) { pos = lines.size() - 1; + } uint32_t l = lines.getv(pos); return l & TOKEN_LINE_MASK; @@ -1451,10 +1466,12 @@ int GDScriptTokenizerBuffer::get_token_line(int p_offset) const { int GDScriptTokenizerBuffer::get_token_column(int p_offset) const { int offset = token + p_offset; int pos = lines.find_nearest(offset); - if (pos < 0) + if (pos < 0) { return -1; - if (pos >= lines.size()) + } + if (pos >= lines.size()) { pos = lines.size() - 1; + } uint32_t l = lines.getv(pos); return l >> TOKEN_LINE_BITS; diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index 9338dcadbe..f87e8687e5 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -144,8 +144,9 @@ void ExtendGDScriptParser::parse_class_symbol(const GDScriptParser::ClassNode *p r_symbol.script_path = path; r_symbol.children.clear(); r_symbol.name = p_class->name; - if (r_symbol.name.empty()) + if (r_symbol.name.empty()) { r_symbol.name = path.get_file(); + } r_symbol.kind = lsp::SymbolKind::Class; r_symbol.deprecated = false; r_symbol.range.start.line = LINE_NUMBER_TO_INDEX(p_class->line); @@ -378,8 +379,9 @@ 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()) + if (i < 0 || i >= lines.size()) { break; + } String line_comment = lines[i].strip_edges(true, false); if (line_comment.begins_with("#")) { @@ -413,8 +415,9 @@ String ExtendGDScriptParser::get_text_for_completion(const lsp::Position &p_curs longthing += lines[i]; } - if (i != len - 1) + if (i != len - 1) { longthing += "\n"; + } } return longthing; @@ -450,8 +453,9 @@ String ExtendGDScriptParser::get_text_for_lookup_symbol(const lsp::Position &p_c longthing += lines[i]; } - if (i != len - 1) + if (i != len - 1) { longthing += "\n"; + } } return longthing; diff --git a/modules/gdscript/language_server/gdscript_language_protocol.cpp b/modules/gdscript/language_server/gdscript_language_protocol.cpp index c5bce5bb87..35bf4287b8 100644 --- a/modules/gdscript/language_server/gdscript_language_protocol.cpp +++ b/modules/gdscript/language_server/gdscript_language_protocol.cpp @@ -47,10 +47,11 @@ Error GDScriptLanguageProtocol::LSPeer::handle_data() { ERR_FAIL_COND_V_MSG(true, ERR_OUT_OF_MEMORY, "Response header too big"); } Error err = connection->get_partial_data(&req_buf[req_pos], 1, read); - if (err != OK) + if (err != OK) { return FAILED; - else if (read != 1) // Busy, wait until next poll + } else if (read != 1) { // Busy, wait until next poll return ERR_BUSY; + } char *r = (char *)req_buf; int l = req_pos; @@ -75,10 +76,11 @@ Error GDScriptLanguageProtocol::LSPeer::handle_data() { ERR_FAIL_COND_V_MSG(req_pos >= LSP_MAX_BUFFER_SIZE, ERR_OUT_OF_MEMORY, "Response content too big"); } Error err = connection->get_partial_data(&req_buf[req_pos], 1, read); - if (err != OK) + if (err != OK) { return FAILED; - else if (read != 1) + } else if (read != 1) { return ERR_BUSY; + } req_pos++; } diff --git a/modules/gdscript/language_server/gdscript_workspace.cpp b/modules/gdscript/language_server/gdscript_workspace.cpp index 7c432bfc80..9285d88157 100644 --- a/modules/gdscript/language_server/gdscript_workspace.cpp +++ b/modules/gdscript/language_server/gdscript_workspace.cpp @@ -184,8 +184,9 @@ Array GDScriptWorkspace::symbol(const Dictionary &p_params) { } Error GDScriptWorkspace::initialize() { - if (initialized) + if (initialized) { return OK; + } DocData *doc = EditorHelp::get_doc_data(); for (Map<String, DocData::ClassDoc>::Element *E = doc->class_list.front(); E; E = E->next()) { @@ -374,8 +375,9 @@ void GDScriptWorkspace::publish_diagnostics(const String &p_path) { } void GDScriptWorkspace::_get_owners(EditorFileSystemDirectory *efsd, String p_path, List<String> &owners) { - if (!efsd) + if (!efsd) { return; + } for (int i = 0; i < efsd->get_subdir_count(); i++) { _get_owners(efsd->get_subdir(i), p_path, owners); @@ -390,8 +392,9 @@ void GDScriptWorkspace::_get_owners(EditorFileSystemDirectory *efsd, String p_pa break; } } - if (!found) + if (!found) { continue; + } owners.push_back(efsd->get_file_path(i)); } diff --git a/modules/gdscript/language_server/lsp.hpp b/modules/gdscript/language_server/lsp.hpp index f979171b6e..44a0076107 100644 --- a/modules/gdscript/language_server/lsp.hpp +++ b/modules/gdscript/language_server/lsp.hpp @@ -280,8 +280,9 @@ struct Command { Dictionary dict; dict["title"] = title; dict["command"] = command; - if (arguments.size()) + if (arguments.size()) { dict["arguments"] = arguments; + } return dict; } }; @@ -945,20 +946,24 @@ struct CompletionItem { dict["preselect"] = preselect; dict["sortText"] = sortText; dict["filterText"] = filterText; - if (commitCharacters.size()) + if (commitCharacters.size()) { dict["commitCharacters"] = commitCharacters; + } dict["command"] = command.to_json(); } return dict; } void load(const Dictionary &p_dict) { - if (p_dict.has("label")) + if (p_dict.has("label")) { label = p_dict["label"]; - if (p_dict.has("kind")) + } + if (p_dict.has("kind")) { kind = p_dict["kind"]; - if (p_dict.has("detail")) + } + if (p_dict.has("detail")) { detail = p_dict["detail"]; + } if (p_dict.has("documentation")) { Variant doc = p_dict["documentation"]; if (doc.get_type() == Variant::STRING) { @@ -968,18 +973,24 @@ struct CompletionItem { documentation.value = v["value"]; } } - if (p_dict.has("deprecated")) + if (p_dict.has("deprecated")) { deprecated = p_dict["deprecated"]; - if (p_dict.has("preselect")) + } + if (p_dict.has("preselect")) { preselect = p_dict["preselect"]; - if (p_dict.has("sortText")) + } + if (p_dict.has("sortText")) { sortText = p_dict["sortText"]; - if (p_dict.has("filterText")) + } + if (p_dict.has("filterText")) { filterText = p_dict["filterText"]; - if (p_dict.has("insertText")) + } + if (p_dict.has("insertText")) { insertText = p_dict["insertText"]; - if (p_dict.has("data")) + } + if (p_dict.has("data")) { data = p_dict["data"]; + } } }; diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 161ab692c9..0625123530 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -68,12 +68,14 @@ public: script_key = preset->get_script_encryption_key().to_lower(); } - if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) + if (!p_path.ends_with(".gd") || script_mode == EditorExportPreset::MODE_SCRIPT_TEXT) { return; + } Vector<uint8_t> file = FileAccess::get_file_as_array(p_path); - if (file.empty()) + if (file.empty()) { return; + } String txt; txt.parse_utf8((const char *)file.ptr(), file.size()); @@ -90,19 +92,21 @@ public: int v = 0; if (i * 2 < script_key.length()) { CharType ct = script_key[i * 2]; - if (ct >= '0' && ct <= '9') + if (ct >= '0' && ct <= '9') { ct = ct - '0'; - else if (ct >= 'a' && ct <= 'f') + } else if (ct >= 'a' && ct <= 'f') { ct = 10 + ct - 'a'; + } v |= ct << 4; } if (i * 2 + 1 < script_key.length()) { CharType ct = script_key[i * 2 + 1]; - if (ct >= '0' && ct <= '9') + if (ct >= '0' && ct <= '9') { ct = ct - '0'; - else if (ct >= 'a' && ct <= 'f') + } else if (ct >= 'a' && ct <= 'f') { ct = 10 + ct - 'a'; + } v |= ct; } key.write[i] = v; @@ -166,8 +170,9 @@ void register_gdscript_types() { void unregister_gdscript_types() { ScriptServer::unregister_language(script_language_gd); - if (script_language_gd) + if (script_language_gd) { memdelete(script_language_gd); + } ResourceLoader::remove_resource_format_loader(resource_loader_gd); resource_loader_gd.unref(); diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index 02258d706a..2975a97bfe 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -118,8 +118,9 @@ bool GridMap::_get(const StringName &p_name, Variant &r_ret) const { } r_ret = ret; - } else + } else { return false; + } return true; } @@ -152,10 +153,11 @@ uint32_t GridMap::get_collision_mask() const { void GridMap::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_mask(mask); } @@ -165,10 +167,11 @@ bool GridMap::get_collision_mask_bit(int p_bit) const { void GridMap::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_layer(); - if (p_value) + if (p_value) { mask |= 1 << p_bit; - else + } else { mask &= ~(1 << p_bit); + } set_collision_layer(mask); } @@ -177,11 +180,13 @@ bool GridMap::get_collision_layer_bit(int p_bit) const { } void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) { - if (!mesh_library.is_null()) + if (!mesh_library.is_null()) { mesh_library->unregister_owner(this); + } mesh_library = p_mesh_library; - if (!mesh_library.is_null()) + if (!mesh_library.is_null()) { mesh_library->register_owner(this); + } _recreate_octant_data(); _change_notify("mesh_library"); @@ -323,8 +328,9 @@ int GridMap::get_cell_item(int p_x, int p_y, int p_z) const { key.y = p_y; key.z = p_z; - if (!cell_map.has(key)) + if (!cell_map.has(key)) { return INVALID_CELL_ITEM; + } return cell_map[key].item; } @@ -338,8 +344,9 @@ int GridMap::get_cell_item_orientation(int p_x, int p_y, int p_z) const { key.y = p_y; key.z = p_z; - if (!cell_map.has(key)) + if (!cell_map.has(key)) { return -1; + } return cell_map[key].rot; } @@ -377,8 +384,9 @@ void GridMap::_octant_transform(const OctantKey &p_key) { bool GridMap::_octant_update(const OctantKey &p_key) { ERR_FAIL_COND_V(!octant_map.has(p_key), false); Octant &g = *octant_map[p_key]; - if (!g.dirty) + if (!g.dirty) { return false; + } //erase body shapes PhysicsServer3D::get_singleton()->body_clear_shapes(g.static_body); @@ -422,8 +430,9 @@ bool GridMap::_octant_update(const OctantKey &p_key) { ERR_CONTINUE(!cell_map.has(E->get())); const Cell &c = cell_map[E->get()]; - if (!mesh_library.is_valid() || !mesh_library->has_item(c.item)) + if (!mesh_library.is_valid() || !mesh_library->has_item(c.item)) { continue; + } Vector3 cellpos = Vector3(E->get().x, E->get().y, E->get().z); Vector3 ofs = _get_offset(); @@ -450,8 +459,9 @@ bool GridMap::_octant_update(const OctantKey &p_key) { // add the item's shape at given xform to octant's static_body for (int i = 0; i < shapes.size(); i++) { // add the item's shape - if (!shapes[i].shape.is_valid()) + if (!shapes[i].shape.is_valid()) { continue; + } PhysicsServer3D::get_singleton()->body_add_shape(g.static_body, shapes[i].shape->get_rid(), xform * shapes[i].local_transform); if (g.collision_debug.is_valid()) { shapes.write[i].shape->add_vertices_to_array(col_debug, xform * shapes[i].local_transform); @@ -598,10 +608,12 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) { ERR_FAIL_COND(!octant_map.has(p_key)); Octant &g = *octant_map[p_key]; - if (g.collision_debug.is_valid()) + if (g.collision_debug.is_valid()) { RS::get_singleton()->free(g.collision_debug); - if (g.collision_debug_instance.is_valid()) + } + if (g.collision_debug_instance.is_valid()) { RS::get_singleton()->free(g.collision_debug_instance); + } PhysicsServer3D::get_singleton()->free(g.static_body); @@ -647,8 +659,9 @@ void GridMap::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { Transform new_xform = get_global_transform(); - if (new_xform == last_transform) + if (new_xform == last_transform) { break; + } //update run for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { _octant_transform(E->key()); @@ -683,8 +696,9 @@ void GridMap::_notification(int p_what) { } void GridMap::_update_visibility() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } _change_notify("visible"); @@ -698,8 +712,9 @@ void GridMap::_update_visibility() { } void GridMap::_queue_octants_dirty() { - if (awaiting_update) + if (awaiting_update) { return; + } MessageQueue::get_singleton()->push_call(this, "_update_octants_callback"); awaiting_update = true; @@ -717,8 +732,9 @@ void GridMap::_recreate_octant_data() { void GridMap::_clear_internal() { for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { - if (is_inside_world()) + if (is_inside_world()) { _octant_exit_world(E->key()); + } _octant_clean_up(E->key()); memdelete(E->get()); @@ -738,8 +754,9 @@ void GridMap::resource_changed(const RES &p_res) { } void GridMap::_update_octants_callback() { - if (!awaiting_update) + if (!awaiting_update) { return; + } List<OctantKey> to_delete; for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) { @@ -830,10 +847,12 @@ 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) + if (!p_enabled && !clip) { return; - if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis) + } + if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis) { return; + } clip = p_enabled; clip_floor = p_floor; @@ -871,19 +890,22 @@ Array GridMap::get_used_cells() const { } Array GridMap::get_meshes() { - if (mesh_library.is_null()) + if (mesh_library.is_null()) { return Array(); + } Vector3 ofs = _get_offset(); 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)) + if (!mesh_library->has_item(id)) { continue; + } Ref<Mesh> mesh = mesh_library->get_item_mesh(id); - if (mesh.is_null()) + if (mesh.is_null()) { continue; + } IndexKey ik = E->key(); @@ -920,8 +942,9 @@ 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()) + if (!mesh_library.is_valid()) { return; + } //generate Map<OctantKey, Map<Ref<Material>, Ref<SurfaceTool>>> surface_map; @@ -930,12 +953,14 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe IndexKey key = E->key(); int item = E->get().item; - if (!mesh_library->has_item(item)) + if (!mesh_library->has_item(item)) { continue; + } Ref<Mesh> mesh = mesh_library->get_item_mesh(item); - if (!mesh.is_valid()) + if (!mesh.is_valid()) { continue; + } Vector3 cellpos = Vector3(key.x, key.y, key.z); Vector3 ofs = _get_offset(); @@ -958,8 +983,9 @@ 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) + if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) { continue; + } Ref<Material> surf_mat = mesh->surface_get_material(i); if (!mat_map.has(surf_mat)) { @@ -1043,8 +1069,9 @@ GridMap::GridMap() { } GridMap::~GridMap() { - if (!mesh_library.is_null()) + if (!mesh_library.is_null()) { mesh_library->unregister_owner(this); + } clear(); } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index e8f7d09bb2..2bae43510a 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -40,13 +40,15 @@ #include "scene/main/window.h" void GridMapEditor::_node_removed(Node *p_node) { - if (p_node == node) + if (p_node == node) { node = nullptr; + } } void GridMapEditor::_configure() { - if (!node) + if (!node) { return; + } update_grid(); } @@ -213,8 +215,9 @@ void GridMapEditor::_menu_option(int p_option) { case MENU_OPTION_SELECTION_DUPLICATE: case MENU_OPTION_SELECTION_CUT: { - if (!(selection.active && input_action == INPUT_NONE)) + if (!(selection.active && input_action == INPUT_NONE)) { break; + } _set_clipboard_data(); @@ -231,15 +234,17 @@ void GridMapEditor::_menu_option(int p_option) { _update_paste_indicator(); } break; case MENU_OPTION_SELECTION_CLEAR: { - if (!selection.active) + if (!selection.active) { break; + } _delete_selection(); } break; case MENU_OPTION_SELECTION_FILL: { - if (!selection.active) + if (!selection.active) { return; + } _fill_selection(); @@ -303,17 +308,21 @@ void GridMapEditor::_update_selection_transform() { } void GridMapEditor::_validate_selection() { - if (!selection.active) + if (!selection.active) { return; + } selection.begin = selection.click; selection.end = selection.current; - if (selection.begin.x > selection.end.x) + if (selection.begin.x > selection.end.x) { SWAP(selection.begin.x, selection.end.x); - if (selection.begin.y > selection.end.y) + } + if (selection.begin.y > selection.end.y) { SWAP(selection.begin.y, selection.end.y); - if (selection.begin.z > selection.end.z) + } + if (selection.begin.z > selection.end.z) { SWAP(selection.begin.z, selection.end.z); + } _update_selection_transform(); } @@ -336,16 +345,20 @@ 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) + if (!spatial_editor) { return false; + } - if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) + if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) { return false; + } Ref<MeshLibrary> mesh_library = node->get_mesh_library(); - if (mesh_library.is_null()) + if (mesh_library.is_null()) { return false; - if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) + } + if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) { return false; + } Camera3D *camera = p_camera; Vector3 from = camera->project_ray_origin(p_point); @@ -360,27 +373,30 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis]; Vector3 inters; - if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) + if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) { return false; + } // 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)) + if (fp.is_point_over(inters)) { return false; + } } int cell[3]; 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) + if (i == edit_axis) { cell[i] = edit_floor[i]; - else { + } else { cell[i] = inters[i] / node->get_cell_size()[i]; - if (inters[i] < 0) + if (inters[i] < 0) { cell[i] -= 1; // Compensate negative. + } grid_ofs[i] = cell[i] * cell_size[i]; } } @@ -404,8 +420,9 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b } else if (input_action == INPUT_SELECT) { selection.current = Vector3(cell[0], cell[1], cell[2]); - if (p_click) + if (p_click) { selection.click = selection.current; + } selection.active = true; _validate_selection(); @@ -446,8 +463,9 @@ bool GridMapEditor::do_input_action(Camera3D *p_camera, const Point2 &p_point, b } void GridMapEditor::_delete_selection() { - if (!selection.active) + if (!selection.active) { return; + } undo_redo->create_action(TTR("GridMap Delete Selection")); for (int i = selection.begin.x; i <= selection.end.x; i++) { @@ -464,8 +482,9 @@ void GridMapEditor::_delete_selection() { } void GridMapEditor::_fill_selection() { - if (!selection.active) + if (!selection.active) { return; + } undo_redo->create_action(TTR("GridMap Fill Selection")); for (int i = selection.begin.x; i <= selection.end.x; i++) { @@ -498,8 +517,9 @@ void GridMapEditor::_set_clipboard_data() { 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) + if (itm == GridMap::INVALID_CELL_ITEM) { continue; + } Ref<Mesh> mesh = meshLibrary->get_item_mesh(itm); @@ -593,13 +613,15 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In if (mb.is_valid()) { if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) { - if (mb->is_pressed()) + if (mb->is_pressed()) { floor->set_value(floor->get_value() + mb->get_factor()); + } return true; // Eaten. } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { - if (mb->is_pressed()) + if (mb->is_pressed()) { floor->set_value(floor->get_value() - mb->get_factor()); + } return true; } @@ -859,8 +881,9 @@ void GridMapEditor::update_palette() { name = "#" + itos(id); } - if (filter != "" && !filter.is_subsequence_ofi(name)) + if (filter != "" && !filter.is_subsequence_ofi(name)) { continue; + } mesh_library_palette->add_item(""); if (!preview.is_null()) { @@ -881,8 +904,9 @@ void GridMapEditor::update_palette() { } void GridMapEditor::edit(GridMap *p_gridmap) { - if (!p_gridmap && node) + if (!p_gridmap && node) { node->disconnect("cell_size_changed", callable_mp(this, &GridMapEditor::_draw_grids)); + } node = p_gridmap; @@ -921,10 +945,11 @@ void GridMapEditor::edit(GridMap *p_gridmap) { void GridMapEditor::_update_clip() { node->set_meta("_editor_clip_", clip_mode); - if (clip_mode == CLIP_DISABLED) + if (clip_mode == CLIP_DISABLED) { node->set_clip(false); - else + } else { node->set_clip(true, clip_mode == CLIP_ABOVE, edit_floor[edit_axis], edit_axis); + } } void GridMapEditor::update_grid() { @@ -1045,8 +1070,9 @@ void GridMapEditor::_notification(int p_what) { grid_xform = xf; } Ref<MeshLibrary> cgmt = node->get_mesh_library(); - if (cgmt.operator->() != last_mesh_library) + if (cgmt.operator->() != last_mesh_library) { update_palette(); + } if (lock_view) { EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0)); @@ -1057,8 +1083,9 @@ void GridMapEditor::_notification(int p_what) { p = node->get_transform().xform(p); // plane to snap Node3DEditorPlugin *sep = Object::cast_to<Node3DEditorPlugin>(editor->get_editor_plugin_screen()); - if (sep) + if (sep) { sep->snap_cursor_to_plane(p); + } } } break; @@ -1074,8 +1101,9 @@ void GridMapEditor::_update_cursor_instance() { return; } - if (cursor_instance.is_valid()) + if (cursor_instance.is_valid()) { RenderingServer::get_singleton()->free(cursor_instance); + } cursor_instance = RID(); if (selected_palette >= 0) { @@ -1096,8 +1124,9 @@ void GridMapEditor::_item_selected_cbk(int idx) { } void GridMapEditor::_floor_changed(float p_value) { - if (updating) + if (updating) { return; + } edit_floor[edit_axis] = p_value; node->set_meta("_editor_floor_", Vector3(edit_floor[0], edit_floor[1], edit_floor[2])); @@ -1284,10 +1313,11 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { v[2] = v[1] * (1 - 2 * (j & 1)); for (int k = 0; k < 3; k++) { - if (i < 3) + if (i < 3) { face_points[j][(i + k) % 3] = v[k]; - else + } else { face_points[3 - j][(i + k) % 3] = -v[k]; + } } } @@ -1395,25 +1425,32 @@ GridMapEditor::~GridMapEditor() { _clear_clipboard_data(); for (int i = 0; i < 3; i++) { - if (grid[i].is_valid()) + if (grid[i].is_valid()) { RenderingServer::get_singleton()->free(grid[i]); - if (grid_instance[i].is_valid()) + } + if (grid_instance[i].is_valid()) { RenderingServer::get_singleton()->free(grid_instance[i]); - if (cursor_instance.is_valid()) + } + if (cursor_instance.is_valid()) { RenderingServer::get_singleton()->free(cursor_instance); - if (selection_level_instance[i].is_valid()) + } + if (selection_level_instance[i].is_valid()) { RenderingServer::get_singleton()->free(selection_level_instance[i]); - if (selection_level_mesh[i].is_valid()) + } + if (selection_level_mesh[i].is_valid()) { RenderingServer::get_singleton()->free(selection_level_mesh[i]); + } } RenderingServer::get_singleton()->free(selection_mesh); - if (selection_instance.is_valid()) + if (selection_instance.is_valid()) { RenderingServer::get_singleton()->free(selection_instance); + } RenderingServer::get_singleton()->free(paste_mesh); - if (paste_instance.is_valid()) + if (paste_instance.is_valid()) { RenderingServer::get_singleton()->free(paste_instance); + } } void GridMapEditorPlugin::_notification(int p_what) { diff --git a/modules/hdr/image_loader_hdr.cpp b/modules/hdr/image_loader_hdr.cpp index 19cd8ae584..333b1cf377 100644 --- a/modules/hdr/image_loader_hdr.cpp +++ b/modules/hdr/image_loader_hdr.cpp @@ -41,8 +41,9 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force while (true) { String line = f->get_line(); ERR_FAIL_COND_V(f->eof_reached(), ERR_FILE_UNRECOGNIZED); - if (line == "") // empty line indicates end of header + if (line == "") { // empty line indicates end of header break; + } if (line.begins_with("FORMAT=")) { // leave option to implement other commands ERR_FAIL_COND_V_MSG(line != "FORMAT=32-bit_rle_rgbe", ERR_FILE_UNRECOGNIZED, "Only 32-bit_rle_rgbe is supported for HDR files."); } else if (!line.begins_with("#")) { // not comment @@ -107,12 +108,14 @@ Error ImageLoaderHDR::load_image(Ref<Image> p_image, FileAccess *f, bool p_force // Run int value = f->get_8(); count -= 128; - for (int z = 0; z < count; ++z) + for (int z = 0; z < count; ++z) { ptr[(j * width + i++) * 4 + k] = uint8_t(value); + } } else { // Dump - for (int z = 0; z < count; ++z) + for (int z = 0; z < count; ++z) { ptr[(j * width + i++) * 4 + k] = f->get_8(); + } } } } diff --git a/modules/jpg/image_loader_jpegd.cpp b/modules/jpg/image_loader_jpegd.cpp index 16ebd65147..9c7ace5cf2 100644 --- a/modules/jpg/image_loader_jpegd.cpp +++ b/modules/jpg/image_loader_jpegd.cpp @@ -48,11 +48,13 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p const int image_width = decoder.get_width(); const int image_height = decoder.get_height(); const int comps = decoder.get_num_components(); - if (comps != 1 && comps != 3) + if (comps != 1 && comps != 3) { return ERR_FILE_CORRUPT; + } - if (decoder.begin_decoding() != jpgd::JPGD_SUCCESS) + if (decoder.begin_decoding() != jpgd::JPGD_SUCCESS) { return ERR_FILE_CORRUPT; + } const int dst_bpl = image_width * comps; @@ -90,10 +92,11 @@ Error jpeg_load_image_from_buffer(Image *p_image, const uint8_t *p_buffer, int p //all good Image::Format fmt; - if (comps == 1) + if (comps == 1) { fmt = Image::FORMAT_L8; - else + } else { fmt = Image::FORMAT_RGB8; + } p_image->create(image_width, image_height, false, fmt, data); diff --git a/modules/jsonrpc/jsonrpc.cpp b/modules/jsonrpc/jsonrpc.cpp index f744dd50d2..6ab5f2d9b3 100644 --- a/modules/jsonrpc/jsonrpc.cpp +++ b/modules/jsonrpc/jsonrpc.cpp @@ -147,8 +147,9 @@ 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()) + if (p_input.empty()) { return String(); + } Variant ret; Variant input; diff --git a/modules/mbedtls/packet_peer_mbed_dtls.cpp b/modules/mbedtls/packet_peer_mbed_dtls.cpp index 210c9877df..8206d739ae 100644 --- a/modules/mbedtls/packet_peer_mbed_dtls.cpp +++ b/modules/mbedtls/packet_peer_mbed_dtls.cpp @@ -35,8 +35,9 @@ #include "core/os/file_access.h" int PacketPeerMbedDTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) { - if (buf == nullptr || len <= 0) + if (buf == nullptr || len <= 0) { return 0; + } PacketPeerMbedDTLS *sp = (PacketPeerMbedDTLS *)ctx; @@ -52,8 +53,9 @@ 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) + if (buf == nullptr || len <= 0) { return 0; + } PacketPeerMbedDTLS *sp = (PacketPeerMbedDTLS *)ctx; @@ -167,8 +169,9 @@ 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) + if (p_bytes == 0) { return OK; + } int ret = mbedtls_ssl_write(ssl_ctx->get_context(), p_buffer, p_bytes); if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) { @@ -251,15 +254,16 @@ PacketPeerMbedDTLS::~PacketPeerMbedDTLS() { } void PacketPeerMbedDTLS::disconnect_from_peer() { - if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) + if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) { return; + } if (status == STATUS_CONNECTED) { int ret = 0; // Send SSL close notification, blocking, but ignore other errors. - do + do { ret = mbedtls_ssl_close_notify(ssl_ctx->get_context()); - while (ret == MBEDTLS_ERR_SSL_WANT_WRITE); + } while (ret == MBEDTLS_ERR_SSL_WANT_WRITE); } _cleanup(); diff --git a/modules/mbedtls/ssl_context_mbedtls.cpp b/modules/mbedtls/ssl_context_mbedtls.cpp index b0ca4a9e44..a2200e0644 100644 --- a/modules/mbedtls/ssl_context_mbedtls.cpp +++ b/modules/mbedtls/ssl_context_mbedtls.cpp @@ -67,8 +67,9 @@ Error CookieContextMbedTLS::setup() { } void CookieContextMbedTLS::clear() { - if (!inited) + if (!inited) { return; + } mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_entropy_free(&entropy); mbedtls_ssl_cookie_free(&cookie_ctx); @@ -120,10 +121,12 @@ Error SSLContextMbedTLS::init_server(int p_transport, int p_authmode, Ref<Crypto // Locking key and certificate(s) pkey = p_pkey; certs = p_cert; - if (pkey.is_valid()) + if (pkey.is_valid()) { pkey->lock(); - if (certs.is_valid()) + } + if (certs.is_valid()) { certs->lock(); + } // Adding key and certificate int ret = mbedtls_ssl_conf_own_cert(&conf, &(certs->cert), &(pkey->pkey)); @@ -175,19 +178,22 @@ Error SSLContextMbedTLS::init_client(int p_transport, int p_authmode, Ref<X509Ce } void SSLContextMbedTLS::clear() { - if (!inited) + if (!inited) { return; + } mbedtls_ssl_free(&ssl); mbedtls_ssl_config_free(&conf); mbedtls_ctr_drbg_free(&ctr_drbg); mbedtls_entropy_free(&entropy); // Unlock and key and certificates - if (certs.is_valid()) + if (certs.is_valid()) { certs->unlock(); + } certs = Ref<X509Certificate>(); - if (pkey.is_valid()) + if (pkey.is_valid()) { pkey->unlock(); + } pkey = Ref<CryptoKeyMbedTLS>(); cookies = Ref<CookieContextMbedTLS>(); inited = false; diff --git a/modules/mbedtls/stream_peer_mbedtls.cpp b/modules/mbedtls/stream_peer_mbedtls.cpp index c6b0846716..e9a610b7ee 100644 --- a/modules/mbedtls/stream_peer_mbedtls.cpp +++ b/modules/mbedtls/stream_peer_mbedtls.cpp @@ -34,8 +34,9 @@ #include "core/os/file_access.h" int StreamPeerMbedTLS::bio_send(void *ctx, const unsigned char *buf, size_t len) { - if (buf == nullptr || len <= 0) + if (buf == nullptr || len <= 0) { return 0; + } StreamPeerMbedTLS *sp = (StreamPeerMbedTLS *)ctx; @@ -53,8 +54,9 @@ 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) + if (buf == nullptr || len <= 0) { return 0; + } StreamPeerMbedTLS *sp = (StreamPeerMbedTLS *)ctx; @@ -167,8 +169,9 @@ Error StreamPeerMbedTLS::put_partial_data(const uint8_t *p_data, int p_bytes, in r_sent = 0; - if (p_bytes == 0) + if (p_bytes == 0) { return OK; + } int ret = mbedtls_ssl_write(ssl_ctx->get_context(), p_data, p_bytes); if (ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE) { @@ -279,8 +282,9 @@ StreamPeerMbedTLS::~StreamPeerMbedTLS() { } void StreamPeerMbedTLS::disconnect_from_stream() { - if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) + if (status != STATUS_CONNECTED && status != STATUS_HANDSHAKING) { return; + } Ref<StreamPeerTCP> tcp = base; if (tcp.is_valid() && tcp->get_status() == StreamPeerTCP::STATUS_CONNECTED) { diff --git a/modules/mobile_vr/mobile_vr_interface.cpp b/modules/mobile_vr/mobile_vr_interface.cpp index 6d10de0096..eebb3af709 100644 --- a/modules/mobile_vr/mobile_vr_interface.cpp +++ b/modules/mobile_vr/mobile_vr_interface.cpp @@ -61,19 +61,25 @@ Vector3 MobileVRInterface::scale_magneto(const Vector3 &p_magnetometer) { }; // adjust our min and max - if (mag_raw.x > mag_next_max.x) + if (mag_raw.x > mag_next_max.x) { mag_next_max.x = mag_raw.x; - if (mag_raw.y > mag_next_max.y) + } + if (mag_raw.y > mag_next_max.y) { mag_next_max.y = mag_raw.y; - if (mag_raw.z > mag_next_max.z) + } + if (mag_raw.z > mag_next_max.z) { mag_next_max.z = mag_raw.z; + } - if (mag_raw.x < mag_next_min.x) + if (mag_raw.x < mag_next_min.x) { mag_next_min.x = mag_raw.x; - if (mag_raw.y < mag_next_min.y) + } + if (mag_raw.y < mag_next_min.y) { mag_next_min.y = mag_raw.y; - if (mag_raw.z < mag_next_min.z) + } + if (mag_raw.z < mag_next_min.z) { mag_next_min.z = mag_raw.z; + } // scale our x, y and z if (!(mag_current_max.x - mag_current_min.x)) { diff --git a/modules/opensimplex/noise_texture.cpp b/modules/opensimplex/noise_texture.cpp index 2ded998b60..1181e69cd3 100644 --- a/modules/opensimplex/noise_texture.cpp +++ b/modules/opensimplex/noise_texture.cpp @@ -124,8 +124,9 @@ void NoiseTexture::_thread_function(void *p_ud) { } void NoiseTexture::_queue_update() { - if (update_queued) + if (update_queued) { return; + } update_queued = true; call_deferred("_update_texture"); @@ -179,8 +180,9 @@ void NoiseTexture::_update_texture() { } void NoiseTexture::set_noise(Ref<OpenSimplexNoise> p_noise) { - if (p_noise == noise) + if (p_noise == noise) { return; + } if (noise.is_valid()) { noise->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &NoiseTexture::_queue_update)); } @@ -196,22 +198,25 @@ Ref<OpenSimplexNoise> NoiseTexture::get_noise() { } void NoiseTexture::set_width(int p_width) { - if (p_width == size.x) + if (p_width == size.x) { return; + } size.x = p_width; _queue_update(); } void NoiseTexture::set_height(int p_height) { - if (p_height == size.y) + if (p_height == size.y) { return; + } size.y = p_height; _queue_update(); } void NoiseTexture::set_seamless(bool p_seamless) { - if (p_seamless == seamless) + if (p_seamless == seamless) { return; + } seamless = p_seamless; _queue_update(); } @@ -221,8 +226,9 @@ bool NoiseTexture::get_seamless() { } void NoiseTexture::set_as_normalmap(bool p_as_normalmap) { - if (p_as_normalmap == as_normalmap) + if (p_as_normalmap == as_normalmap) { return; + } as_normalmap = p_as_normalmap; _queue_update(); _change_notify(); @@ -233,11 +239,13 @@ bool NoiseTexture::is_normalmap() { } void NoiseTexture::set_bump_strength(float p_bump_strength) { - if (p_bump_strength == bump_strength) + if (p_bump_strength == bump_strength) { return; + } bump_strength = p_bump_strength; - if (as_normalmap) + if (as_normalmap) { _queue_update(); + } } float NoiseTexture::get_bump_strength() { diff --git a/modules/opensimplex/open_simplex_noise.cpp b/modules/opensimplex/open_simplex_noise.cpp index 97b66f2c07..00b3d47db9 100644 --- a/modules/opensimplex/open_simplex_noise.cpp +++ b/modules/opensimplex/open_simplex_noise.cpp @@ -52,8 +52,9 @@ void OpenSimplexNoise::_init_seeds() { } void OpenSimplexNoise::set_seed(int p_seed) { - if (seed == p_seed) + if (seed == p_seed) { return; + } seed = p_seed; @@ -67,8 +68,9 @@ int OpenSimplexNoise::get_seed() { } void OpenSimplexNoise::set_octaves(int p_octaves) { - if (p_octaves == octaves) + if (p_octaves == octaves) { return; + } ERR_FAIL_COND_MSG(p_octaves > MAX_OCTAVES, vformat("The number of OpenSimplexNoise octaves is limited to %d; ignoring the new value.", MAX_OCTAVES)); @@ -77,22 +79,25 @@ void OpenSimplexNoise::set_octaves(int p_octaves) { } void OpenSimplexNoise::set_period(float p_period) { - if (p_period == period) + if (p_period == period) { return; + } period = p_period; emit_changed(); } void OpenSimplexNoise::set_persistence(float p_persistence) { - if (p_persistence == persistence) + if (p_persistence == persistence) { return; + } persistence = p_persistence; emit_changed(); } void OpenSimplexNoise::set_lacunarity(float p_lacunarity) { - if (p_lacunarity == lacunarity) + if (p_lacunarity == lacunarity) { return; + } lacunarity = p_lacunarity; emit_changed(); } diff --git a/modules/pvr/texture_loader_pvr.cpp b/modules/pvr/texture_loader_pvr.cpp index 20f46e1f7a..36c0913f62 100644 --- a/modules/pvr/texture_loader_pvr.cpp +++ b/modules/pvr/texture_loader_pvr.cpp @@ -52,20 +52,23 @@ 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) + if (r_error) { *r_error = ERR_CANT_OPEN; + } Error err; FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - if (!f) + if (!f) { return RES(); + } FileAccessRef faref(f); ERR_FAIL_COND_V(err, RES()); - if (r_error) + if (r_error) { *r_error = ERR_FILE_CORRUPT; + } uint32_t hsize = f->get_32(); @@ -160,8 +163,9 @@ RES ResourceFormatPVR::load(const String &p_path, const String &p_original_path, Ref<ImageTexture> texture = memnew(ImageTexture); texture->create_from_image(image); - if (r_error) + if (r_error) { *r_error = OK; + } return texture; } @@ -175,8 +179,9 @@ bool ResourceFormatPVR::handles_type(const String &p_type) const { } String ResourceFormatPVR::get_resource_type(const String &p_path) const { - if (p_path.get_extension().to_lower() == "pvr") + if (p_path.get_extension().to_lower() == "pvr") { return "Texture2D"; + } return ""; } @@ -189,8 +194,9 @@ static void _compress_pvrtc4(Image *p_img) { img->resize_to_po2(true); } img->convert(Image::FORMAT_RGBA8); - if (!img->has_mipmaps() && make_mipmaps) + if (!img->has_mipmaps() && make_mipmaps) { img->generate_mipmaps(); + } bool use_alpha = img->detect_alpha(); @@ -253,8 +259,9 @@ struct PVRTCBlock { }; _FORCE_INLINE_ bool is_po2(uint32_t p_input) { - if (p_input == 0) + if (p_input == 0) { return false; + } uint32_t minus1 = p_input - 1; return ((p_input | minus1) == (p_input ^ minus1)) ? true : false; } @@ -269,8 +276,9 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { 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; - if (i == 0) + if (i == 0) { 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; @@ -281,10 +289,11 @@ static void unpack_5554(const PVRTCBlock *p_block, int p_ab_colors[2][4]) { p_ab_colors[i][2] = (raw_bits[i] & 0xF) << 1; - if (i == 0) + if (i == 0) { p_ab_colors[0][2] |= p_ab_colors[0][2] >> 3; - else + } else { p_ab_colors[0][2] |= p_ab_colors[0][2] >> 4; + } p_ab_colors[i][3] = (raw_bits[i] >> 11) & 0xE; } @@ -312,10 +321,11 @@ static void unpack_modulations(const PVRTCBlock *p_block, const int p_2bit, int for (int x = 0; x < BLK_X_2BPP; x++) { p_modulation_modes[y + p_y][x + p_x] = block_mod_mode; - if (modulation_bits & 1) + if (modulation_bits & 1) { p_modulation[y + p_y][x + p_x] = 0x3; - else + } else { p_modulation[y + p_y][x + p_x] = 0x0; + } modulation_bits >>= 1; } @@ -350,10 +360,11 @@ static void interpolate_colors(const int p_colorp[4], const int p_colorq[4], con v = (y & 0x3) | ((~y & 0x2) << 1); - if (p_2bit) + if (p_2bit) { u = (x & 0x7) | ((~x & 0x4) << 1); - else + } else { u = (x & 0x3) | ((~x & 0x2) << 1); + } v = v - BLK_Y_SIZE / 2; @@ -409,19 +420,20 @@ static void get_modulation_value(int x, int y, const int p_2bit, const int p_mod y = (y & 0x3) | ((~y & 0x2) << 1); - if (p_2bit) + if (p_2bit) { x = (x & 0x7) | ((~x & 0x4) << 1); - else + } else { x = (x & 0x3) | ((~x & 0x2) << 1); + } *p_dopt = 0; if (p_modulation_modes[y][x] == 0) { mod_val = rep_vals0[p_modulation[y][x]]; } else if (p_2bit) { - if (((x ^ y) & 1) == 0) + if (((x ^ y) & 1) == 0) { mod_val = rep_vals0[p_modulation[y][x]]; - else if (p_modulation_modes[y][x] == 1) { + } else if (p_modulation_modes[y][x] == 1) { mod_val = (rep_vals0[p_modulation[y - 1][x]] + rep_vals0[p_modulation[y + 1][x]] + rep_vals0[p_modulation[y][x - 1]] + @@ -472,8 +484,9 @@ static uint32_t twiddle_uv(uint32_t p_height, uint32_t p_width, uint32_t p_y, ui max_value = p_y; } - if (disable_twiddling) + if (disable_twiddling) { return (p_y * p_width + p_x); + } scr_bit_pos = 1; dst_bit_pos = 1; @@ -533,10 +546,11 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int int r_result[4]; - if (p_2bit) + if (p_2bit) { x_block_size = BLK_X_2BPP; - else + } else { x_block_size = BLK_X_4BPP; + } block_width = MAX(2, p_width / x_block_size); block_height = MAX(2, p_height / BLK_Y_SIZE); @@ -607,8 +621,9 @@ static void decompress_pvrtc(PVRTCBlock *p_comp_img, const int p_2bit, const int r_result[i] >>= 3; } - if (DoPT) + if (DoPT) { r_result[3] = 0; + } u_pos = (x + y * p_width) << 2; p_dst[u_pos + 0] = (uint8_t)r_result[0]; @@ -635,6 +650,7 @@ static void _pvrtc_decompress(Image *p_img) { bool make_mipmaps = p_img->has_mipmaps(); p_img->create(p_img->get_width(), p_img->get_height(), false, Image::FORMAT_RGBA8, newdata); - if (make_mipmaps) + if (make_mipmaps) { p_img->generate_mipmaps(); + } } diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index c0627b8f25..50ca01067b 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -46,14 +46,16 @@ static void _regex_free(void *ptr, void *user) { int RegExMatch::_find(const Variant &p_name) const { if (p_name.is_num()) { int i = (int)p_name; - if (i >= data.size()) + 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) + if (found) { return found->value(); + } } return -1; @@ -64,8 +66,9 @@ String RegExMatch::get_subject() const { } int RegExMatch::get_group_count() const { - if (data.size() == 0) + if (data.size() == 0) { return 0; + } return data.size() - 1; } @@ -103,13 +106,15 @@ Array RegExMatch::get_strings() const { String RegExMatch::get_string(const Variant &p_name) const { int id = _find(p_name); - if (id < 0) + if (id < 0) { return String(); + } int start = data[id].start; - if (start == -1) + if (start == -1) { return String(); + } int length = data[id].end - start; @@ -119,8 +124,9 @@ 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) + if (id < 0) { return -1; + } return data[id].start; } @@ -128,8 +134,9 @@ 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) + if (id < 0) { return -1; + } return data[id].end; } @@ -223,8 +230,9 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) Ref<RegExMatch> result = memnew(RegExMatch); int length = p_subject.length(); - if (p_end >= 0 && p_end < length) + if (p_end >= 0 && p_end < length) { length = p_end; + } if (sizeof(CharType) == 2) { pcre2_code_16 *c = (pcre2_code_16 *)code; @@ -297,11 +305,13 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) for (uint32_t i = 0; i < count; i++) { CharType id = table[i * entry_size]; - if (result->data[id].start == -1) + if (result->data[id].start == -1) { continue; + } String name = &table[i * entry_size + 1]; - if (result->names.has(name)) + if (result->names.has(name)) { continue; + } result->names.insert(name, id); } @@ -314,8 +324,9 @@ Array RegEx::search_all(const String &p_subject, int p_offset, int p_end) const Array result; Ref<RegExMatch> match = search(p_subject, p_offset, p_end); while (match.is_valid()) { - if (last_end == match->get_end(0)) + if (last_end == match->get_end(0)) { break; + } result.push_back(match); last_end = match->get_end(0); match = search(p_subject, match->get_end(0), p_end); @@ -337,12 +348,14 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a output.resize(olength + safety_zone); uint32_t flags = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH; - if (p_all) + if (p_all) { flags |= PCRE2_SUBSTITUTE_GLOBAL; + } PCRE2_SIZE length = p_subject.length(); - if (p_end >= 0 && (uint32_t)p_end < length) + if (p_end >= 0 && (uint32_t)p_end < length) { length = p_end; + } if (sizeof(CharType) == 2) { pcre2_code_16 *c = (pcre2_code_16 *)code; @@ -365,8 +378,9 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a pcre2_match_data_free_16(match); pcre2_match_context_free_16(mctx); - if (res < 0) + if (res < 0) { return String(); + } } else { pcre2_code_32 *c = (pcre2_code_32 *)code; @@ -389,8 +403,9 @@ String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_a pcre2_match_data_free_32(match); pcre2_match_context_free_32(mctx); - if (res < 0) + if (res < 0) { return String(); + } } return String(output.ptr(), olength); @@ -460,13 +475,15 @@ RegEx::RegEx(const String &p_pattern) { RegEx::~RegEx() { if (sizeof(CharType) == 2) { - if (code) + if (code) { pcre2_code_free_16((pcre2_code_16 *)code); + } pcre2_general_context_free_16((pcre2_general_context_16 *)general_ctx); } else { - if (code) + if (code) { pcre2_code_free_32((pcre2_code_32 *)code); + } pcre2_general_context_free_32((pcre2_general_context_32 *)general_ctx); } } diff --git a/modules/squish/image_compress_squish.cpp b/modules/squish/image_compress_squish.cpp index a19f3158c4..c510779317 100644 --- a/modules/squish/image_compress_squish.cpp +++ b/modules/squish/image_compress_squish.cpp @@ -78,8 +78,9 @@ 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) + if (p_image->get_format() >= Image::FORMAT_DXT1) { return; //do not compress, already compressed + } int w = p_image->get_width(); int h = p_image->get_height(); @@ -87,10 +88,11 @@ void image_compress_squish(Image *p_image, float p_lossy_quality, Image::UsedCha if (p_image->get_format() <= Image::FORMAT_RGBA8) { int squish_comp = squish::kColourRangeFit; - if (p_lossy_quality > 0.85) + if (p_lossy_quality > 0.85) { squish_comp = squish::kColourIterativeClusterFit; - else if (p_lossy_quality > 0.75) + } else if (p_lossy_quality > 0.75) { squish_comp = squish::kColourClusterFit; + } Image::Format target_format = Image::FORMAT_RGBA8; diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp index 775a2f23c7..3aceaf11c5 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.cpp @@ -102,8 +102,9 @@ float AudioStreamPlaybackOGGVorbis::get_playback_position() const { } void AudioStreamPlaybackOGGVorbis::seek(float p_time) { - if (!active) + if (!active) { return; + } if (p_time >= vorbis_stream->get_length()) { p_time = 0; diff --git a/modules/tga/image_loader_tga.cpp b/modules/tga/image_loader_tga.cpp index 53c6a8c269..ce889a4928 100644 --- a/modules/tga/image_loader_tga.cpp +++ b/modules/tga/image_loader_tga.cpp @@ -38,8 +38,9 @@ Error ImageLoaderTGA::decode_tga_rle(const uint8_t *p_compressed_buffer, size_t Vector<uint8_t> pixels; error = pixels.resize(p_pixel_size); - if (error != OK) + if (error != OK) { return error; + } uint8_t *pixels_w = pixels.ptrw(); @@ -232,8 +233,9 @@ Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force bool has_color_map = (tga_header.image_type == TGA_TYPE_RLE_INDEXED || tga_header.image_type == TGA_TYPE_INDEXED); bool is_monochrome = (tga_header.image_type == TGA_TYPE_RLE_MONOCHROME || tga_header.image_type == TGA_TYPE_MONOCHROME); - if (tga_header.image_type == TGA_TYPE_NO_DATA) + if (tga_header.image_type == TGA_TYPE_NO_DATA) { err = FAILED; + } if (has_color_map) { if (tga_header.color_map_length > 256 || (tga_header.color_map_depth != 24) || tga_header.color_map_type != 1) { @@ -245,8 +247,9 @@ Error ImageLoaderTGA::load_image(Ref<Image> p_image, FileAccess *f, bool p_force } } - if (tga_header.image_width <= 0 || tga_header.image_height <= 0) + if (tga_header.image_width <= 0 || tga_header.image_height <= 0) { err = FAILED; + } if (!(tga_header.pixel_depth == 8 || tga_header.pixel_depth == 24 || tga_header.pixel_depth == 32)) { err = FAILED; diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index 7df204ff51..4d83e6a4a5 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -68,13 +68,15 @@ int VideoStreamPlaybackTheora::buffer_data() { int VideoStreamPlaybackTheora::queue_page(ogg_page *page) { if (theora_p) { ogg_stream_pagein(&to, page); - if (to.e_o_s) + if (to.e_o_s) { theora_eos = true; + } } if (vorbis_p) { ogg_stream_pagein(&vo, page); - if (vo.e_o_s) + if (vo.e_o_s) { vorbis_eos = true; + } } return 0; } @@ -112,8 +114,9 @@ void VideoStreamPlaybackTheora::video_write() { } void VideoStreamPlaybackTheora::clear() { - if (!file) + if (!file) { return; + } if (vorbis_p) { ogg_stream_clear(&vo); @@ -203,8 +206,9 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { while (!stateflag) { int ret = buffer_data(); - if (ret == 0) + if (ret == 0) { break; + } while (ogg_sync_pageout(&oy, &og) > 0) { ogg_stream_state test; @@ -280,8 +284,9 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) { return; } vorbis_p++; - if (vorbis_p == 3) + if (vorbis_p == 3) { break; + } } /* The header pages/packets will arrive before anything else we @@ -371,8 +376,9 @@ Ref<Texture2D> VideoStreamPlaybackTheora::get_texture() const { } void VideoStreamPlaybackTheora::update(float p_delta) { - if (!file) + if (!file) { return; + } if (!playing || paused) { //printf("not playing\n"); @@ -450,8 +456,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) { audio_done = videobuf_time < (audio_frames_wrote / float(vi.rate)); - if (buffer_full) + if (buffer_full) { break; + } } while (theora_p && !frame_done) { @@ -542,9 +549,9 @@ void VideoStreamPlaybackTheora::update(float p_delta) { }; void VideoStreamPlaybackTheora::play() { - if (!playing) + if (!playing) { time = 0; - else { + } else { stop(); } @@ -679,8 +686,9 @@ VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { #endif clear(); - if (file) + if (file) { memdelete(file); + } }; void VideoStreamTheora::_bind_methods() { @@ -725,7 +733,8 @@ bool ResourceFormatLoaderTheora::handles_type(const String &p_type) const { String ResourceFormatLoaderTheora::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "ogv") + if (el == "ogv") { return "VideoStreamTheora"; + } return ""; } diff --git a/modules/tinyexr/image_loader_tinyexr.cpp b/modules/tinyexr/image_loader_tinyexr.cpp index dc34fe3003..9e7266b95a 100644 --- a/modules/tinyexr/image_loader_tinyexr.cpp +++ b/modules/tinyexr/image_loader_tinyexr.cpp @@ -212,8 +212,9 @@ Error ImageLoaderTinyEXR::load_image(Ref<Image> p_image, FileAccess *f, bool p_f for (int x = 0; x < tw; x++) { Color color(*r_channel++, *g_channel++, *b_channel++); - if (p_force_linear) + if (p_force_linear) { color = color.to_linear(); + } *row_w++ = Math::make_half_float(color.r); *row_w++ = Math::make_half_float(color.g); diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index 42d0fb37fe..8afed1229f 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -134,6 +134,7 @@ void unregister_visual_script_types() { memdelete(vs_editor_singleton); } #endif - if (visual_script_language) + if (visual_script_language) { memdelete(visual_script_language); + } } diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 4d5e5200b6..f387c0f288 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -133,8 +133,9 @@ VisualScriptNode::TypeGuess VisualScriptNode::guess_output_type(TypeGuess *p_inp } Ref<VisualScript> VisualScriptNode::get_visual_script() const { - if (scripts_used.size()) + if (scripts_used.size()) { return Ref<VisualScript>(scripts_used.front()->get()); + } return Ref<VisualScript>(); } @@ -194,8 +195,9 @@ 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) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -506,8 +508,9 @@ bool VisualScript::is_input_value_port_connected(const StringName &p_func, int p const Function &func = functions[p_func]; for (const Set<DataConnection>::Element *E = func.data_connections.front(); E; E = E->next()) { - if (E->get().to_node == p_node && E->get().to_port == p_port) + if (E->get().to_node == p_node && E->get().to_port == p_port) { return true; + } } return false; @@ -620,16 +623,21 @@ bool VisualScript::get_variable_export(const StringName &p_name) const { void VisualScript::_set_variable_info(const StringName &p_name, const Dictionary &p_info) { PropertyInfo pinfo; - if (p_info.has("type")) + if (p_info.has("type")) { pinfo.type = Variant::Type(int(p_info["type"])); - if (p_info.has("name")) + } + if (p_info.has("name")) { pinfo.name = p_info["name"]; - if (p_info.has("hint")) + } + if (p_info.has("hint")) { pinfo.hint = PropertyHint(int(p_info["hint"])); - if (p_info.has("hint_string")) + } + if (p_info.has("hint_string")) { pinfo.hint_string = p_info["hint_string"]; - if (p_info.has("usage")) + } + if (p_info.has("usage")) { pinfo.usage = p_info["usage"]; + } set_variable_info(p_name, pinfo); } @@ -662,8 +670,9 @@ void VisualScript::set_instance_base_type(const StringName &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) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -682,13 +691,15 @@ void VisualScript::rename_variable(const StringName &p_name, const StringName &p for (List<int>::Element *E = ids.front(); E; E = E->next()) { Ref<VisualScriptVariableGet> nodeget = get_node(F->get(), E->get()); if (nodeget.is_valid()) { - if (nodeget->get_variable() == p_name) + if (nodeget->get_variable() == p_name) { nodeget->set_variable(p_new_name); + } } else { Ref<VisualScriptVariableSet> nodeset = get_node(F->get(), E->get()); if (nodeset.is_valid()) { - if (nodeset->get_variable() == p_name) + if (nodeset->get_variable() == p_name) { nodeset->set_variable(p_new_name); + } } } } @@ -713,10 +724,11 @@ void VisualScript::custom_signal_add_argument(const StringName &p_func, Variant: Argument arg; arg.type = p_type; arg.name = p_name; - if (p_index < 0) + if (p_index < 0) { custom_signals[p_func].push_back(arg); - else + } else { 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) { @@ -775,8 +787,9 @@ void VisualScript::remove_custom_signal(const StringName &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) + if (p_new_name == p_name) { return; + } ERR_FAIL_COND(!String(p_new_name).is_valid_identifier()); @@ -799,8 +812,9 @@ 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()) + if (E->get().nodes.empty()) { continue; + } int last_id = E->get().nodes.back()->key(); max_id = MAX(max_id, last_id + 1); @@ -829,14 +843,16 @@ void VisualScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) } void VisualScript::_update_placeholders() { - if (placeholders.size() == 0) + 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) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); @@ -862,8 +878,9 @@ 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) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); @@ -940,8 +957,9 @@ 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)) + if (!variables.has(p_property)) { return false; + } r_value = variables[p_property].default_value; return true; @@ -973,8 +991,9 @@ bool VisualScript::has_method(const StringName &p_method) const { MethodInfo VisualScript::get_method_info(const StringName &p_method) const { const Map<StringName, Function>::Element *E = functions.find(p_method); - if (!E) + if (!E) { return MethodInfo(); + } MethodInfo mi; mi.name = E->key(); @@ -1014,8 +1033,9 @@ int VisualScript::get_member_line(const StringName &p_member) const { #ifdef TOOLS_ENABLED if (has_function(p_member)) { for (Map<int, Function::NodeData>::Element *E = functions[p_member].nodes.front(); E; E = E->next()) { - if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) + if (Object::cast_to<VisualScriptFunction>(E->get().node.ptr())) { return E->key(); + } } } #endif @@ -1092,8 +1112,9 @@ 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")) + if (d.has("base_type")) { base_type = d["base_type"]; + } variables.clear(); Array vars = d["variables"]; @@ -1184,10 +1205,11 @@ void VisualScript::_set_data(const Dictionary &p_data) { } } - if (d.has("is_tool_script")) + if (d.has("is_tool_script")) { is_tool_script = d["is_tool_script"]; - else + } else { is_tool_script = false; + } // Takes all the rpc methods rpc_functions.clear(); @@ -1390,8 +1412,9 @@ VisualScript::~VisualScript() { bool VisualScriptInstance::set(const StringName &p_name, const Variant &p_value) { Map<StringName, Variant>::Element *E = variables.find(p_name); - if (!E) + if (!E) { return false; + } E->get() = p_value; @@ -1400,8 +1423,9 @@ 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) + if (!E) { return false; + } r_ret = E->get(); return true; @@ -1409,8 +1433,9 @@ bool VisualScriptInstance::get(const StringName &p_name, Variant &r_ret) const { 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) + if (!E->get()._export) { continue; + } PropertyInfo p = E->get().info; p.name = String(E->key()); p.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; @@ -1421,13 +1446,15 @@ 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) + if (r_is_valid) { *r_is_valid = false; + } ERR_FAIL_V(Variant::NIL); } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return E->get().info.type; } @@ -1462,8 +1489,9 @@ 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()) + if (p_method == script->get_default_func()) { return false; + } return script->functions.has(p_method); } @@ -1474,8 +1502,9 @@ bool VisualScriptInstance::has_method(const StringName &p_method) const { 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) + if (pass_stack[node->pass_idx] == p_pass) { return; + } pass_stack[node->pass_idx] = p_pass; @@ -1485,8 +1514,9 @@ void VisualScriptInstance::_dependency_step(VisualScriptNodeInstance *node, int 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) + if (r_error.error != Callable::CallError::CALL_OK) { return; + } } } @@ -1599,8 +1629,9 @@ Variant VisualScriptInstance::_call_internal(const StringName &p_method, void *p } } - if (error) + if (error) { break; + } //setup output pointers @@ -1684,14 +1715,17 @@ 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) + 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) + } + if (EngineDebugger::get_script_debugger()->get_lines_left() <= 0) { do_break = true; + } } - if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source)) + if (EngineDebugger::get_script_debugger()->is_breakpoint(current_node_id, source)) { do_break = true; + } if (do_break) { VisualScriptLanguage::singleton->debug_break("Breakpoint", true); @@ -1988,17 +2022,20 @@ String VisualScriptInstance::to_string(bool *r_valid) { Variant ret = call(CoreStringNames::get_singleton()->_to_string, nullptr, 0, ce); if (ce.error == Callable::CallError::CALL_OK) { if (ret.get_type() != Variant::STRING) { - if (r_valid) + if (r_valid) { *r_valid = false; + } ERR_FAIL_V_MSG(String(), "Wrong type for " + CoreStringNames::get_singleton()->_to_string + ", must be a String."); } - if (r_valid) + if (r_valid) { *r_valid = true; + } return ret.operator String(); } } - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } @@ -2057,16 +2094,21 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o if (Object::cast_to<Node>(p_owner)) { //turn on these if they exist and base is a node Node *node = Object::cast_to<Node>(p_owner); - if (p_script->functions.has("_process")) + if (p_script->functions.has("_process")) { node->set_process(true); - if (p_script->functions.has("_physics_process")) + } + if (p_script->functions.has("_physics_process")) { node->set_physics_process(true); - if (p_script->functions.has("_input")) + } + if (p_script->functions.has("_input")) { node->set_process_input(true); - if (p_script->functions.has("_unhandled_input")) + } + if (p_script->functions.has("_unhandled_input")) { node->set_process_unhandled_input(true); - if (p_script->functions.has("_unhandled_key_input")) + } + if (p_script->functions.has("_unhandled_key_input")) { node->set_process_unhandled_key_input(true); + } } for (const Map<StringName, VisualScript::Variable>::Element *E = script->variables.front(); E; E = E->next()) { @@ -2156,10 +2198,11 @@ void VisualScriptInstance::create(const Ref<VisualScript> &p_script, Object *p_o StringName var_name; - if (Object::cast_to<VisualScriptLocalVar>(*node)) + if (Object::cast_to<VisualScriptLocalVar>(*node)) { var_name = String(Object::cast_to<VisualScriptLocalVar>(*node)->get_var_name()).strip_edges(); - else + } else { var_name = String(Object::cast_to<VisualScriptLocalVarSet>(*node)->get_var_name()).strip_edges(); + } if (!local_var_indices.has(var_name)) { local_var_indices[var_name] = function.max_stack; @@ -2491,15 +2534,17 @@ String VisualScriptLanguage::debug_get_error() const { } int VisualScriptLanguage::debug_get_stack_level_count() const { - if (_debug_parse_err_node >= 0) + 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) + if (_debug_parse_err_node >= 0) { return _debug_parse_err_node; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, -1); @@ -2509,8 +2554,9 @@ int VisualScriptLanguage::debug_get_stack_level_line(int p_level) const { } String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_node >= 0) + if (_debug_parse_err_node >= 0) { return ""; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, ""); int l = _debug_call_stack_pos - p_level - 1; @@ -2518,8 +2564,9 @@ String VisualScriptLanguage::debug_get_stack_level_function(int p_level) const { } String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_node >= 0) + if (_debug_parse_err_node >= 0) { return _debug_parse_err_file; + } ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, ""); int l = _debug_call_stack_pos - p_level - 1; @@ -2527,8 +2574,9 @@ String VisualScriptLanguage::debug_get_stack_level_source(int p_level) const { } 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) + if (_debug_parse_err_node >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); @@ -2601,15 +2649,17 @@ 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) + if (_debug_parse_err_node >= 0) { return; + } ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); int l = _debug_call_stack_pos - p_level - 1; Ref<VisualScript> vs = _call_stack[l].instance->get_script(); - if (vs.is_null()) + if (vs.is_null()) { return; + } List<StringName> vars; vs->get_variable_list(&vars); diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index d47f7f2a4b..d54b1faf42 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -424,8 +424,9 @@ public: bool set_variable(const StringName &p_variable, const Variant &p_value) { Map<StringName, Variant>::Element *E = variables.find(p_variable); - if (!E) + if (!E) { return false; + } E->get() = p_value; return true; @@ -433,8 +434,9 @@ public: bool get_variable(const StringName &p_variable, Variant *r_variable) const { const Map<StringName, Variant>::Element *E = variables.find(p_variable); - if (!E) + if (!E) { return false; + } *r_variable = E->get(); return true; @@ -527,11 +529,13 @@ 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()) + if (Thread::get_main_id() != Thread::get_caller_id()) { return; //no support for other threads than main for now + } - if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) { EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1); + } if (_debug_call_stack_pos >= _debug_max_call_stack) { //stack overflow @@ -549,11 +553,13 @@ public: } _FORCE_INLINE_ void exit_function() { - if (Thread::get_main_id() != Thread::get_caller_id()) + if (Thread::get_main_id() != Thread::get_caller_id()) { return; //no support for other threads than main for now + } - if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) + if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) { 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)"; diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 953d9a5fed..a0dcd76d10 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -111,8 +111,9 @@ 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]) + if (p_string == func_name[i]) { return BuiltinFunc(i); + } } return FUNC_MAX; @@ -269,95 +270,106 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::FLOAT, "s"); } break; case MATH_ATAN2: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "y"); - else + } else { return PropertyInfo(Variant::FLOAT, "x"); + } } break; case MATH_FMOD: case MATH_FPOSMOD: case LOGIC_MAX: case LOGIC_MIN: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "a"); - else + } else { return PropertyInfo(Variant::FLOAT, "b"); + } } break; case MATH_POSMOD: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::INT, "a"); - else + } else { return PropertyInfo(Variant::INT, "b"); + } } break; case MATH_POW: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "base"); - else + } else { return PropertyInfo(Variant::FLOAT, "exp"); + } } break; case MATH_EASE: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "s"); - else + } else { return PropertyInfo(Variant::FLOAT, "curve"); + } } break; case MATH_STEP_DECIMALS: { return PropertyInfo(Variant::FLOAT, "step"); } break; case MATH_STEPIFY: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "s"); - else + } else { return PropertyInfo(Variant::FLOAT, "steps"); + } } break; case MATH_LERP: case MATH_LERP_ANGLE: case MATH_INVERSE_LERP: case MATH_SMOOTHSTEP: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "from"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "to"); - else + } else { return PropertyInfo(Variant::FLOAT, "weight"); + } } break; case MATH_RANGE_LERP: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "value"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "istart"); - else if (p_idx == 2) + } else if (p_idx == 2) { return PropertyInfo(Variant::FLOAT, "istop"); - else if (p_idx == 3) + } else if (p_idx == 3) { return PropertyInfo(Variant::FLOAT, "ostart"); - else + } else { return PropertyInfo(Variant::FLOAT, "ostop"); + } } break; case MATH_MOVE_TOWARD: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "from"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "to"); - else + } else { return PropertyInfo(Variant::FLOAT, "delta"); + } } break; case MATH_DECTIME: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "value"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "amount"); - else + } else { return PropertyInfo(Variant::FLOAT, "step"); + } } break; case MATH_RANDOMIZE: case MATH_RAND: case MATH_RANDF: { } break; case MATH_RANDOM: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "from"); - else + } else { return PropertyInfo(Variant::FLOAT, "to"); + } } break; case MATH_SEED: case MATH_RANDSEED: { @@ -376,33 +388,37 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::FLOAT, "db"); } break; case MATH_POLAR2CARTESIAN: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "r"); - else + } else { return PropertyInfo(Variant::FLOAT, "th"); + } } break; case MATH_CARTESIAN2POLAR: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "x"); - else + } else { return PropertyInfo(Variant::FLOAT, "y"); + } } break; case MATH_WRAP: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::INT, "value"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::INT, "min"); - else + } else { return PropertyInfo(Variant::INT, "max"); + } } break; case MATH_WRAPF: case LOGIC_CLAMP: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::FLOAT, "value"); - else if (p_idx == 1) + } else if (p_idx == 1) { return PropertyInfo(Variant::FLOAT, "min"); - else + } else { return PropertyInfo(Variant::FLOAT, "max"); + } } break; case LOGIC_NEAREST_PO2: { return PropertyInfo(Variant::INT, "value"); @@ -411,16 +427,18 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const return PropertyInfo(Variant::OBJECT, "source"); } break; case FUNC_FUNCREF: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::OBJECT, "instance"); - else + } else { return PropertyInfo(Variant::STRING, "funcname"); + } } break; case TYPE_CONVERT: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::NIL, "what"); - else + } else { return PropertyInfo(Variant::STRING, "type"); + } } break; case TYPE_OF: { return PropertyInfo(Variant::NIL, "what"); @@ -445,23 +463,26 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const } break; case VAR_TO_STR: case VAR_TO_BYTES: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::NIL, "var"); - else + } else { return PropertyInfo(Variant::BOOL, "full_objects"); + } } break; case BYTES_TO_VAR: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::PACKED_BYTE_ARRAY, "bytes"); - else + } else { return PropertyInfo(Variant::BOOL, "allow_objects"); + } } break; case COLORN: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::STRING, "name"); - else + } else { return PropertyInfo(Variant::FLOAT, "alpha"); + } } break; case FUNC_MAX: { } @@ -540,10 +561,11 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case MATH_SEED: { } break; case MATH_RANDSEED: { - if (p_idx == 0) + if (p_idx == 0) { return PropertyInfo(Variant::INT, "rnd"); - else + } else { return PropertyInfo(Variant::INT, "seed"); + } } break; case MATH_DEG2RAD: case MATH_RAD2DEG: @@ -603,15 +625,17 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case STR_TO_VAR: { } break; case VAR_TO_BYTES: { - if (p_idx == 0) + if (p_idx == 0) { t = Variant::PACKED_BYTE_ARRAY; - else + } else { t = Variant::BOOL; + } } break; case BYTES_TO_VAR: { - if (p_idx == 1) + if (p_idx == 1) { t = Variant::BOOL; + } } break; case COLORN: { t = Variant::COLOR; @@ -1220,8 +1244,9 @@ void VisualScriptBuiltinFunc::_bind_methods() { String cc; for (int i = 0; i < FUNC_MAX; i++) { - if (i > 0) + if (i > 0) { cc += ","; + } cc += func_name[i]; } ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, cc), "set_func", "get_func"); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index fb8aac9a01..fea7d151df 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -66,14 +66,16 @@ protected: } bool _set(const StringName &p_name, const Variant &p_value) { - if (sig == StringName()) + 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) + if (argc == new_argc) { return true; + } undo_redo->create_action(TTR("Change Signal Arguments")); @@ -126,8 +128,9 @@ protected: } bool _get(const StringName &p_name, Variant &r_ret) const { - if (sig == StringName()) + if (sig == StringName()) { return false; + } if (p_name == "argument_count") { r_ret = script->custom_signal_get_argument_count(sig); @@ -150,8 +153,9 @@ protected: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - if (sig == StringName()) + if (sig == StringName()) { return; + } p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256")); String argt = "Variant"; @@ -200,8 +204,9 @@ protected: } bool _set(const StringName &p_name, const Variant &p_value) { - if (var == StringName()) + if (var == StringName()) { return false; + } if (String(p_name) == "value") { undo_redo->create_action(TTR("Set Variable Default Value")); @@ -262,8 +267,9 @@ protected: } bool _get(const StringName &p_name, Variant &r_ret) const { - if (var == StringName()) + if (var == StringName()) { return false; + } if (String(p_name) == "value") { r_ret = script->get_variable_default_value(var); @@ -293,8 +299,9 @@ protected: return false; } void _get_property_list(List<PropertyInfo> *p_list) const { - if (var == StringName()) + if (var == StringName()) { return; + } String argt = "Variant"; for (int i = 1; i < Variant::VARIANT_MAX; i++) { @@ -319,7 +326,7 @@ public: static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { Color color; - if (dark_theme) + if (dark_theme) { switch (p_type) { case Variant::NIL: color = Color(0.41, 0.93, 0.74); @@ -425,7 +432,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { default: color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.7, 0.7); } - else + } else { switch (p_type) { case Variant::NIL: color = Color(0.15, 0.89, 0.63); @@ -531,6 +538,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { default: color.set_hsv(p_type / float(Variant::VARIANT_MAX), 0.3, 0.3); } + } return color; } @@ -575,8 +583,9 @@ void VisualScriptEditor::_update_graph_connections() { } void VisualScriptEditor::_update_graph(int p_only_id) { - if (updating_graph) + if (updating_graph) { return; + } updating_graph = true; @@ -584,8 +593,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { if (p_only_id >= 0) { if (graph->has_node(itos(p_only_id))) { Node *gid = graph->get_node(itos(p_only_id)); - if (gid) + if (gid) { memdelete(gid); + } } } else { for (int i = 0; i < graph->get_child_count(); i++) { @@ -653,8 +663,9 @@ 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()) + if (p_only_id >= 0 && p_only_id != E->get()) { continue; + } Ref<VisualScriptNode> node = script->get_node(F->get(), E->get()); Vector2 pos = script->get_node_position(F->get(), E->get()); @@ -692,8 +703,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { btn->connect("pressed", callable_mp(this, &VisualScriptEditor::_add_input_port), varray(E->get()), CONNECT_DEFERRED); } if (nd_list->is_output_port_editable()) { - if (nd_list->is_input_port_editable()) + if (nd_list->is_input_port_editable()) { hbnc->add_spacer(); + } has_gnode_text = true; Button *btn = memnew(Button); btn->set_text(TTR("Add Output Port")); @@ -729,8 +741,9 @@ void VisualScriptEditor::_update_graph(int p_only_id) { if (node_styles.has(node->get_category())) { Ref<StyleBoxFlat> sbf = node_styles[node->get_category()]; - if (gnode->is_comment()) + if (gnode->is_comment()) { sbf = EditorNode::get_singleton()->get_theme_base()->get_theme()->get_stylebox("comment", "GraphNode"); + } Color c = sbf->get_border_color(); Color ic = c; @@ -983,8 +996,9 @@ void VisualScriptEditor::_change_port_type(int p_select, int p_id, int p_port, b StringName func = _get_function_of_node(p_id); Ref<VisualScriptLists> vsn = script->get_node(func, p_id); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } undo_redo->create_action("Change Port Type"); if (is_input) { @@ -999,23 +1013,26 @@ 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)) + if (Object::cast_to<Control>(node)) { Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller + } } void VisualScriptEditor::_port_name_focus_out(const Node *p_name_box, 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); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } String text; - if (Object::cast_to<LineEdit>(p_name_box)) + if (Object::cast_to<LineEdit>(p_name_box)) { text = Object::cast_to<LineEdit>(p_name_box)->get_text(); - else + } else { return; + } undo_redo->create_action("Change Port Name"); if (is_input) { @@ -1055,8 +1072,9 @@ void VisualScriptEditor::_update_members() { ti->set_selectable(0, true); ti->set_metadata(0, E->get()); ti->add_button(0, Control::get_theme_icon("Edit", "EditorIcons"), 0); - if (selected == E->get()) + if (selected == E->get()) { ti->select(0); + } } TreeItem *variables = members->create_item(root); @@ -1113,8 +1131,9 @@ void VisualScriptEditor::_update_members() { ti->set_selectable(0, true); ti->set_editable(0, true); ti->set_metadata(0, E->get()); - if (selected == E->get()) + if (selected == E->get()) { ti->select(0); + } } TreeItem *_signals = members->create_item(root); @@ -1131,8 +1150,9 @@ void VisualScriptEditor::_update_members() { ti->set_selectable(0, true); ti->set_editable(0, true); ti->set_metadata(0, E->get()); - if (selected == E->get()) + if (selected == E->get()) { ti->select(0); + } } String base_type = script->get_instance_base_type(); @@ -1148,8 +1168,9 @@ void VisualScriptEditor::_update_members() { } void VisualScriptEditor::_member_selected() { - if (updating_members) + if (updating_members) { return; + } TreeItem *ti = members->get_selected(); ERR_FAIL_COND(!ti); @@ -1170,8 +1191,9 @@ void VisualScriptEditor::_member_selected() { } void VisualScriptEditor::_member_edited() { - if (updating_members) + if (updating_members) { return; + } TreeItem *ti = members->get_edited(); ERR_FAIL_COND(!ti); @@ -1179,8 +1201,9 @@ void VisualScriptEditor::_member_edited() { String name = ti->get_metadata(0); String new_name = ti->get_text(0); - if (name == new_name) + if (name == new_name) { return; + } if (!new_name.is_valid_identifier()) { EditorNode::get_singleton()->show_warning(TTR("Name is not a valid identifier:") + " " + new_name); @@ -1224,8 +1247,9 @@ void VisualScriptEditor::_member_edited() { script->get_node_list(E->get(), &lst); for (List<int>::Element *F = lst.front(); F; F = F->next()) { Ref<VisualScriptFunctionCall> fncall = script->get_node(E->get(), F->get()); - if (!fncall.is_valid()) + if (!fncall.is_valid()) { continue; + } if (fncall->get_function() == name) { undo_redo->add_do_method(fncall.ptr(), "set_function", new_name); undo_redo->add_undo_method(fncall.ptr(), "set_function", name); @@ -1297,8 +1321,9 @@ void VisualScriptEditor::_create_function() { for (int i = 0; i < func_input_vbox->get_child_count(); i++) { OptionButton *opbtn = Object::cast_to<OptionButton>(func_input_vbox->get_child(i)->get_child(3)); LineEdit *lne = Object::cast_to<LineEdit>(func_input_vbox->get_child(i)->get_child(1)); - if (!opbtn || !lne) + if (!opbtn || !lne) { continue; + } Variant::Type arg_type = Variant::Type(opbtn->get_selected()); String arg_name = lne->get_text(); func_node->add_argument(arg_type, arg_name); @@ -1343,8 +1368,9 @@ void VisualScriptEditor::_add_func_input() { OptionButton *type_box = memnew(OptionButton); type_box->set_custom_minimum_size(Size2(120 * EDSCALE, 0)); - for (int i = Variant::NIL; i < Variant::VARIANT_MAX; i++) + for (int i = Variant::NIL; i < Variant::VARIANT_MAX; i++) { type_box->add_item(Variant::get_type_name(Variant::Type(i))); + } type_box->select(1); hbox->add_child(type_box); @@ -1376,8 +1402,9 @@ void VisualScriptEditor::_deselect_input_names() { int cn = func_input_vbox->get_child_count(); for (int i = 0; i < cn; i++) { LineEdit *lne = Object::cast_to<LineEdit>(func_input_vbox->get_child(i)->get_child(1)); - if (lne) + if (lne) { lne->deselect(); + } } } @@ -1466,8 +1493,9 @@ 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); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } updating_graph = true; @@ -1487,8 +1515,9 @@ 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); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } updating_graph = true; @@ -1508,8 +1537,9 @@ 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); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } updating_graph = true; @@ -1518,14 +1548,16 @@ void VisualScriptEditor::_remove_input_port(int p_id, int p_port) { int conn_from = -1, conn_port = -1; script->get_input_value_port_connection_source(func, p_id, p_port, &conn_from, &conn_port); - if (conn_from != -1) + if (conn_from != -1) { undo_redo->add_do_method(script.ptr(), "data_disconnect", func, conn_from, conn_port, p_id, p_port); + } undo_redo->add_do_method(vsn.ptr(), "remove_input_data_port", p_port); undo_redo->add_do_method(this, "_update_graph", p_id); - if (conn_from != -1) + if (conn_from != -1) { undo_redo->add_undo_method(script.ptr(), "data_connect", func, conn_from, conn_port, p_id, p_port); + } undo_redo->add_undo_method(vsn.ptr(), "add_input_data_port", vsn->get_input_value_port_info(p_port).type, vsn->get_input_value_port_info(p_port).name, p_port); undo_redo->add_undo_method(this, "_update_graph", p_id); @@ -1539,8 +1571,9 @@ 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); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } updating_graph = true; @@ -1553,8 +1586,9 @@ void VisualScriptEditor::_remove_output_port(int p_id, int p_port) { for (const List<VisualScript::DataConnection>::Element *E = data_connections.front(); E; E = E->next()) { if (E->get().from_node == p_id && E->get().from_port == p_port) { // push into the connections map - if (!conn_map.has(E->get().to_node)) + if (!conn_map.has(E->get().to_node)) { conn_map.set(E->get().to_node, Set<int>()); + } conn_map[E->get().to_node].insert(E->get().to_port); } } @@ -1582,8 +1616,9 @@ 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); - if (!vse.is_valid()) + if (!vse.is_valid()) { return; + } updating_graph = true; @@ -1595,15 +1630,17 @@ void VisualScriptEditor::_expression_text_changed(const String &p_text, int p_id undo_redo->commit_action(); Node *node = graph->get_node(itos(p_id)); - if (Object::cast_to<Control>(node)) + if (Object::cast_to<Control>(node)) { Object::cast_to<Control>(node)->set_size(Vector2(1, 1)); //shrink if text is smaller + } updating_graph = false; } Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const { - if (centered) + if (centered) { ofs = graph->get_scroll_ofs() + graph->get_size() * 0.5; + } if (graph->is_using_snap()) { int snap = graph->get_snap(); @@ -1629,8 +1666,9 @@ Vector2 VisualScriptEditor::_get_available_pos(bool centered, Vector2 ofs) const } } } - if (exists) + if (exists) { continue; + } break; } @@ -1670,8 +1708,9 @@ void VisualScriptEditor::_on_nodes_delete() { } } - if (to_erase.empty()) + if (to_erase.empty()) { return; + } undo_redo->create_action(TTR("Remove VisualScript Nodes")); @@ -1722,8 +1761,9 @@ void VisualScriptEditor::_on_nodes_duplicate() { } } - if (to_duplicate.empty()) + if (to_duplicate.empty()) { return; + } undo_redo->create_action(TTR("Duplicate VisualScript Nodes")); int idc = script->get_available_id() + 1; @@ -1783,10 +1823,11 @@ void VisualScriptEditor::_on_nodes_duplicate() { } void VisualScriptEditor::_generic_search(String p_base_type, Vector2 pos, bool node_centered) { - if (node_centered) + if (node_centered) { port_action_pos = graph->get_size() / 2.0f; - else + } else { port_action_pos = graph->get_viewport()->get_mouse_position() - graph->get_global_position(); + } new_connect_node_select->select_from_visual_script(p_base_type, false, false); // neither connecting nor reset text @@ -1795,8 +1836,9 @@ void VisualScriptEditor::_generic_search(String p_base_type, Vector2 pos, bool n pos.x = pos.x > bounds.x ? bounds.x : pos.x; pos.y = pos.y > bounds.y ? bounds.y : pos.y; - if (pos != Vector2()) + if (pos != Vector2()) { new_connect_node_select->set_position(pos); + } } void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) { @@ -1849,8 +1891,9 @@ void VisualScriptEditor::_members_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> btn = p_event; if (btn.is_valid() && btn->is_doubleclick()) { TreeItem *ti = members->get_selected(); - if (ti && ti->get_parent() == members->get_root()->get_children()) // to check if it's a function + if (ti && ti->get_parent() == members->get_root()->get_children()) { // to check if it's a function _center_on_node(ti->get_metadata(0), script->get_function_node_id(ti->get_metadata(0))); + } } } @@ -1886,8 +1929,9 @@ void VisualScriptEditor::_rename_function(const String &name, const String &new_ script->get_node_list(E->get(), &lst); for (List<int>::Element *F = lst.front(); F; F = F->next()) { Ref<VisualScriptFunctionCall> fncall = script->get_node(E->get(), F->get()); - if (!fncall.is_valid()) + if (!fncall.is_valid()) { continue; + } if (fncall->get_function() == name) { undo_redo->add_do_method(fncall.ptr(), "set_function", new_name); undo_redo->add_undo_method(fncall.ptr(), "set_function", name); @@ -1905,8 +1949,9 @@ 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()) + if (!function_name_edit->is_visible()) { return; + } Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed() && key->get_keycode() == KEY_ENTER) { @@ -1919,13 +1964,15 @@ 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) + if (!it) { return Variant(); + } String type = it->get_metadata(0); - if (type == String()) + if (type == String()) { return Variant(); + } Dictionary dd; TreeItem *root = members->get_root(); @@ -1996,18 +2043,21 @@ 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) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; @@ -2199,8 +2249,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da for (int i = 0; i < files.size(); i++) { Ref<Resource> res = ResourceLoader::load(files[i]); - if (!res.is_valid()) + if (!res.is_valid()) { continue; + } Ref<VisualScriptPreload> prnode; prnode.instance(); @@ -2305,8 +2356,9 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da Object *obj = d["object"]; - if (!obj) + if (!obj) { return; + } Node *node = Object::cast_to<Node>(obj); Vector2 ofs = graph->get_scroll_ofs() + p_point; @@ -2324,10 +2376,11 @@ 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) + if (use_get) { undo_redo->create_action(TTR("Add Getter Property")); - else + } else { undo_redo->create_action(TTR("Add Setter Property")); + } int base_id = script->get_available_id(); @@ -2365,10 +2418,11 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da undo_redo->commit_action(); } else { - if (use_get) + if (use_get) { undo_redo->create_action(TTR("Add Getter Property")); - else + } else { undo_redo->create_action(TTR("Add Setter Property")); + } int base_id = script->get_available_id(); @@ -2412,15 +2466,17 @@ 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()) + if (!vsfc.is_valid()) { return; + } vsfc->set_function(p_method); } void VisualScriptEditor::_draw_color_over_button(Object *obj, Color p_color) { Button *button = Object::cast_to<Button>(obj); - if (!button) + if (!button) { return; + } Ref<StyleBox> normal = get_theme_stylebox("normal", "Button"); button->draw_rect(Rect2(normal->get_offset(), button->get_size() - normal->get_minimum_size()), p_color); @@ -2433,8 +2489,9 @@ void VisualScriptEditor::_button_resource_previewed(const String &p_path, const ObjectID id = ud[0]; Object *obj = ObjectDB::get_instance(id); - if (!obj) + if (!obj) { return; + } Button *b = Object::cast_to<Button>(obj); ERR_FAIL_COND(!b); @@ -2491,10 +2548,11 @@ String VisualScriptEditor::get_name() { if (is_unsaved()) { name += "(*)"; } - } else if (script->get_name() != "") + } else if (script->get_name() != "") { name = script->get_name(); - else + } else { name = script->get_class() + "(" + itos(script->get_instance_id()) + ")"; + } return name; } @@ -2547,8 +2605,9 @@ void VisualScriptEditor::_center_on_node(const StringName &p_func, int p_id) { // clear selection for (int i = 0; i < graph->get_child_count(); i++) { GraphNode *gnd = Object::cast_to<GraphNode>(graph->get_child(i)); - if (gnd) + if (gnd) { gnd->set_selected(false); + } } if (gn) { @@ -2563,8 +2622,9 @@ 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) + if (p_with_error) { error_line = p_line; + } List<StringName> functions; script->get_function_list(&functions); @@ -2713,8 +2773,9 @@ 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()) + if (vnode.is_null()) { return; + } EditorNode::get_singleton()->push_item(vnode.ptr()); //edit node in inspector } @@ -2755,13 +2816,15 @@ void VisualScriptEditor::_end_node_move() { } void VisualScriptEditor::_move_node(const StringName &p_func, int p_id, const Vector2 &p_to) { - if (!script->has_function(p_func)) + if (!script->has_function(p_func)) { return; + } Node *node = graph->get_node(itos(p_id)); - if (Object::cast_to<GraphNode>(node)) + if (Object::cast_to<GraphNode>(node)) { Object::cast_to<GraphNode>(node)->set_offset(p_to); + } script->set_node_position(p_func, p_id, p_to / EDSCALE); } @@ -2829,8 +2892,9 @@ bool VisualScriptEditor::node_has_sequence_connections(const StringName &p_func, int from = E->get().from_node; int to = E->get().to_node; - if (to == p_id || from == p_id) + if (to == p_id || from == p_id) { return true; + } } return false; @@ -2845,8 +2909,9 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, bool from_seq; int from_port; - if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) + if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) { return; //can't connect this, it's invalid + } StringName to_func = _get_function_of_node(p_to.to_int()); @@ -2856,8 +2921,9 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, bool to_seq; int to_port; - if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) + if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) { return; //can't connect this, it's invalid + } ERR_FAIL_COND(from_seq != to_seq); @@ -2958,19 +3024,21 @@ void VisualScriptEditor::_graph_connected(const String &p_from, int p_from_slot, Vector2 constructor_pos; if ((to_node_pos.x - from_node_pos.x) < 0) { // to is behind from node - if (to_node_pos.x > (from_node_pos.x - to_node_size.x - 240)) + if (to_node_pos.x > (from_node_pos.x - to_node_size.x - 240)) { new_to_node_pos.x = from_node_pos.x - to_node_size.x - 240; // approx size of constructor node + padding - else + } else { new_to_node_pos.x = to_node_pos.x; + } new_to_node_pos.y = to_node_pos.y; constructor_pos.x = from_node_pos.x - 210; constructor_pos.y = to_node_pos.y; } else { // to is ahead of from node - if (to_node_pos.x < (from_node_size.x + from_node_pos.x + 240)) + if (to_node_pos.x < (from_node_size.x + from_node_pos.x + 240)) { new_to_node_pos.x = from_node_size.x + from_node_pos.x + 240; // approx size of constructor node + padding - else + } else { new_to_node_pos.x = to_node_pos.x; + } new_to_node_pos.y = to_node_pos.y; constructor_pos.x = from_node_size.x + from_node_pos.x + 10; constructor_pos.y = to_node_pos.y; @@ -3043,8 +3111,9 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl bool from_seq; int from_port; - if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) + if (!_get_out_slot(from_node, p_from_slot, from_port, from_seq)) { return; //can't connect this, it's invalid + } Ref<VisualScriptNode> to_node = script->get_node(func, p_to.to_int()); ERR_FAIL_COND(!to_node.is_valid()); @@ -3052,8 +3121,9 @@ void VisualScriptEditor::_graph_disconnected(const String &p_from, int p_from_sl bool to_seq; int to_port; - if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) + if (!_get_in_slot(to_node, p_to_slot, to_port, to_seq)) { return; //can't connect this, it's invalid + } ERR_FAIL_COND(from_seq != to_seq); @@ -3098,8 +3168,9 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, int from = E->get().from_node; int to = E->get().to_node; int out_p = E->get().from_output; - if (!seqcons.has(from)) + if (!seqcons.has(from)) { seqcons.set(from, Map<int, int>()); + } seqcons[from].insert(out_p, to); sequence_connections.insert(to); sequence_connections.insert(from); @@ -3122,12 +3193,14 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, } continue; } - if (!seen.has(conn)) + if (!seen.has(conn)) { seen.set(conn, Set<int>()); + } seen[conn].insert(E->key()); stack.push_back(conn); - if (!seqconns_to_move.has(conn)) + if (!seqconns_to_move.has(conn)) { seqconns_to_move.set(conn, Map<int, int>()); + } seqconns_to_move[conn].insert(E->key(), E->get()); conn = E->get(); nodes_to_move.insert(conn); @@ -3152,8 +3225,9 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, int out_p = E->get().from_port; int in_p = E->get().to_port; - if (!connections.has(to)) + if (!connections.has(to)) { connections.set(to, Map<int, Pair<int, int>>()); + } connections[to].insert(in_p, Pair<int, int>(from, out_p)); } @@ -3190,12 +3264,14 @@ void VisualScriptEditor::_move_nodes_with_rescan(const StringName &p_func_from, } } - if (!seen.has(id)) + if (!seen.has(id)) { seen.set(id, Set<int>()); + } seen[id].insert(E->key()); stack.push_back(id); - if (!dataconns_to_move.has(id)) + if (!dataconns_to_move.has(id)) { dataconns_to_move.set(id, Map<int, Pair<int, int>>()); + } dataconns_to_move[id].insert(E->key(), Pair<int, int>(E->get().first, E->get().second)); id = E->get().first; nodes_to_be_added.insert(id); @@ -3293,14 +3369,16 @@ 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) + if (!gn) { return; + } StringName func = _get_function_of_node(p_from.to_int()); Ref<VisualScriptNode> vsn = script->get_node(func, p_from.to_int()); - if (!vsn.is_valid()) + if (!vsn.is_valid()) { return; + } port_action_pos = p_release_pos; @@ -3319,8 +3397,9 @@ VisualScriptNode::TypeGuess VisualScriptEditor::_guess_output_type(int p_port_ac VisualScriptNode::TypeGuess tg; tg.type = Variant::NIL; - if (visited_nodes.has(p_port_action_node)) + if (visited_nodes.has(p_port_action_node)) { return tg; //no loop + } visited_nodes.insert(p_port_action_node); @@ -3486,8 +3565,9 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri if (p_category == "visualscript") { Ref<VisualScriptNode> vnode_new = VisualScriptLanguage::singleton->create_node_from_name(p_text); Ref<VisualScriptNode> vnode_old; - if (port_node_exists) + if (port_node_exists) { vnode_old = script->get_node(func, port_action_node); + } int new_id = script->get_available_id(); if (Object::cast_to<VisualScriptOperator>(vnode_new.ptr()) && vnode_old.is_valid()) { @@ -3578,8 +3658,9 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri undo_redo->add_undo_method(this, "_update_graph", new_id); undo_redo->commit_action(); - if (script_prop_set.is_valid()) + if (script_prop_set.is_valid()) { script_prop_set->set_property(p_text); + } port_action_new_node = new_id; @@ -3690,8 +3771,9 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri } } _update_graph(port_action_new_node); - if (port_node_exists) + if (port_node_exists) { _update_graph_connections(); + } } void VisualScriptEditor::connect_seq(Ref<VisualScriptNode> vnode_old, Ref<VisualScriptNode> vnode_new, int new_id) { @@ -3805,8 +3887,9 @@ 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()) + if (p_func != StringName()) { func = p_func; + } Ref<VisualScriptNode> vnode = VisualScriptLanguage::singleton->create_node_from_name(p_text); int new_id = script->get_available_id(); @@ -3821,8 +3904,9 @@ 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()) + if (vsn.is_null()) { return; + } undo_redo->create_action(TTR("Change Input Value")); undo_redo->add_do_method(vsn.ptr(), "set_default_input_value", editing_input, default_value_edit->get_variant()); @@ -3835,8 +3919,9 @@ 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()) + if (vsn.is_null()) { return; + } PropertyInfo pinfo = vsn->get_input_value_port_info(p_input_port); Variant existing = vsn->get_default_input_value(p_input_port); @@ -3867,10 +3952,11 @@ void VisualScriptEditor::_default_value_edited(Node *p_button, int p_id, int p_i } if (default_value_edit->edit(nullptr, pinfo.name, pinfo.type, existing, pinfo.hint, pinfo.hint_string)) { - if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) + if (pinfo.hint == PROPERTY_HINT_MULTILINE_TEXT) { default_value_edit->popup_centered_ratio(); - else + } else { default_value_edit->popup(); + } } editing_id = p_id; @@ -3950,8 +4036,9 @@ void VisualScriptEditor::_notification(int p_what) { } void VisualScriptEditor::_graph_ofs_changed(const Vector2 &p_ofs) { - if (updating_graph || !script.is_valid()) + if (updating_graph || !script.is_valid()) { return; + } updating_graph = true; @@ -3964,19 +4051,22 @@ 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) + if (updating_graph) { return; + } StringName func = _get_function_of_node(p_node); Ref<VisualScriptComment> vsc = script->get_node(func, p_node); - if (vsc.is_null()) + if (vsc.is_null()) { return; + } Node *node = graph->get_node(itos(p_node)); GraphNode *gn = Object::cast_to<GraphNode>(node); - if (!gn) + if (!gn) { return; + } updating_graph = true; @@ -4028,8 +4118,9 @@ void VisualScriptEditor::_menu_option(int p_what) { } break; case EDIT_COPY_NODES: case EDIT_CUT_NODES: { - if (!script->has_function(default_func)) + if (!script->has_function(default_func)) { break; + } clipboard->nodes.clear(); clipboard->data_connections.clear(); @@ -4056,8 +4147,9 @@ void VisualScriptEditor::_menu_option(int p_what) { } } - if (clipboard->nodes.empty()) + if (clipboard->nodes.empty()) { break; + } for (Set<String>::Element *F = funcs.front(); F; F = F->next()) { List<VisualScript::SequenceConnection> sequence_connections; @@ -4086,8 +4178,9 @@ void VisualScriptEditor::_menu_option(int p_what) { } break; case EDIT_PASTE_NODES: { - if (!script->has_function(default_func)) + if (!script->has_function(default_func)) { break; + } if (clipboard->nodes.empty()) { EditorNode::get_singleton()->show_warning(TTR("Clipboard is empty!")); @@ -4199,9 +4292,9 @@ void VisualScriptEditor::_menu_option(int p_what) { Set<int> end_nodes; if (nodes.size() == 1) { Ref<VisualScriptNode> nd = script->get_node(function, nodes.front()->key()); - if (nd.is_valid() && nd->has_input_sequence_port()) + if (nd.is_valid() && nd->has_input_sequence_port()) { start_node = nodes.front()->key(); - else { + } else { EditorNode::get_singleton()->show_warning(TTR("Select at least one node with sequence port.")); return; } @@ -4230,9 +4323,9 @@ void VisualScriptEditor::_menu_option(int p_what) { } } Ref<VisualScriptNode> nd = script->get_node(function, top_nd); - if (nd.is_valid() && nd->has_input_sequence_port()) + if (nd.is_valid() && nd->has_input_sequence_port()) { start_node = top_nd; - else { + } else { EditorNode::get_singleton()->show_warning(TTR("Select at least one node with sequence port.")); return; } @@ -4837,8 +4930,9 @@ static ScriptEditorBase *create_editor(const RES &p_resource) { VisualScriptEditor::Clipboard *VisualScriptEditor::clipboard = nullptr; void VisualScriptEditor::free_clipboard() { - if (clipboard) + if (clipboard) { memdelete(clipboard); + } } static void register_editor_callback() { diff --git a/modules/visual_script/visual_script_expression.cpp b/modules/visual_script/visual_script_expression.cpp index ee166082bd..bd41117497 100644 --- a/modules/visual_script/visual_script_expression.cpp +++ b/modules/visual_script/visual_script_expression.cpp @@ -466,8 +466,9 @@ Error VisualScriptExpression::_get_token(Token &r_token) { exp_beg = true; } else if ((c == '-' || c == '+') && !exp_sign && !exp_beg) { - if (c == '-') + if (c == '-') { is_float = true; + } exp_sign = true; } else { @@ -476,8 +477,9 @@ Error VisualScriptExpression::_get_token(Token &r_token) { } break; } - if (reading == READING_DONE) + if (reading == READING_DONE) { break; + } num += String::chr(c); c = GET_CHAR(); } @@ -486,10 +488,11 @@ Error VisualScriptExpression::_get_token(Token &r_token) { r_token.type = TK_CONSTANT; - if (is_float) + if (is_float) { r_token.value = num.to_double(); - else + } else { r_token.value = num.to_int(); + } return OK; } else if ((cchar >= 'A' && cchar <= 'Z') || (cchar >= 'a' && cchar <= 'z') || cchar == '_') { @@ -618,8 +621,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { Token tk; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } switch (tk.type) { case TK_CURLY_BRACKET_OPEN: { @@ -635,8 +639,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } dn->dict.push_back(expr2); _get_token(tk); @@ -646,8 +651,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } dn->dict.push_back(expr2); @@ -678,8 +684,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } an->array.push_back(expr2); cofs = str_ofs; @@ -698,8 +705,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { case TK_PARENTHESIS_OPEN: { //a suexpression ENode *e = _parse_expression(); - if (error_set) + if (error_set) { return nullptr; + } _get_token(tk); if (tk.type != TK_PARENTHESIS_CLOSE) { _set_error("Expected ')'"); @@ -759,8 +767,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } constructor->arguments.push_back(expr2); @@ -799,8 +808,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } bifunc->arguments.push_back(expr2); @@ -849,8 +859,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { while (true) { int cofs2 = str_ofs; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } bool done = false; @@ -862,8 +873,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { index->base = expr; ENode *what = _parse_expression(); - if (!what) + if (!what) { return nullptr; + } index->index = what; @@ -902,8 +914,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { str_ofs = cofs3; //revert //parse an expression ENode *expr2 = _parse_expression(); - if (!expr2) + if (!expr2) { return nullptr; + } func_call->arguments.push_back(expr2); @@ -936,8 +949,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } break; } - if (done) + if (done) { break; + } } //push expression @@ -952,8 +966,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { int cofs = str_ofs; _get_token(tk); - if (error_set) + if (error_set) { return nullptr; + } Variant::Operator op = Variant::OP_MAX; @@ -1216,8 +1231,9 @@ VisualScriptExpression::ENode *VisualScriptExpression::_parse_expression() { } bool VisualScriptExpression::_compile_expression() { - if (!expression_dirty) + if (!expression_dirty) { return error_set; + } if (nodes) { memdelete(nodes); @@ -1270,15 +1286,17 @@ public: Variant a; bool ret = _execute(p_inputs, op->nodes[0], a, r_error_str, ce); - if (ret) + if (ret) { return true; + } Variant b; if (op->nodes[1]) { ret = _execute(p_inputs, op->nodes[1], b, r_error_str, ce); - if (ret) + if (ret) { return true; + } } bool valid = true; @@ -1294,14 +1312,16 @@ public: Variant base; bool ret = _execute(p_inputs, index->base, base, r_error_str, ce); - if (ret) + if (ret) { return true; + } Variant idx; ret = _execute(p_inputs, index->index, idx, r_error_str, ce); - if (ret) + if (ret) { return true; + } bool valid; r_ret = base.get(idx, &valid); @@ -1316,8 +1336,9 @@ public: Variant base; bool ret = _execute(p_inputs, index->base, base, r_error_str, ce); - if (ret) + if (ret) { return true; + } bool valid; r_ret = base.get_named(index->name, &valid); @@ -1335,8 +1356,9 @@ public: 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) + if (ret) { return true; + } arr[i] = value; } @@ -1350,13 +1372,15 @@ public: 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) + if (ret) { return true; + } Variant value; ret = _execute(p_inputs, dictionary->dict[i + 1], value, r_error_str, ce); - if (ret) + if (ret) { return true; + } d[key] = value; } @@ -1374,8 +1398,9 @@ public: 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) + if (ret) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } @@ -1399,8 +1424,9 @@ public: 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) + if (ret) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } @@ -1418,8 +1444,9 @@ public: Variant base; bool ret = _execute(p_inputs, call->base, base, r_error_str, ce); - if (ret) + if (ret) { return true; + } Vector<Variant> arr; Vector<const Variant *> argp; @@ -1429,8 +1456,9 @@ public: 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) + if (ret2) { return true; + } arr.write[i] = value; argp.write[i] = &arr[i]; } diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index ed0857ab9f..dee0213d54 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -104,8 +104,9 @@ class VisualScriptExpression : public VisualScriptNode { }; void _set_error(const String &p_err) { - if (error_set) + if (error_set) { return; + } error_str = p_err; error_set = true; } diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index 96616c281e..3ed20fab35 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -78,8 +78,9 @@ String VisualScriptReturn::get_text() const { } void VisualScriptReturn::set_return_type(Variant::Type p_type) { - if (type == p_type) + if (type == p_type) { return; + } type = p_type; ports_changed_notify(); } @@ -89,8 +90,9 @@ Variant::Type VisualScriptReturn::get_return_type() const { } void VisualScriptReturn::set_enable_return_value(bool p_enable) { - if (with_value == p_enable) + if (with_value == p_enable) { return; + } with_value = p_enable; ports_changed_notify(); @@ -178,12 +180,13 @@ int VisualScriptCondition::get_output_value_port_count() const { } String VisualScriptCondition::get_output_sequence_port_text(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "true"; - else if (p_port == 1) + } else if (p_port == 1) { return "false"; - else + } else { return "done"; + } } PropertyInfo VisualScriptCondition::get_input_value_port_info(int p_idx) const { @@ -218,12 +221,13 @@ 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) + if (p_start_mode == START_MODE_CONTINUE_SEQUENCE) { return 2; - else if (p_inputs[0]->operator bool()) + } else if (p_inputs[0]->operator bool()) { return 0 | STEP_FLAG_PUSH_STACK_BIT; - else + } else { return 1 | STEP_FLAG_PUSH_STACK_BIT; + } } }; @@ -258,10 +262,11 @@ int VisualScriptWhile::get_output_value_port_count() const { } String VisualScriptWhile::get_output_sequence_port_text(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "repeat"; - else + } else { return "exit"; + } } PropertyInfo VisualScriptWhile::get_input_value_port_info(int p_idx) const { @@ -298,10 +303,11 @@ 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) { bool keep_going = p_inputs[0]->operator bool(); - if (keep_going) + if (keep_going) { return 0 | STEP_FLAG_PUSH_STACK_BIT; - else + } else { return 1; + } } }; @@ -336,10 +342,11 @@ int VisualScriptIterator::get_output_value_port_count() const { } String VisualScriptIterator::get_output_sequence_port_text(int p_port) const { - if (p_port == 0) + if (p_port == 0) { return "each"; - else + } else { return "exit"; + } } PropertyInfo VisualScriptIterator::get_input_value_port_info(int p_idx) const { @@ -388,8 +395,9 @@ public: return 0; } - if (!can_iter) + if (!can_iter) { return 1; //nothing to iterate + } *p_outputs[0] = p_working_mem[0].iter_get(p_working_mem[1], valid); @@ -410,8 +418,9 @@ public: return 0; } - if (!can_iter) + if (!can_iter) { return 1; //nothing to iterate + } *p_outputs[0] = p_working_mem[0].iter_get(p_working_mem[1], valid); @@ -478,8 +487,9 @@ String VisualScriptSequence::get_text() const { void VisualScriptSequence::set_steps(int p_steps) { ERR_FAIL_COND(p_steps < 1); - if (steps == p_steps) + if (steps == p_steps) { return; + } steps = p_steps; ports_changed_notify(); @@ -515,9 +525,9 @@ public: *p_outputs[0] = step; - if (step + 1 == steps) + if (step + 1 == steps) { return step; - else { + } else { p_working_mem[0] = step + 1; return step | STEP_FLAG_PUSH_STACK_BIT; } @@ -557,8 +567,9 @@ int VisualScriptSwitch::get_output_value_port_count() const { } String VisualScriptSwitch::get_output_sequence_port_text(int p_port) const { - if (p_port == case_values.size()) + if (p_port == case_values.size()) { return "done"; + } return String(); } @@ -566,8 +577,9 @@ 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 + } else { return PropertyInfo(Variant::NIL, "input"); + } } PropertyInfo VisualScriptSwitch::get_output_value_port_info(int p_idx) const { @@ -708,15 +720,17 @@ String VisualScriptTypeCast::get_caption() const { } String VisualScriptTypeCast::get_text() const { - if (script != String()) + if (script != String()) { return "Is " + script.get_file() + "?"; - else + } else { return "Is " + base_type + "?"; + } } void VisualScriptTypeCast::set_base_type(const StringName &p_type) { - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; _change_notify(); @@ -728,8 +742,9 @@ StringName VisualScriptTypeCast::get_base_type() const { } void VisualScriptTypeCast::set_base_script(const String &p_path) { - if (script == p_path) + if (script == p_path) { return; + } script = p_path; _change_notify(); @@ -806,8 +821,9 @@ public: if (ClassDB::is_parent_class(obj->get_class_name(), base_type)) { *p_outputs[0] = *p_inputs[0]; //copy return 0; - } else + } else { return 1; + } } }; @@ -833,8 +849,9 @@ void VisualScriptTypeCast::_bind_methods() { String script_ext_hint; for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) { - if (script_ext_hint != String()) + if (script_ext_hint != String()) { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index e7cb2f5473..f13377f3c8 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -42,10 +42,11 @@ ////////////////////////////////////////// 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))) + 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 + } else { return 1; + } } bool VisualScriptFunctionCall::has_input_sequence_port() const { @@ -54,18 +55,21 @@ bool VisualScriptFunctionCall::has_input_sequence_port() const { #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) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; @@ -75,27 +79,32 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Node *VisualScriptFunctionCall::_get_base_node() const { #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return nullptr; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return nullptr; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return nullptr; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return nullptr; + } - if (!script_node->has_node(base_path)) + if (!script_node->has_node(base_path)) { return nullptr; + } Node *path_to = script_node->get_node(base_path); @@ -107,12 +116,13 @@ Node *VisualScriptFunctionCall::_get_base_node() const { } StringName VisualScriptFunctionCall::_get_base_type() const { - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) + 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()) { + } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { Node *path = _get_base_node(); - if (path) + if (path) { return path->get_class(); + } } return base_type; @@ -146,8 +156,9 @@ int VisualScriptFunctionCall::get_output_value_port_count() const { MethodBind *mb = ClassDB::get_method(_get_base_type(), function); if (mb) { ret = mb->has_return() ? 1 : 0; - } else + } else { ret = 1; //it is assumed that script always returns something + } if (call_mode == CALL_MODE_INSTANCE) { ret++; @@ -244,16 +255,18 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con } String VisualScriptFunctionCall::get_caption() const { - if (call_mode == CALL_MODE_SELF) + if (call_mode == CALL_MODE_SELF) { return " " + String(function) + "()"; - if (call_mode == CALL_MODE_SINGLETON) + } + if (call_mode == CALL_MODE_SINGLETON) { return String(singleton) + ":" + String(function) + "()"; - else if (call_mode == CALL_MODE_BASIC_TYPE) + } else if (call_mode == CALL_MODE_BASIC_TYPE) { return Variant::get_type_name(basic_type) + "." + String(function) + "()"; - else if (call_mode == CALL_MODE_NODE_PATH) + } else if (call_mode == CALL_MODE_NODE_PATH) { return " [" + String(base_path.simplified()) + "]." + String(function) + "()"; - else + } else { return " " + base_type + "." + String(function) + "()"; + } } String VisualScriptFunctionCall::get_text() const { @@ -264,8 +277,9 @@ String VisualScriptFunctionCall::get_text() const { } void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { - if (basic_type == p_type) + if (basic_type == p_type) { return; + } basic_type = p_type; _change_notify(); @@ -277,8 +291,9 @@ Variant::Type VisualScriptFunctionCall::get_basic_type() const { } void VisualScriptFunctionCall::set_base_type(const StringName &p_type) { - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; _change_notify(); @@ -290,8 +305,9 @@ StringName VisualScriptFunctionCall::get_base_type() const { } void VisualScriptFunctionCall::set_base_script(const String &p_path) { - if (base_script == p_path) + if (base_script == p_path) { return; + } base_script = p_path; _change_notify(); @@ -303,8 +319,9 @@ String VisualScriptFunctionCall::get_base_script() const { } void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { - if (singleton == p_type) + if (singleton == p_type) { return; + } singleton = p_type; Object *obj = Engine::get_singleton()->get_singleton_object(singleton); @@ -395,8 +412,9 @@ void VisualScriptFunctionCall::_update_method_cache() { } void VisualScriptFunctionCall::set_function(const StringName &p_type) { - if (function == p_type) + if (function == p_type) { return; + } function = p_type; @@ -417,8 +435,9 @@ StringName VisualScriptFunctionCall::get_function() const { } void VisualScriptFunctionCall::set_base_path(const NodePath &p_type) { - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; _change_notify(); @@ -430,8 +449,9 @@ NodePath VisualScriptFunctionCall::get_base_path() const { } void VisualScriptFunctionCall::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; _change_notify(); @@ -443,16 +463,18 @@ VisualScriptFunctionCall::CallMode VisualScriptFunctionCall::get_call_mode() con } void VisualScriptFunctionCall::set_use_default_args(int p_amount) { - if (use_default_args == p_amount) + if (use_default_args == p_amount) { return; + } use_default_args = p_amount; ports_changed_notify(); } void VisualScriptFunctionCall::set_rpc_call_mode(VisualScriptFunctionCall::RPCCallMode p_mode) { - if (rpc_call_mode == p_mode) + if (rpc_call_mode == p_mode) { return; + } rpc_call_mode = p_mode; ports_changed_notify(); _change_notify(); @@ -511,8 +533,9 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const property.hint = PROPERTY_HINT_ENUM; String sl; for (List<Engine::Singleton>::Element *E = names.front(); E; E = E->next()) { - if (sl != String()) + if (sl != String()) { sl += ","; + } sl += E->get().name; } property.hint_string = sl; @@ -641,8 +664,9 @@ void VisualScriptFunctionCall::_bind_methods() { String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { bt += ","; + } bt += Variant::get_type_name(Variant::Type(i)); } @@ -654,8 +678,9 @@ void VisualScriptFunctionCall::_bind_methods() { String script_ext_hint; for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) { - if (script_ext_hint != String()) + if (script_ext_hint != String()) { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } @@ -703,12 +728,14 @@ 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) + if (!p_base) { return false; + } Node *node = Object::cast_to<Node>(p_base); - if (!node) + if (!node) { return false; + } int to_id = 0; bool reliable = true; @@ -881,28 +908,33 @@ bool VisualScriptPropertySet::has_input_sequence_port() const { Node *VisualScriptPropertySet::_get_base_node() const { #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return nullptr; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return nullptr; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return nullptr; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return nullptr; + } - if (!script_node->has_node(base_path)) + if (!script_node->has_node(base_path)) { return nullptr; + } Node *path_to = script_node->get_node(base_path); @@ -914,12 +946,13 @@ Node *VisualScriptPropertySet::_get_base_node() const { } StringName VisualScriptPropertySet::_get_base_type() const { - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) + 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()) { + } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { Node *path = _get_base_node(); - if (path) + if (path) { return path->get_class(); + } } return base_type; @@ -1028,8 +1061,9 @@ void VisualScriptPropertySet::_update_base_type() { } void VisualScriptPropertySet::set_basic_type(Variant::Type p_type) { - if (basic_type == p_type) + if (basic_type == p_type) { return; + } basic_type = p_type; _change_notify(); @@ -1042,8 +1076,9 @@ Variant::Type VisualScriptPropertySet::get_basic_type() const { } void VisualScriptPropertySet::set_base_type(const StringName &p_type) { - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; _change_notify(); @@ -1055,8 +1090,9 @@ StringName VisualScriptPropertySet::get_base_type() const { } void VisualScriptPropertySet::set_base_script(const String &p_path) { - if (base_script == p_path) + if (base_script == p_path) { return; + } base_script = p_path; _change_notify(); @@ -1068,11 +1104,13 @@ String VisualScriptPropertySet::get_base_script() const { } void VisualScriptPropertySet::_update_cache() { - if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop())) + if (!Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop())) { return; + } - if (!Engine::get_singleton()->is_editor_hint()) //only update cache if editor exists, it's pointless otherwise + if (!Engine::get_singleton()->is_editor_hint()) { //only update cache if editor exists, it's pointless otherwise return; + } if (call_mode == CALL_MODE_BASIC_TYPE) { //not super efficient.. @@ -1145,8 +1183,9 @@ void VisualScriptPropertySet::_update_cache() { } void VisualScriptPropertySet::set_property(const StringName &p_type) { - if (property == p_type) + if (property == p_type) { return; + } property = p_type; index = StringName(); @@ -1160,8 +1199,9 @@ StringName VisualScriptPropertySet::get_property() const { } void VisualScriptPropertySet::set_base_path(const NodePath &p_type) { - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; _update_base_type(); @@ -1174,8 +1214,9 @@ NodePath VisualScriptPropertySet::get_base_path() const { } void VisualScriptPropertySet::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; _update_base_type(); @@ -1196,8 +1237,9 @@ Dictionary VisualScriptPropertySet::_get_type_cache() const { } void VisualScriptPropertySet::set_index(const StringName &p_type) { - if (index == p_type) + if (index == p_type) { return; + } index = p_type; _update_cache(); _change_notify(); @@ -1210,8 +1252,9 @@ StringName VisualScriptPropertySet::get_index() const { void VisualScriptPropertySet::set_assign_op(AssignOp p_op) { ERR_FAIL_INDEX(p_op, ASSIGN_OP_MAX); - if (assign_op == p_op) + if (assign_op == p_op) { return; + } assign_op = p_op; _update_cache(); @@ -1304,8 +1347,9 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { property.hint = PROPERTY_HINT_ENUM; property.hint_string = options; property.type = Variant::STRING; - if (options == "") + if (options == "") { property.usage = 0; //hide if type has no usable index + } } } @@ -1339,8 +1383,9 @@ void VisualScriptPropertySet::_bind_methods() { String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { bt += ","; + } bt += Variant::get_type_name(Variant::Type(i)); } @@ -1352,8 +1397,9 @@ void VisualScriptPropertySet::_bind_methods() { String script_ext_hint; for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) { - if (script_ext_hint != String()) + if (script_ext_hint != String()) { script_ext_hint += ","; + } script_ext_hint += "*." + E->get(); } @@ -1602,28 +1648,33 @@ void VisualScriptPropertyGet::_update_base_type() { Node *VisualScriptPropertyGet::_get_base_node() const { #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return nullptr; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return nullptr; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return nullptr; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return nullptr; + } - if (!script_node->has_node(base_path)) + if (!script_node->has_node(base_path)) { return nullptr; + } Node *path_to = script_node->get_node(base_path); @@ -1635,12 +1686,13 @@ Node *VisualScriptPropertyGet::_get_base_node() const { } StringName VisualScriptPropertyGet::_get_base_type() const { - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) + 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()) { + } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { Node *path = _get_base_node(); - if (path) + if (path) { return path->get_class(); + } } return base_type; @@ -1701,8 +1753,9 @@ String VisualScriptPropertyGet::get_text() const { } void VisualScriptPropertyGet::set_base_type(const StringName &p_type) { - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; _change_notify(); @@ -1714,8 +1767,9 @@ StringName VisualScriptPropertyGet::get_base_type() const { } void VisualScriptPropertyGet::set_base_script(const String &p_path) { - if (base_script == p_path) + if (base_script == p_path) { return; + } base_script = p_path; _change_notify(); @@ -1808,8 +1862,9 @@ void VisualScriptPropertyGet::_update_cache() { } void VisualScriptPropertyGet::set_property(const StringName &p_type) { - if (property == p_type) + if (property == p_type) { return; + } property = p_type; @@ -1823,8 +1878,9 @@ StringName VisualScriptPropertyGet::get_property() const { } void VisualScriptPropertyGet::set_base_path(const NodePath &p_type) { - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; _change_notify(); @@ -1837,8 +1893,9 @@ NodePath VisualScriptPropertyGet::get_base_path() const { } void VisualScriptPropertyGet::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; _change_notify(); @@ -1851,8 +1908,9 @@ VisualScriptPropertyGet::CallMode VisualScriptPropertyGet::get_call_mode() const } void VisualScriptPropertyGet::set_basic_type(Variant::Type p_type) { - if (basic_type == p_type) + if (basic_type == p_type) { return; + } basic_type = p_type; _change_notify(); @@ -1872,8 +1930,9 @@ Variant::Type VisualScriptPropertyGet::_get_type_cache() const { } void VisualScriptPropertyGet::set_index(const StringName &p_type) { - if (index == p_type) + if (index == p_type) { return; + } index = p_type; _update_cache(); _change_notify(); @@ -1964,8 +2023,9 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { property.hint = PROPERTY_HINT_ENUM; property.hint_string = options; property.type = Variant::STRING; - if (options == "") + if (options == "") { property.usage = 0; //hide if type has no usable index + } } } @@ -1996,8 +2056,9 @@ void VisualScriptPropertyGet::_bind_methods() { String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { bt += ","; + } bt += Variant::get_type_name(Variant::Type(i)); } @@ -2009,8 +2070,9 @@ void VisualScriptPropertyGet::_bind_methods() { String script_ext_hint; for (List<String>::Element *E = script_extensions.front(); E; E = E->next()) { - if (script_ext_hint != String()) + if (script_ext_hint != String()) { script_ext_hint += ","; + } script_ext_hint += "." + E->get(); } @@ -2149,8 +2211,9 @@ bool VisualScriptEmitSignal::has_input_sequence_port() const { int VisualScriptEmitSignal::get_input_value_port_count() const { Ref<VisualScript> vs = get_visual_script(); if (vs.is_valid()) { - if (!vs->has_custom_signal(name)) + if (!vs->has_custom_signal(name)) { return 0; + } return vs->custom_signal_get_argument_count(name); } @@ -2169,8 +2232,9 @@ String VisualScriptEmitSignal::get_output_sequence_port_text(int p_port) const { 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)) + if (!vs->has_custom_signal(name)) { return PropertyInfo(); + } return PropertyInfo(vs->custom_signal_get_argument_type(name, p_idx), vs->custom_signal_get_argument_name(name, p_idx)); } @@ -2187,8 +2251,9 @@ String VisualScriptEmitSignal::get_caption() const { } void VisualScriptEmitSignal::set_signal(const StringName &p_type) { - if (name == p_type) + if (name == p_type) { return; + } name = p_type; @@ -2213,8 +2278,9 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { String ml; for (List<StringName>::Element *E = sigs.front(); E; E = E->next()) { - if (ml != String()) + if (ml != String()) { ml += ","; + } ml += E->get(); } diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 8d35da2685..87aa64211e 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -46,8 +46,9 @@ 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) + if (argc == new_argc) { return true; + } arguments.resize(new_argc); @@ -213,10 +214,11 @@ void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_na arg.type = p_type; arg.hint = p_hint; arg.hint_string = p_hint_string; - if (p_index >= 0) + if (p_index >= 0) { arguments.insert(p_index, arg); - else + } else { arguments.push_back(arg); + } ports_changed_notify(); } @@ -339,8 +341,9 @@ int VisualScriptFunction::get_stack_size() const { ////////////////////////////////////////// int VisualScriptLists::get_output_sequence_port_count() const { - if (sequenced) + if (sequenced) { return 1; + } return 0; } @@ -407,8 +410,9 @@ 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) + if (argc == new_argc) { return true; + } inputports.resize(new_argc); @@ -442,8 +446,9 @@ 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) + if (argc == new_argc) { return true; + } outputports.resize(new_argc); @@ -559,24 +564,27 @@ 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()) + if (!is_input_port_editable()) { return; + } Port inp; inp.name = p_name; inp.type = p_type; - if (p_index >= 0) + if (p_index >= 0) { inputports.insert(p_index, inp); - else + } else { inputports.push_back(inp); + } ports_changed_notify(); _change_notify(); } void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) { - if (!is_input_port_type_editable()) + if (!is_input_port_type_editable()) { return; + } ERR_FAIL_INDEX(p_idx, inputports.size()); @@ -586,8 +594,9 @@ void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type } void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) { - if (!is_input_port_name_editable()) + if (!is_input_port_name_editable()) { return; + } ERR_FAIL_INDEX(p_idx, inputports.size()); @@ -597,8 +606,9 @@ void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name } void VisualScriptLists::remove_input_data_port(int p_argidx) { - if (!is_input_port_editable()) + if (!is_input_port_editable()) { return; + } ERR_FAIL_INDEX(p_argidx, inputports.size()); @@ -610,24 +620,27 @@ 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()) + if (!is_output_port_editable()) { return; + } Port out; out.name = p_name; out.type = p_type; - if (p_index >= 0) + if (p_index >= 0) { outputports.insert(p_index, out); - else + } else { outputports.push_back(out); + } ports_changed_notify(); _change_notify(); } void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) { - if (!is_output_port_type_editable()) + if (!is_output_port_type_editable()) { return; + } ERR_FAIL_INDEX(p_idx, outputports.size()); @@ -637,8 +650,9 @@ void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_typ } void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) { - if (!is_output_port_name_editable()) + if (!is_output_port_name_editable()) { return; + } ERR_FAIL_INDEX(p_idx, outputports.size()); @@ -648,8 +662,9 @@ void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_nam } void VisualScriptLists::remove_output_data_port(int p_argidx) { - if (!is_output_port_editable()) + if (!is_output_port_editable()) { return; + } ERR_FAIL_INDEX(p_argidx, outputports.size()); @@ -661,8 +676,9 @@ void VisualScriptLists::remove_output_data_port(int p_argidx) { // sequences void VisualScriptLists::set_sequenced(bool p_enable) { - if (sequenced == p_enable) + if (sequenced == p_enable) { return; + } sequenced = p_enable; ports_changed_notify(); } @@ -694,8 +710,9 @@ void VisualScriptLists::_bind_methods() { ////////////////////////////////////////// int VisualScriptComposeArray::get_output_sequence_port_count() const { - if (sequenced) + if (sequenced) { return 1; + } return 0; } @@ -747,8 +764,9 @@ 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 (input_count > 0) { Array arr; - for (int i = 0; i < input_count; i++) + for (int i = 0; i < input_count; i++) { arr.push_back((*p_inputs[i])); + } Variant va = Variant(arr); *p_outputs[0] = va; @@ -832,8 +850,9 @@ PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const { PropertyInfo pinfo; pinfo.name = p_idx == 0 ? "A" : "B"; pinfo.type = port_types[op][p_idx]; - if (pinfo.type == Variant::NIL) + if (pinfo.type == Variant::NIL) { pinfo.type = typed; + } return pinfo; } @@ -874,8 +893,9 @@ PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const { PropertyInfo pinfo; pinfo.name = ""; pinfo.type = port_types[op]; - if (pinfo.type == Variant::NIL) + if (pinfo.type == Variant::NIL) { pinfo.type = typed; + } return pinfo; } @@ -949,8 +969,9 @@ String VisualScriptOperator::get_caption() const { } void VisualScriptOperator::set_operator(Variant::Operator p_op) { - if (op == p_op) + if (op == p_op) { return; + } op = p_op; ports_changed_notify(); } @@ -960,8 +981,9 @@ Variant::Operator VisualScriptOperator::get_operator() const { } void VisualScriptOperator::set_typed(Variant::Type p_op) { - if (typed == p_op) + if (typed == p_op) { return; + } typed = p_op; ports_changed_notify(); @@ -980,8 +1002,9 @@ void VisualScriptOperator::_bind_methods() { String types; for (int i = 0; i < Variant::OP_MAX; i++) { - if (i > 0) + if (i > 0) { types += ","; + } types += op_names[i]; } @@ -1014,10 +1037,11 @@ public: if (p_outputs[0]->get_type() == Variant::STRING) { r_error_str = *p_outputs[0]; } else { - if (unary) + if (unary) { r_error_str = String(op_names[op]) + RTR(": Invalid argument of type: ") + Variant::get_type_name(p_inputs[0]->get_type()); - else + } else { r_error_str = String(op_names[op]) + RTR(": Invalid arguments: ") + "A: " + Variant::get_type_name(p_inputs[0]->get_type()) + " B: " + Variant::get_type_name(p_inputs[1]->get_type()); + } } } @@ -1092,8 +1116,9 @@ String VisualScriptSelect::get_text() const { } void VisualScriptSelect::set_typed(Variant::Type p_op) { - if (typed == p_op) + if (typed == p_op) { return; + } typed = p_op; ports_changed_notify(); @@ -1121,10 +1146,11 @@ 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) { bool cond = *p_inputs[0]; - if (cond) + if (cond) { *p_outputs[0] = *p_inputs[1]; - else + } else { *p_outputs[0] = *p_inputs[2]; + } return 0; } @@ -1184,8 +1210,9 @@ String VisualScriptVariableGet::get_caption() const { } void VisualScriptVariableGet::set_variable(StringName p_variable) { - if (variable == p_variable) + if (variable == p_variable) { return; + } variable = p_variable; ports_changed_notify(); } @@ -1202,8 +1229,9 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { String vhint; for (List<StringName>::Element *E = vars.front(); E; E = E->next()) { - if (vhint != String()) + if (vhint != String()) { vhint += ","; + } vhint += E->get().operator String(); } @@ -1292,8 +1320,9 @@ String VisualScriptVariableSet::get_caption() const { } void VisualScriptVariableSet::set_variable(StringName p_variable) { - if (variable == p_variable) + if (variable == p_variable) { return; + } variable = p_variable; ports_changed_notify(); } @@ -1310,8 +1339,9 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { String vhint; for (List<StringName>::Element *E = vars.front(); E; E = E->next()) { - if (vhint != String()) + if (vhint != String()) { vhint += ","; + } vhint += E->get().operator String(); } @@ -1397,8 +1427,9 @@ String VisualScriptConstant::get_caption() const { } void VisualScriptConstant::set_constant_type(Variant::Type p_type) { - if (type == p_type) + if (type == p_type) { return; + } type = p_type; Callable::CallError ce; @@ -1412,8 +1443,9 @@ Variant::Type VisualScriptConstant::get_constant_type() const { } void VisualScriptConstant::set_constant_value(Variant p_value) { - if (value == p_value) + if (value == p_value) { return; + } value = p_value; ports_changed_notify(); @@ -1426,8 +1458,9 @@ Variant VisualScriptConstant::get_constant_value() const { void VisualScriptConstant::_validate_property(PropertyInfo &property) const { if (property.name == "value") { property.type = type; - if (type == Variant::NIL) + if (type == Variant::NIL) { property.usage = 0; //do not save if nil + } } } @@ -1521,8 +1554,9 @@ String VisualScriptPreload::get_caption() const { } void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) { - if (preload == p_preload) + if (preload == p_preload) { return; + } preload = p_preload; ports_changed_notify(); @@ -1762,8 +1796,9 @@ void VisualScriptGlobalConstant::_bind_methods() { String cc; for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { - if (i > 0) + if (i > 0) { cc += ","; + } cc += GlobalConstants::get_global_constant_name(i); } ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant"); @@ -2137,8 +2172,9 @@ void VisualScriptMathConstant::_bind_methods() { String cc; for (int i = 0; i < MATH_CONSTANT_MAX; i++) { - if (i > 0) + if (i > 0) { cc += ","; + } cc += const_name[i]; } ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant"); @@ -2243,11 +2279,13 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con Engine::get_singleton()->get_singletons(&singletons); for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { - if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") + if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") { continue; //skip these, too simple named + } - if (cc != String()) + if (cc != String()) { cc += ","; + } cc += E->get().name; } @@ -2352,18 +2390,21 @@ 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) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; @@ -2378,24 +2419,28 @@ VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGu #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return tg; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return tg; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return tg; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return tg; + } Node *another = script_node->get_node(path); @@ -2411,24 +2456,28 @@ 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()) + if (!script.is_valid()) { return; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return; + } property.hint_string = script_node->get_path(); } @@ -2638,10 +2687,11 @@ PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const { PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const { String type_name; - if (get_visual_script().is_valid()) + if (get_visual_script().is_valid()) { type_name = get_visual_script()->get_instance_base_type(); - else + } else { type_name = "instance"; + } return PropertyInfo(Variant::OBJECT, type_name); } @@ -2674,8 +2724,9 @@ VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inp tg.gdclass = "Object"; Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return tg; + } tg.gdclass = script->get_instance_base_type(); tg.script = script; @@ -2958,10 +3009,12 @@ String VisualScriptSubCall::get_caption() const { String VisualScriptSubCall::get_text() const { Ref<Script> script = get_script(); if (script.is_valid()) { - if (script->get_name() != String()) + if (script->get_name() != String()) { return script->get_name(); - if (script->get_path().is_resource_file()) + } + if (script->get_path().is_resource_file()) { return script->get_path().get_file(); + } return script->get_class(); } return ""; @@ -3054,8 +3107,9 @@ String VisualScriptComment::get_text() const { } void VisualScriptComment::set_title(const String &p_title) { - if (title == p_title) + if (title == p_title) { return; + } title = p_title; ports_changed_notify(); } @@ -3065,8 +3119,9 @@ String VisualScriptComment::get_title() const { } void VisualScriptComment::set_description(const String &p_description) { - if (description == p_description) + if (description == p_description) { return; + } description = p_description; ports_changed_notify(); } @@ -3076,8 +3131,9 @@ String VisualScriptComment::get_description() const { } void VisualScriptComment::set_size(const Size2 &p_size) { - if (size == p_size) + if (size == p_size) { return; + } size = p_size; ports_changed_notify(); } @@ -3168,8 +3224,9 @@ String VisualScriptConstructor::get_category() const { } void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) { - if (type == p_type) + if (type == p_type) { return; + } type = p_type; ports_changed_notify(); @@ -3284,8 +3341,9 @@ String VisualScriptLocalVar::get_category() const { } void VisualScriptLocalVar::set_var_name(const StringName &p_name) { - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); @@ -3390,8 +3448,9 @@ String VisualScriptLocalVarSet::get_category() const { } void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) { - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); @@ -3509,8 +3568,9 @@ String VisualScriptInputAction::get_category() const { } void VisualScriptInputAction::set_action_name(const StringName &p_name) { - if (name == p_name) + if (name == p_name) { return; + } name = p_name; ports_changed_notify(); @@ -3521,8 +3581,9 @@ StringName VisualScriptInputAction::get_action_name() const { } void VisualScriptInputAction::set_action_mode(Mode p_mode) { - if (mode == p_mode) + if (mode == p_mode) { return; + } mode = p_mode; ports_changed_notify(); @@ -3579,8 +3640,9 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { const PropertyInfo &pi = E->get(); - if (!pi.name.begins_with("input/")) + if (!pi.name.begins_with("input/")) { continue; + } String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length()); @@ -3590,8 +3652,9 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { al.sort(); for (int i = 0; i < al.size(); i++) { - if (actions != String()) + if (actions != String()) { actions += ","; + } actions += al[i]; } @@ -3678,8 +3741,9 @@ void VisualScriptDeconstruct::_update_elements() { } void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) { - if (type == p_type) + if (type == p_type) { return; + } type = p_type; _update_elements(); diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp index 3cdf3f5d75..f14c9ce49d 100644 --- a/modules/visual_script/visual_script_property_selector.cpp +++ b/modules/visual_script/visual_script_property_selector.cpp @@ -58,8 +58,9 @@ void VisualScriptPropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) { search_box->accept_event(); TreeItem *root = search_options->get_root(); - if (!root->get_children()) + if (!root->get_children()) { break; + } TreeItem *current = search_options->get_selected(); @@ -150,11 +151,13 @@ void VisualScriptPropertySelector::_update_search() { } } for (List<PropertyInfo>::Element *F = props.front(); F; F = F->next()) { - if (!(F->get().usage & PROPERTY_USAGE_EDITOR) && !(F->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) + if (!(F->get().usage & PROPERTY_USAGE_EDITOR) && !(F->get().usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) { continue; + } - if (type_filter.size() && type_filter.find(F->get().type) == -1) + if (type_filter.size() && type_filter.find(F->get().type) == -1) { continue; + } // capitalize() also converts underscore to space, we'll match again both possible styles String get_text_raw = String(vformat(TTR("Get %s"), F->get().name)); @@ -206,14 +209,17 @@ 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)) + if (name.begins_with("_") && !(M->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } - if (virtuals_only && !(M->get().flags & METHOD_FLAG_VIRTUAL)) + if (virtuals_only && !(M->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } - if (!virtuals_only && (M->get().flags & METHOD_FLAG_VIRTUAL)) + if (!virtuals_only && (M->get().flags & METHOD_FLAG_VIRTUAL)) { continue; + } MethodInfo mi = M->get(); String desc_arguments; @@ -353,8 +359,9 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt bool in_modifier = p_modifiers.empty(); for (Set<String>::Element *F = p_modifiers.front(); F && in_modifier; F = F->next()) { - if (E->get().findn(F->get()) != -1) + if (E->get().findn(F->get()) != -1) { in_modifier = true; + } } if (!in_modifier) { continue; @@ -406,8 +413,9 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt void VisualScriptPropertySelector::_confirmed() { TreeItem *ti = search_options->get_selected(); - if (!ti) + if (!ti) { return; + } emit_signal("selected", ti->get_metadata(0), ti->get_metadata(1), ti->get_metadata(2)); set_visible(false); } @@ -416,8 +424,9 @@ void VisualScriptPropertySelector::_item_selected() { help_bit->set_text(""); TreeItem *item = search_options->get_selected(); - if (!item) + if (!item) { return; + } String name = item->get_metadata(0); String class_type; @@ -502,8 +511,9 @@ void VisualScriptPropertySelector::_item_selected() { memdelete(names); - if (text == String()) + if (text == String()) { return; + } help_bit->set_text(text); } @@ -527,10 +537,11 @@ void VisualScriptPropertySelector::select_method_from_base_type(const String &p_ virtuals_only = p_virtuals_only; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); connecting = p_connecting; @@ -551,10 +562,11 @@ void VisualScriptPropertySelector::select_from_base_type(const String &p_base, c virtuals_only = p_virtuals_only; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = p_seq_connect; connecting = p_connecting; @@ -575,10 +587,11 @@ void VisualScriptPropertySelector::select_from_script(const Ref<Script> &p_scrip virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = false; connecting = p_connecting; @@ -597,10 +610,11 @@ void VisualScriptPropertySelector::select_from_basic_type(Variant::Type p_type, virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = false; connecting = p_connecting; @@ -618,10 +632,11 @@ void VisualScriptPropertySelector::select_from_action(const String &p_type, cons virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = true; connecting = p_connecting; @@ -639,10 +654,11 @@ void VisualScriptPropertySelector::select_from_instance(Object *p_instance, cons virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); seq_connect = false; connecting = p_connecting; @@ -659,10 +675,11 @@ void VisualScriptPropertySelector::select_from_visual_script(const String &p_bas instance = nullptr; virtuals_only = false; show_window(.5f); - if (clear_text) + if (clear_text) { search_box->set_text(""); - else + } else { search_box->select_all(); + } search_box->grab_focus(); connecting = p_connecting; diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index a035efd25d..dd07cc45a7 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -147,8 +147,9 @@ VisualScriptNodeInstance *VisualScriptYield::instance(VisualScriptInstance *p_in } void VisualScriptYield::set_yield_mode(YieldMode p_mode) { - if (yield_mode == p_mode) + if (yield_mode == p_mode) { return; + } yield_mode = p_mode; ports_changed_notify(); _change_notify(); @@ -159,8 +160,9 @@ VisualScriptYield::YieldMode VisualScriptYield::get_yield_mode() { } void VisualScriptYield::set_wait_time(float p_time) { - if (wait_time == p_time) + if (wait_time == p_time) { return; + } wait_time = p_time; ports_changed_notify(); } @@ -219,18 +221,21 @@ bool VisualScriptYieldSignal::has_input_sequence_port() const { #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) + if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) { return nullptr; + } Ref<Script> scr = p_current_node->get_script(); - if (scr.is_valid() && scr == script) + if (scr.is_valid() && scr == script) { return p_current_node; + } for (int i = 0; i < p_current_node->get_child_count(); i++) { Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script); - if (n) + if (n) { return n; + } } return nullptr; @@ -240,27 +245,32 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Node *VisualScriptYieldSignal::_get_base_node() const { #ifdef TOOLS_ENABLED Ref<Script> script = get_visual_script(); - if (!script.is_valid()) + if (!script.is_valid()) { return nullptr; + } MainLoop *main_loop = OS::get_singleton()->get_main_loop(); SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop); - if (!scene_tree) + if (!scene_tree) { return nullptr; + } Node *edited_scene = scene_tree->get_edited_scene_root(); - if (!edited_scene) + if (!edited_scene) { return nullptr; + } Node *script_node = _find_script_node(edited_scene, edited_scene, script); - if (!script_node) + if (!script_node) { return nullptr; + } - if (!script_node->has_node(base_path)) + if (!script_node->has_node(base_path)) { return nullptr; + } Node *path_to = script_node->get_node(base_path); @@ -272,29 +282,32 @@ Node *VisualScriptYieldSignal::_get_base_node() const { } StringName VisualScriptYieldSignal::_get_base_type() const { - if (call_mode == CALL_MODE_SELF && get_visual_script().is_valid()) + 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()) { + } else if (call_mode == CALL_MODE_NODE_PATH && get_visual_script().is_valid()) { Node *path = _get_base_node(); - if (path) + if (path) { return path->get_class(); + } } return base_type; } int VisualScriptYieldSignal::get_input_value_port_count() const { - if (call_mode == CALL_MODE_INSTANCE) + if (call_mode == CALL_MODE_INSTANCE) { return 1; - else + } else { return 0; + } } int VisualScriptYieldSignal::get_output_value_port_count() const { MethodInfo sr; - if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) + if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) { return 0; + } return sr.arguments.size(); } @@ -304,17 +317,19 @@ String VisualScriptYieldSignal::get_output_sequence_port_text(int p_port) const } PropertyInfo VisualScriptYieldSignal::get_input_value_port_info(int p_idx) const { - if (call_mode == CALL_MODE_INSTANCE) + if (call_mode == CALL_MODE_INSTANCE) { return PropertyInfo(Variant::OBJECT, "instance"); - else + } else { return PropertyInfo(); + } } PropertyInfo VisualScriptYieldSignal::get_output_value_port_info(int p_idx) const { MethodInfo sr; - if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) + if (!ClassDB::get_signal(_get_base_type(), signal, &sr)) { return PropertyInfo(); //no signal + } ERR_FAIL_INDEX_V(p_idx, sr.arguments.size(), PropertyInfo()); return sr.arguments[p_idx]; } @@ -330,15 +345,17 @@ String VisualScriptYieldSignal::get_caption() const { } String VisualScriptYieldSignal::get_text() const { - if (call_mode == CALL_MODE_SELF) + if (call_mode == CALL_MODE_SELF) { return " " + String(signal) + "()"; - else + } else { return " " + _get_base_type() + "." + String(signal) + "()"; + } } void VisualScriptYieldSignal::set_base_type(const StringName &p_type) { - if (base_type == p_type) + if (base_type == p_type) { return; + } base_type = p_type; @@ -351,8 +368,9 @@ StringName VisualScriptYieldSignal::get_base_type() const { } void VisualScriptYieldSignal::set_signal(const StringName &p_type) { - if (signal == p_type) + if (signal == p_type) { return; + } signal = p_type; @@ -365,8 +383,9 @@ StringName VisualScriptYieldSignal::get_signal() const { } void VisualScriptYieldSignal::set_base_path(const NodePath &p_type) { - if (base_path == p_type) + if (base_path == p_type) { return; + } base_path = p_type; @@ -379,8 +398,9 @@ NodePath VisualScriptYieldSignal::get_base_path() const { } void VisualScriptYieldSignal::set_call_mode(CallMode p_mode) { - if (call_mode == p_mode) + if (call_mode == p_mode) { return; + } call_mode = p_mode; @@ -419,8 +439,9 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { List<String> mstring; for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) { - if (E->get().name.begins_with("_")) + if (E->get().name.begins_with("_")) { continue; + } mstring.push_back(E->get().name.get_slice(":", 0)); } @@ -428,8 +449,9 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { String ml; for (List<String>::Element *E = mstring.front(); E; E = E->next()) { - if (ml != String()) + if (ml != String()) { ml += ","; + } ml += E->get(); } @@ -452,8 +474,9 @@ void VisualScriptYieldSignal::_bind_methods() { String bt; for (int i = 0; i < Variant::VARIANT_MAX; i++) { - if (i > 0) + if (i > 0) { bt += ","; + } bt += Variant::get_type_name(Variant::Type(i)); } diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index 47c54b61e9..832e14d91a 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -55,16 +55,19 @@ public: ERR_FAIL_COND_MSG(!file, "Failed loading resource: '" + p_file + "'."); } ~MkvReader() { - if (file) + if (file) { memdelete(file); + } } virtual int Read(long long pos, long len, unsigned char *buf) { if (file) { - if (file->get_position() != (size_t)pos) + if (file->get_position() != (size_t)pos) { file->seek(pos); - if (file->get_buffer(buf, len) == len) + } + if (file->get_buffer(buf, len) == len) { return 0; + } } return -1; } @@ -72,10 +75,12 @@ public: virtual int Length(long long *total, long long *available) { if (file) { const size_t len = file->get_len(); - if (total) + if (total) { *total = len; - if (available) + } + if (available) { *available = len; + } return 0; } return -1; @@ -178,8 +183,9 @@ bool VideoStreamPlaybackWebm::has_loop() const { } float VideoStreamPlaybackWebm::get_length() const { - if (webm) + if (webm) { return webm->getLength(); + } return 0.0f; } @@ -200,8 +206,9 @@ Ref<Texture2D> VideoStreamPlaybackWebm::get_texture() const { } void VideoStreamPlaybackWebm::update(float p_delta) { - if ((!playing || paused) || !video) + if ((!playing || paused) || !video) { return; + } time += p_delta; @@ -244,11 +251,13 @@ void VideoStreamPlaybackWebm::update(float p_delta) { } video_frame = video_frames[video_frames_pos]; - if (!webm->readFrame(video_frame, audio_frame)) //This will invalidate frames + if (!webm->readFrame(video_frame, audio_frame)) { //This will invalidate frames break; //Can't demux, EOS? + } - if (video_frame->isValid()) + if (video_frame->isValid()) { ++video_frames_pos; + } }; bool video_frame_done = false; @@ -315,8 +324,9 @@ void VideoStreamPlaybackWebm::update(float p_delta) { video_frames[video_frames_pos] = video_frame; } - if (video_frames_pos == 0 && webm->isEOS()) + if (video_frames_pos == 0 && webm->isEOS()) { stop(); + } } void VideoStreamPlaybackWebm::set_mix_callback(VideoStreamPlayback::AudioMixCallback p_callback, void *p_userdata) { @@ -325,14 +335,16 @@ void VideoStreamPlaybackWebm::set_mix_callback(VideoStreamPlayback::AudioMixCall } int VideoStreamPlaybackWebm::get_channels() const { - if (audio) + if (audio) { return webm->getChannels(); + } return 0; } int VideoStreamPlaybackWebm::get_mix_rate() const { - if (audio) + if (audio) { return webm->getSampleRate(); + } return 0; } @@ -357,24 +369,30 @@ bool VideoStreamPlaybackWebm::should_process(WebMFrame &video_frame) { } void VideoStreamPlaybackWebm::delete_pointers() { - if (pcm) + if (pcm) { memfree(pcm); + } - if (audio_frame) + if (audio_frame) { memdelete(audio_frame); + } if (video_frames) { - for (int i = 0; i < video_frames_capacity; ++i) + for (int i = 0; i < video_frames_capacity; ++i) { memdelete(video_frames[i]); + } memfree(video_frames); } - if (video) + if (video) { memdelete(video); - if (audio) + } + if (audio) { memdelete(audio); + } - if (webm) + if (webm) { memdelete(webm); + } } /**/ @@ -384,8 +402,9 @@ VideoStreamWebm::VideoStreamWebm() {} Ref<VideoStreamPlayback> VideoStreamWebm::instance_playback() { Ref<VideoStreamPlaybackWebm> pb = memnew(VideoStreamPlaybackWebm); pb->set_audio_track(audio_track); - if (pb->open_file(file)) + if (pb->open_file(file)) { return pb; + } return nullptr; } @@ -443,7 +462,8 @@ bool ResourceFormatLoaderWebm::handles_type(const String &p_type) const { String ResourceFormatLoaderWebm::get_resource_type(const String &p_path) const { String el = p_path.get_extension().to_lower(); - if (el == "webm") + if (el == "webm") { return "VideoStreamWebm"; + } return ""; } diff --git a/modules/webp/image_loader_webp.cpp b/modules/webp/image_loader_webp.cpp index 744b7ef8b9..d5c80e7909 100644 --- a/modules/webp/image_loader_webp.cpp +++ b/modules/webp/image_loader_webp.cpp @@ -42,10 +42,11 @@ static Vector<uint8_t> _webp_lossy_pack(const Ref<Image> &p_image, float p_quali ERR_FAIL_COND_V(p_image.is_null() || p_image->empty(), Vector<uint8_t>()); Ref<Image> img = p_image->duplicate(); - if (img->detect_alpha()) + if (img->detect_alpha()) { img->convert(Image::FORMAT_RGBA8); - else + } else { img->convert(Image::FORMAT_RGB8); + } Size2 s(img->get_width(), img->get_height()); Vector<uint8_t> data = img->get_data(); diff --git a/modules/webrtc/webrtc_multiplayer.cpp b/modules/webrtc/webrtc_multiplayer.cpp index 72115628ed..e0c0cad68c 100644 --- a/modules/webrtc/webrtc_multiplayer.cpp +++ b/modules/webrtc/webrtc_multiplayer.cpp @@ -65,8 +65,9 @@ bool WebRTCMultiplayer::is_server() const { } void WebRTCMultiplayer::poll() { - if (peer_map.size() == 0) + if (peer_map.size() == 0) { return; + } List<int> remove; List<int> add; @@ -113,15 +114,17 @@ void WebRTCMultiplayer::poll() { // Remove disconnected peers for (List<int>::Element *E = remove.front(); E; E = E->next()) { remove_peer(E->get()); - if (next_packet_peer == E->get()) + if (next_packet_peer == E->get()) { next_packet_peer = 0; + } } // Signal newly connected peers for (List<int>::Element *E = add.front(); E; E = E->next()) { // Already connected to server: simply notify new peer. // NOTE: Mesh is always connected. - if (connection_status == CONNECTION_CONNECTED) + if (connection_status == CONNECTION_CONNECTED) { emit_signal("peer_connected", E->get()); + } // Server emulation mode suppresses peer_conencted until server connects. if (server_compat && E->get() == TARGET_PEER_SERVER) { @@ -131,21 +134,24 @@ void WebRTCMultiplayer::poll() { emit_signal("connection_succeeded"); // Notify of all previously connected peers for (Map<int, Ref<ConnectedPeer>>::Element *F = peer_map.front(); F; F = F->next()) { - if (F->key() != 1 && F->get()->connected) + if (F->key() != 1 && F->get()->connected) { emit_signal("peer_connected", F->key()); + } } break; // Because we already notified of all newly added peers. } } // Fetch next packet - if (next_packet_peer == 0) + if (next_packet_peer == 0) { _find_next_peer(); + } } void WebRTCMultiplayer::_find_next_peer() { Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.find(next_packet_peer); - if (E) + if (E) { E = E->next(); + } // After last. while (E) { for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) { @@ -165,8 +171,9 @@ void WebRTCMultiplayer::_find_next_peer() { return; } } - if (E->key() == (int)next_packet_peer) + if (E->key() == (int)next_packet_peer) { break; + } E = E->next(); } // No packet found @@ -191,10 +198,11 @@ Error WebRTCMultiplayer::initialize(int p_self_id, bool p_server_compat) { server_compat = p_server_compat; // Mesh and server are always connected - if (!server_compat || p_self_id == 1) + if (!server_compat || p_self_id == 1) { connection_status = CONNECTION_CONNECTED; - else + } else { connection_status = CONNECTION_CONNECTING; + } return OK; } @@ -332,8 +340,9 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) 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) + if (target_peer != 0 && F->key() == exclude) { continue; + } ERR_CONTINUE(F->value()->channels.size() <= ch || !F->value()->channels[ch].is_valid()); F->value()->channels[ch]->put_packet(p_buffer, p_buffer_size); @@ -343,8 +352,9 @@ Error WebRTCMultiplayer::put_packet(const uint8_t *p_buffer, int p_buffer_size) } int WebRTCMultiplayer::get_available_packet_count() const { - if (next_packet_peer == 0) + if (next_packet_peer == 0) { return 0; // To be sure next call to get_packet works if size > 0 . + } int size = 0; for (Map<int, Ref<ConnectedPeer>>::Element *E = peer_map.front(); E; E = E->next()) { for (List<Ref<WebRTCDataChannel>>::Element *F = E->get()->channels.front(); F; F = F->next()) { diff --git a/modules/webrtc/webrtc_multiplayer.h b/modules/webrtc/webrtc_multiplayer.h index 876e2c6fe9..906b90a1b6 100644 --- a/modules/webrtc/webrtc_multiplayer.h +++ b/modules/webrtc/webrtc_multiplayer.h @@ -56,8 +56,9 @@ private: ConnectedPeer() { connected = false; - for (int i = 0; i < CH_RESERVED_MAX; i++) + for (int i = 0; i < CH_RESERVED_MAX; i++) { channels.push_front(Ref<WebRTCDataChannel>()); + } } }; diff --git a/modules/webrtc/webrtc_peer_connection.cpp b/modules/webrtc/webrtc_peer_connection.cpp index f71dcc956c..670924bca2 100644 --- a/modules/webrtc/webrtc_peer_connection.cpp +++ b/modules/webrtc/webrtc_peer_connection.cpp @@ -37,8 +37,9 @@ Ref<WebRTCPeerConnection> WebRTCPeerConnection::create_ref() { } WebRTCPeerConnection *WebRTCPeerConnection::create() { - if (!_create) + if (!_create) { return nullptr; + } return _create(); } diff --git a/modules/websocket/editor_debugger_server_websocket.cpp b/modules/websocket/editor_debugger_server_websocket.cpp index 66f3dac907..95ea7ceafa 100644 --- a/modules/websocket/editor_debugger_server_websocket.cpp +++ b/modules/websocket/editor_debugger_server_websocket.cpp @@ -39,8 +39,9 @@ void EditorDebuggerServerWebSocket::_peer_connected(int p_id, String _protocol) } void EditorDebuggerServerWebSocket::_peer_disconnected(int p_id, bool p_was_clean) { - if (pending_peers.find(p_id)) + if (pending_peers.find(p_id)) { pending_peers.erase(p_id); + } } void EditorDebuggerServerWebSocket::poll() { diff --git a/modules/websocket/remote_debugger_peer_websocket.cpp b/modules/websocket/remote_debugger_peer_websocket.cpp index a0629ecf00..a67a959e31 100644 --- a/modules/websocket/remote_debugger_peer_websocket.cpp +++ b/modules/websocket/remote_debugger_peer_websocket.cpp @@ -88,8 +88,9 @@ Array RemoteDebuggerPeerWebSocket::get_message() { } Error RemoteDebuggerPeerWebSocket::put_message(const Array &p_arr) { - if (out_queue.size() >= max_queued_messages) + if (out_queue.size() >= max_queued_messages) { return ERR_OUT_OF_MEMORY; + } out_queue.push_back(p_arr); return OK; } diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp index 7cf3bf74bb..3900180739 100644 --- a/modules/websocket/websocket_client.cpp +++ b/modules/websocket/websocket_client.cpp @@ -53,8 +53,9 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto port = 443; } else { ssl = false; - if (host.begins_with("ws://")) + if (host.begins_with("ws://")) { host = host.substr(5, host.length() - 5); + } } // Path diff --git a/modules/websocket/websocket_multiplayer_peer.cpp b/modules/websocket/websocket_multiplayer_peer.cpp index e0462c74a1..fa2fe891a5 100644 --- a/modules/websocket/websocket_multiplayer_peer.cpp +++ b/modules/websocket/websocket_multiplayer_peer.cpp @@ -70,8 +70,9 @@ int WebSocketMultiplayerPeer::_gen_unique_id() const { void WebSocketMultiplayerPeer::_clear() { _peer_map.clear(); - if (_current_packet.data != nullptr) + if (_current_packet.data != nullptr) { memfree(_current_packet.data); + } for (List<Packet>::Element *E = _incoming_packets.front(); E; E = E->next()) { memfree(E->get().data); @@ -193,8 +194,9 @@ void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) { for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { int32_t id = E->key(); - if (p_peer_id == id) + if (p_peer_id == id) { continue; // Skip the newwly added peer (already confirmed) + } // Send new peer to others _send_sys(get_peer(id), SYS_ADD, p_peer_id); @@ -206,8 +208,9 @@ void WebSocketMultiplayerPeer::_send_add(int32_t p_peer_id) { void WebSocketMultiplayerPeer::_send_del(int32_t p_peer_id) { for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { int32_t id = E->key(); - if (p_peer_id != id) + if (p_peer_id != id) { _send_sys(get_peer(id), SYS_DEL, p_peer_id); + } } } @@ -228,15 +231,17 @@ Error WebSocketMultiplayerPeer::_server_relay(int32_t p_from, int32_t p_to, cons } else if (p_to == 0) { for (Map<int, Ref<WebSocketPeer>>::Element *E = _peer_map.front(); E; E = E->next()) { - if (E->key() != p_from) + if (E->key() != p_from) { E->get()->put_packet(p_buffer, p_buffer_size); + } } 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) + if (E->key() != p_from && E->key() != -p_to) { E->get()->put_packet(p_buffer, p_buffer_size); + } } return OK; // Sent to all but sender and excluded @@ -286,8 +291,9 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u } else if (to < 0) { // All but one, for us if not excluded - if (_peer_id != -(int32_t)p_peer_id) + if (_peer_id != -(int32_t)p_peer_id) { _store_pkt(from, to, in_buffer, data_size); + } } // Relay if needed (i.e. "to" includes a peer that is not the server) _server_relay(from, to, in_buffer, size); @@ -308,8 +314,9 @@ void WebSocketMultiplayerPeer::_process_multiplayer(Ref<WebSocketPeer> p_peer, u case SYS_ADD: // Add peer _peer_map[id] = Ref<WebSocketPeer>(); emit_signal("peer_connected", id); - if (id == 1) // We just connected to the server + if (id == 1) { // We just connected to the server emit_signal("connection_succeeded"); + } break; case SYS_DEL: // Remove peer diff --git a/modules/websocket/websocket_server.cpp b/modules/websocket/websocket_server.cpp index 4c1fcff626..b20b925dec 100644 --- a/modules/websocket/websocket_server.cpp +++ b/modules/websocket/websocket_server.cpp @@ -109,8 +109,9 @@ void WebSocketServer::set_ca_chain(Ref<X509Certificate> p_ca_chain) { } NetworkedMultiplayerPeer::ConnectionStatus WebSocketServer::get_connection_status() const { - if (is_listening()) + if (is_listening()) { return CONNECTION_CONNECTED; + } return CONNECTION_DISCONNECTED; } diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index 271e475786..7d16c2e99f 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -117,10 +117,11 @@ bool WSLClient::_verify_headers(String &r_protocol) { ERR_FAIL_COND_V_MSG(header.size() != 2, false, "Invalid header -> " + psa[i] + "."); String name = header[0].to_lower(); String value = header[1].strip_edges(); - if (headers.has(name)) + if (headers.has(name)) { headers[name] += "," + value; - else + } else { headers[name] = value; + } } #define _WSL_CHECK(NAME, VALUE) \ @@ -142,13 +143,15 @@ bool WSLClient::_verify_headers(String &r_protocol) { r_protocol = headers["sec-websocket-protocol"]; bool valid = false; for (int i = 0; i < _protocols.size(); i++) { - if (_protocols[i] != r_protocol) + if (_protocols[i] != r_protocol) { continue; + } valid = true; break; } - if (!valid) + if (!valid) { return false; + } } return true; } @@ -199,8 +202,9 @@ Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port, if (p_protocols.size() > 0) { request += "Sec-WebSocket-Protocol: "; for (int i = 0; i < p_protocols.size(); i++) { - if (i != 0) + if (i != 0) { request += ","; + } request += p_protocols[i]; } request += "\r\n"; @@ -228,8 +232,9 @@ void WSLClient::poll() { return; } - if (_connection.is_null()) + if (_connection.is_null()) { return; // Not connected. + } switch (_tcp->get_status()) { case StreamPeerTCP::STATUS_NONE: @@ -256,9 +261,9 @@ void WSLClient::poll() { ERR_FAIL_COND(ssl.is_null()); // Bug? ssl->poll(); } - if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) + if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) { return; // Need more polling. - else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) { + } else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) { disconnect_from_host(); _on_error(); return; // Error. @@ -283,11 +288,13 @@ Ref<WebSocketPeer> WSLClient::get_peer(int p_peer_id) const { } NetworkedMultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const { - if (_peer->is_connected_to_host()) + if (_peer->is_connected_to_host()) { return CONNECTION_CONNECTED; + } - if (_tcp->is_connected_to_host()) + if (_tcp->is_connected_to_host()) { return CONNECTION_CONNECTING; + } return CONNECTION_DISCONNECTED; } diff --git a/modules/websocket/wsl_peer.cpp b/modules/websocket/wsl_peer.cpp index 98dff6fec9..bf1ba43f8a 100644 --- a/modules/websocket/wsl_peer.cpp +++ b/modules/websocket/wsl_peer.cpp @@ -60,8 +60,9 @@ String WSLPeer::compute_key_response(String p_key) { } void WSLPeer::_wsl_destroy(struct PeerData **p_data) { - if (!p_data || !(*p_data)) + if (!p_data || !(*p_data)) { return; + } struct PeerData *data = *p_data; if (data->polling) { data->destroy = true; @@ -147,8 +148,9 @@ void wsl_msg_recv_callback(wslay_event_context_ptr ctx, const struct wslay_event } WSLPeer *peer = (WSLPeer *)peer_data->peer; - if (peer->parse_message(arg) != OK) + if (peer->parse_message(arg) != OK) { return; + } if (peer_data->is_server) { WSLServer *helper = (WSLServer *)peer_data->obj; @@ -209,10 +211,11 @@ void WSLPeer::make_context(PeerData *p_data, unsigned int p_in_buf_size, unsigne _data->peer = this; _data->valid = true; - if (_data->is_server) + if (_data->is_server) { wslay_event_context_server_init(&(_data->ctx), &wsl_callbacks, _data); - else + } else { wslay_event_context_client_init(&(_data->ctx), &wsl_callbacks, _data); + } wslay_event_config_set_max_recv_msg_length(_data->ctx, (1ULL << p_in_buf_size)); } @@ -225,8 +228,9 @@ WSLPeer::WriteMode WSLPeer::get_write_mode() const { } void WSLPeer::poll() { - if (!_data) + if (!_data) { return; + } if (_wsl_poll(_data)) { _data = nullptr; @@ -254,8 +258,9 @@ Error WSLPeer::get_packet(const uint8_t **r_buffer, int &r_buffer_size) { ERR_FAIL_COND_V(!is_connected_to_host(), FAILED); - if (_in_buffer.packets_left() == 0) + if (_in_buffer.packets_left() == 0) { return ERR_UNAVAILABLE; + } int read = 0; uint8_t *rw = _packet_buffer.ptrw(); @@ -268,8 +273,9 @@ 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()) + if (!is_connected_to_host()) { return 0; + } return _in_buffer.packets_left(); } @@ -317,8 +323,9 @@ void WSLPeer::set_no_delay(bool p_enabled) { } void WSLPeer::invalidate() { - if (_data) + if (_data) { _data->valid = false; + } } WSLPeer::WSLPeer() { diff --git a/modules/websocket/wsl_server.cpp b/modules/websocket/wsl_server.cpp index a3f4349f04..da7bfc70c0 100644 --- a/modules/websocket/wsl_server.cpp +++ b/modules/websocket/wsl_server.cpp @@ -60,10 +60,11 @@ bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols) { ERR_FAIL_COND_V_MSG(header.size() != 2, false, "Invalid header -> " + psa[i]); String name = header[0].to_lower(); String value = header[1].strip_edges(); - if (headers.has(name)) + if (headers.has(name)) { headers[name] += "," + value; - else + } else { headers[name] = value; + } } #define _WSL_CHECK(NAME, VALUE) \ ERR_FAIL_COND_V_MSG(!headers.has(NAME) || headers[NAME].to_lower() != VALUE, false, \ @@ -83,44 +84,52 @@ bool WSLServer::PendingPeer::_parse_request(const Vector<String> p_protocols) { String proto = protos[i].strip_edges(); // Check if we have the given protocol for (int j = 0; j < p_protocols.size(); j++) { - if (proto != p_protocols[j]) + if (proto != p_protocols[j]) { continue; + } protocol = proto; break; } // Found a protocol - if (protocol != "") + if (protocol != "") { break; + } } - if (protocol == "") // Invalid protocol(s) requested + if (protocol == "") { // Invalid protocol(s) requested return false; - } else if (p_protocols.size() > 0) // No protocol requested, but we need one + } + } else if (p_protocols.size() > 0) { // No protocol requested, but we need one return false; + } return true; } Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) { - if (OS::get_singleton()->get_ticks_msec() - time > WSL_SERVER_TIMEOUT) + if (OS::get_singleton()->get_ticks_msec() - time > WSL_SERVER_TIMEOUT) { return ERR_TIMEOUT; + } if (use_ssl) { Ref<StreamPeerSSL> ssl = static_cast<Ref<StreamPeerSSL>>(connection); - if (ssl.is_null()) + if (ssl.is_null()) { return FAILED; + } ssl->poll(); - if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) + if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING) { return ERR_BUSY; - else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) + } else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) { return FAILED; + } } if (!has_request) { int read = 0; while (true) { ERR_FAIL_COND_V_MSG(req_pos >= WSL_MAX_HEADER_SIZE, ERR_OUT_OF_MEMORY, "Response headers too big."); Error err = connection->get_partial_data(&req_buf[req_pos], 1, read); - if (err != OK) // Got an error + if (err != OK) { // Got an error return FAILED; - else if (read != 1) // Busy, wait next poll + } else if (read != 1) { // Busy, wait next poll return ERR_BUSY; + } char *r = (char *)req_buf; int l = req_pos; if (l > 3 && r[l] == '\n' && r[l - 1] == '\r' && r[l - 2] == '\n' && r[l - 3] == '\r') { @@ -132,8 +141,9 @@ Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) { s += "Upgrade: websocket\r\n"; s += "Connection: Upgrade\r\n"; s += "Sec-WebSocket-Accept: " + WSLPeer::compute_key_response(key) + "\r\n"; - if (protocol != "") + if (protocol != "") { s += "Sec-WebSocket-Protocol: " + protocol + "\r\n"; + } s += "\r\n"; response = s.utf8(); has_request = true; @@ -150,8 +160,9 @@ Error WSLServer::PendingPeer::do_handshake(const Vector<String> p_protocols) { } response_sent += sent; } - if (response_sent < response.size() - 1) + if (response_sent < response.size() - 1) { return ERR_BUSY; + } return OK; } @@ -216,13 +227,15 @@ void WSLServer::poll() { } remove_peers.clear(); - if (!_server->is_listening()) + if (!_server->is_listening()) { return; + } while (_server->is_connection_available()) { Ref<StreamPeerTCP> conn = _server->take_connection(); - if (is_refusing_new_connections()) + if (is_refusing_new_connections()) { continue; // Conn will go out-of-scope and be closed. + } Ref<PendingPeer> peer = memnew(PendingPeer); if (private_key.is_valid() && ssl_cert.is_valid()) { |