diff options
Diffstat (limited to 'modules')
64 files changed, 1685 insertions, 1271 deletions
diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index bc60c9cb6b..cbf30c8a2e 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -77,7 +77,7 @@ btScalar GodotAllConvexResultCallback::addSingleResult(btCollisionWorld::LocalCo PhysicsDirectSpaceState::ShapeResult &result = m_results[count]; - result.shape = convexResult.m_localShapeInfo->m_shapePart; + result.shape = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID result.rid = gObj->get_self(); result.collider_id = gObj->get_instance_id(); result.collider = 0 == result.collider_id ? NULL : ObjectDB::get_instance(result.collider_id); @@ -122,7 +122,7 @@ bool GodotClosestConvexResultCallback::needsCollision(btBroadphaseProxy *proxy0) btScalar GodotClosestConvexResultCallback::addSingleResult(btCollisionWorld::LocalConvexResult &convexResult, bool normalInWorldSpace) { btScalar res = btCollisionWorld::ClosestConvexResultCallback::addSingleResult(convexResult, normalInWorldSpace); - m_shapePart = convexResult.m_localShapeInfo->m_shapePart; + m_shapeId = convexResult.m_localShapeInfo->m_triangleIndex; // "m_triangleIndex" Is a odd name but contains the compound shape ID return res; } @@ -242,3 +242,21 @@ btScalar GodotRestInfoContactResultCallback::addSingleResult(btManifoldPoint &cp return cp.getDistance(); } + +void GodotDeepPenetrationContactResultCallback::addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorldOnB, btScalar depth) { + + if (depth < 0) { + // Has penetration + if (m_most_penetrated_distance > depth) { + + bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject(); + + m_most_penetrated_distance = depth; + m_pointCollisionObject = (isSwapped ? m_body0Wrap : m_body1Wrap)->getCollisionObject(); + m_other_compound_shape_index = isSwapped ? m_index1 : m_index0; + m_pointNormalWorld = isSwapped ? normalOnBInWorld * -1 : normalOnBInWorld; + m_pointWorld = isSwapped ? (pointInWorldOnB + normalOnBInWorld * depth) : pointInWorldOnB; + m_penetration_distance = depth; + } + } +} diff --git a/modules/bullet/godot_result_callbacks.h b/modules/bullet/godot_result_callbacks.h index 68dff5b12a..ba5142676b 100644 --- a/modules/bullet/godot_result_callbacks.h +++ b/modules/bullet/godot_result_callbacks.h @@ -88,7 +88,7 @@ public: struct GodotClosestConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback { public: const Set<RID> *m_exclude; - int m_shapePart; + int m_shapeId; GodotClosestConvexResultCallback(const btVector3 &convexFromWorld, const btVector3 &convexToWorld, const Set<RID> *p_exclude) : btCollisionWorld::ClosestConvexResultCallback(convexFromWorld, convexToWorld), m_exclude(p_exclude) {} @@ -149,4 +149,31 @@ public: virtual btScalar addSingleResult(btManifoldPoint &cp, const btCollisionObjectWrapper *colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper *colObj1Wrap, int partId1, int index1); }; +struct GodotDeepPenetrationContactResultCallback : public btManifoldResult { + btVector3 m_pointNormalWorld; + btVector3 m_pointWorld; + btScalar m_penetration_distance; + int m_other_compound_shape_index; + const btCollisionObject *m_pointCollisionObject; + + btScalar m_most_penetrated_distance; + + GodotDeepPenetrationContactResultCallback(const btCollisionObjectWrapper *body0Wrap, const btCollisionObjectWrapper *body1Wrap) + : btManifoldResult(body0Wrap, body1Wrap), + m_pointCollisionObject(NULL), + m_penetration_distance(0), + m_other_compound_shape_index(0), + m_most_penetrated_distance(1e20) {} + + void reset() { + m_pointCollisionObject = NULL; + m_most_penetrated_distance = 1e20; + } + + bool hasHit() { + return m_pointCollisionObject; + } + + virtual void addContactPoint(const btVector3 &normalOnBInWorld, const btVector3 &pointInWorld, btScalar depth); +}; #endif // GODOT_RESULT_CALLBACKS_H diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 98ae82bc5f..f5ab8221e3 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -511,12 +511,14 @@ void RigidBodyBullet::set_mode(PhysicsServer::BodyMode p_mode) { mode = PhysicsServer::BODY_MODE_RIGID; set_axis_lock(axis_lock); // Reload axis lock _internal_set_mass(0 == mass ? 1 : mass); + scratch_space_override_modificator(); break; } case PhysicsServer::BODY_MODE_CHARACTER: { mode = PhysicsServer::BODY_MODE_CHARACTER; set_axis_lock(axis_lock); // Reload axis lock _internal_set_mass(0 == mass ? 1 : mass); + scratch_space_override_modificator(); break; } } diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index 9df01aee3e..c82a1d1668 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -53,7 +53,7 @@ BulletPhysicsDirectSpaceState::BulletPhysicsDirectSpaceState(SpaceBullet *p_space) : PhysicsDirectSpaceState(), 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_layer, uint32_t p_object_type_mask) { +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) { if (p_result_max <= 0) return 0; @@ -68,15 +68,15 @@ int BulletPhysicsDirectSpaceState::intersect_point(const Vector3 &p_point, Shape // Setup query GodotAllContactResultCallback btResult(&collision_object_point, r_results, p_result_max, &p_exclude); - btResult.m_collisionFilterGroup = p_collision_layer; - btResult.m_collisionFilterMask = p_object_type_mask; + btResult.m_collisionFilterGroup = 0; + btResult.m_collisionFilterMask = p_collision_mask; space->dynamicsWorld->contactTest(&collision_object_point, btResult); // The results is already populated by GodotAllConvexResultCallback return btResult.m_count; } -bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_layer, uint32_t p_object_type_mask, bool p_pick_ray) { +bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude, uint32_t p_collision_mask, bool p_pick_ray) { btVector3 btVec_from; btVector3 btVec_to; @@ -86,8 +86,8 @@ bool BulletPhysicsDirectSpaceState::intersect_ray(const Vector3 &p_from, const V // setup query GodotClosestRayResultCallback btResult(btVec_from, btVec_to, &p_exclude); - btResult.m_collisionFilterGroup = p_collision_layer; - btResult.m_collisionFilterMask = p_object_type_mask; + btResult.m_collisionFilterGroup = 0; + btResult.m_collisionFilterMask = p_collision_mask; btResult.m_pickRay = p_pick_ray; space->dynamicsWorld->rayTest(btVec_from, btVec_to, btResult); @@ -109,18 +109,19 @@ 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 *p_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_layer, uint32_t p_object_type_mask) { +int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *p_results, int p_result_max, const Set<RID> &p_exclude, uint32_t p_collision_mask) { if (p_result_max <= 0) return 0; ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); - btConvexShape *btConvex = dynamic_cast<btConvexShape *>(shape->create_bt_shape()); - if (!btConvex) { - bulletdelete(btConvex); + btCollisionShape *btShape = shape->create_bt_shape(); + if (!btShape->isConvex()) { + bulletdelete(btShape); ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return 0; } + btConvexShape *btConvex = static_cast<btConvexShape *>(btShape); btVector3 scale_with_margin; G_TO_B(p_xform.basis.get_scale(), scale_with_margin); @@ -134,8 +135,8 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra collision_object.setWorldTransform(bt_xform); GodotAllContactResultCallback btQuery(&collision_object, p_results, p_result_max, &p_exclude); - btQuery.m_collisionFilterGroup = p_collision_layer; - btQuery.m_collisionFilterMask = p_object_type_mask; + btQuery.m_collisionFilterGroup = 0; + btQuery.m_collisionFilterMask = p_collision_mask; btQuery.m_closestDistanceThreshold = p_margin; space->dynamicsWorld->contactTest(&collision_object, btQuery); @@ -144,15 +145,16 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra return btQuery.m_count; } -bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_layer, uint32_t p_object_type_mask, ShapeRestInfo *r_info) { +bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude, uint32_t p_collision_mask, ShapeRestInfo *r_info) { ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); - btConvexShape *bt_convex_shape = dynamic_cast<btConvexShape *>(shape->create_bt_shape()); - if (!bt_convex_shape) { - bulletdelete(bt_convex_shape); + btCollisionShape *btShape = shape->create_bt_shape(); + if (!btShape->isConvex()) { + bulletdelete(btShape); ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return 0; } + btConvexShape *bt_convex_shape = static_cast<btConvexShape *>(btShape); btVector3 bt_motion; G_TO_B(p_motion, bt_motion); @@ -168,22 +170,24 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf bt_xform_to.getOrigin() += bt_motion; GodotClosestConvexResultCallback btResult(bt_xform_from.getOrigin(), bt_xform_to.getOrigin(), &p_exclude); - btResult.m_collisionFilterGroup = p_collision_layer; - btResult.m_collisionFilterMask = p_object_type_mask; + btResult.m_collisionFilterGroup = 0; + btResult.m_collisionFilterMask = p_collision_mask; space->dynamicsWorld->convexSweepTest(bt_convex_shape, bt_xform_from, bt_xform_to, btResult, 0.002); if (btResult.hasHit()) { - if (btCollisionObject::CO_RIGID_BODY == btResult.m_hitCollisionObject->getInternalType()) { - B_TO_G(static_cast<const btRigidBody *>(btResult.m_hitCollisionObject)->getVelocityInLocalPoint(btResult.m_hitPointWorld), r_info->linear_velocity); - } - CollisionObjectBullet *collision_object = static_cast<CollisionObjectBullet *>(btResult.m_hitCollisionObject->getUserPointer()); p_closest_safe = p_closest_unsafe = btResult.m_closestHitFraction; - B_TO_G(btResult.m_hitPointWorld, r_info->point); - B_TO_G(btResult.m_hitNormalWorld, r_info->normal); - r_info->rid = collision_object->get_self(); - r_info->collider_id = collision_object->get_instance_id(); - r_info->shape = btResult.m_shapePart; + if (r_info) { + if (btCollisionObject::CO_RIGID_BODY == btResult.m_hitCollisionObject->getInternalType()) { + B_TO_G(static_cast<const btRigidBody *>(btResult.m_hitCollisionObject)->getVelocityInLocalPoint(btResult.m_hitPointWorld), r_info->linear_velocity); + } + CollisionObjectBullet *collision_object = static_cast<CollisionObjectBullet *>(btResult.m_hitCollisionObject->getUserPointer()); + B_TO_G(btResult.m_hitPointWorld, r_info->point); + B_TO_G(btResult.m_hitNormalWorld, r_info->normal); + r_info->rid = collision_object->get_self(); + r_info->collider_id = collision_object->get_instance_id(); + r_info->shape = btResult.m_shapeId; + } } bulletdelete(bt_convex_shape); @@ -191,18 +195,19 @@ 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_layer, uint32_t p_object_type_mask) { +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) { if (p_result_max <= 0) return 0; ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); - btConvexShape *btConvex = dynamic_cast<btConvexShape *>(shape->create_bt_shape()); - if (!btConvex) { - bulletdelete(btConvex); + btCollisionShape *btShape = shape->create_bt_shape(); + if (!btShape->isConvex()) { + bulletdelete(btShape); ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return 0; } + btConvexShape *btConvex = static_cast<btConvexShape *>(btShape); btVector3 scale_with_margin; G_TO_B(p_shape_xform.basis.get_scale(), scale_with_margin); @@ -216,8 +221,8 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & collision_object.setWorldTransform(bt_xform); GodotContactPairContactResultCallback btQuery(&collision_object, r_results, p_result_max, &p_exclude); - btQuery.m_collisionFilterGroup = p_collision_layer; - btQuery.m_collisionFilterMask = p_object_type_mask; + btQuery.m_collisionFilterGroup = 0; + btQuery.m_collisionFilterMask = p_collision_mask; btQuery.m_closestDistanceThreshold = p_margin; space->dynamicsWorld->contactTest(&collision_object, btQuery); @@ -227,16 +232,17 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & return btQuery.m_count; } -bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_layer, uint32_t p_object_type_mask) { +bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude, uint32_t p_collision_mask) { ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->get(p_shape); - btConvexShape *btConvex = dynamic_cast<btConvexShape *>(shape->create_bt_shape()); - if (!btConvex) { - bulletdelete(btConvex); + btCollisionShape *btShape = shape->create_bt_shape(); + if (!btShape->isConvex()) { + bulletdelete(btShape); ERR_PRINTS("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return 0; } + btConvexShape *btConvex = static_cast<btConvexShape *>(btShape); btVector3 scale_with_margin; G_TO_B(p_shape_xform.basis.get_scale() + Vector3(p_margin, p_margin, p_margin), scale_with_margin); @@ -250,8 +256,8 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh collision_object.setWorldTransform(bt_xform); GodotRestInfoContactResultCallback btQuery(&collision_object, r_info, &p_exclude); - btQuery.m_collisionFilterGroup = p_collision_layer; - btQuery.m_collisionFilterMask = p_object_type_mask; + btQuery.m_collisionFilterGroup = 0; + btQuery.m_collisionFilterMask = p_collision_mask; btQuery.m_closestDistanceThreshold = p_margin; space->dynamicsWorld->contactTest(&collision_object, btQuery); @@ -777,7 +783,8 @@ void SpaceBullet::check_body_collision() { void SpaceBullet::update_gravity() { btVector3 btGravity; G_TO_B(gravityDirection * gravityMagnitude, btGravity); - dynamicsWorld->setGravity(btGravity); + //dynamicsWorld->setGravity(btGravity); + dynamicsWorld->setGravity(btVector3(0, 0, 0)); if (soft_body_world_info) { soft_body_world_info->m_gravity = btGravity; } @@ -877,11 +884,11 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f continue; } - btConvexShape *convex_shape_test(dynamic_cast<btConvexShape *>(p_body->get_bt_shape(shIndex))); - if (!convex_shape_test) { + if (!p_body->get_bt_shape(shIndex)->isConvex()) { // Skip no convex shape continue; } + btConvexShape *convex_shape_test(static_cast<btConvexShape *>(p_body->get_bt_shape(shIndex))); btTransform shape_world_from; G_TO_B(p_body->get_shape_transform(shIndex), shape_world_from); @@ -910,26 +917,26 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f { /// Phase three - Recover + contact test with margin - RecoverResult recover_result; + RecoverResult r_recover_result; - hasPenetration = recover_from_penetration(p_body, body_safe_position, recovered_motion, &recover_result); + hasPenetration = recover_from_penetration(p_body, body_safe_position, recovered_motion, &r_recover_result); if (r_result) { B_TO_G(recovered_motion + recover_initial_position, r_result->motion); if (hasPenetration) { - const btRigidBody *btRigid = static_cast<const btRigidBody *>(recover_result.other_collision_object); + const btRigidBody *btRigid = static_cast<const btRigidBody *>(r_recover_result.other_collision_object); CollisionObjectBullet *collisionObject = static_cast<CollisionObjectBullet *>(btRigid->getUserPointer()); r_result->remainder = p_motion - r_result->motion; // is the remaining movements - B_TO_G(recover_result.pointWorld, r_result->collision_point); - B_TO_G(recover_result.pointNormalWorld, r_result->collision_normal); - B_TO_G(btRigid->getVelocityInLocalPoint(recover_result.pointWorld - btRigid->getWorldTransform().getOrigin()), r_result->collider_velocity); // It calculates velocity at point and assign it using special function Bullet_to_Godot + B_TO_G(r_recover_result.pointWorld, r_result->collision_point); + B_TO_G(r_recover_result.pointNormalWorld, r_result->collision_normal); + B_TO_G(btRigid->getVelocityInLocalPoint(r_recover_result.pointWorld - btRigid->getWorldTransform().getOrigin()), r_result->collider_velocity); // It calculates velocity at point and assign it using special function Bullet_to_Godot r_result->collider = collisionObject->get_self(); r_result->collider_id = collisionObject->get_instance_id(); - r_result->collider_shape = recover_result.other_compound_shape_index; - r_result->collision_local_shape = recover_result.local_shape_most_recovered; + r_result->collider_shape = r_recover_result.other_compound_shape_index; + r_result->collision_local_shape = r_recover_result.local_shape_most_recovered; //{ /// Add manifold point to manage collisions // btPersistentManifold* manifold = dynamicsWorld->getDispatcher()->getNewManifold(p_body->getBtBody(), btRigid); @@ -995,7 +1002,7 @@ public: } }; -bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_body_position, btVector3 &out_recover_position, RecoverResult *recover_result) { +bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_body_position, btVector3 &r_recover_position, RecoverResult *r_recover_result) { RecoverPenetrationBroadPhaseCallback recover_broad_result(p_body->get_bt_collision_object(), p_body->get_collision_layer(), p_body->get_collision_mask()); @@ -1005,9 +1012,6 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran // Broad phase support btVector3 minAabb, maxAabb; - // GJK support - btGjkPairDetector::ClosestPointInput gjk_input; - bool penetration = false; // For each shape @@ -1022,7 +1026,7 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran body_shape_position = p_body_position * kin_shape.transform; body_shape_position_recovered = body_shape_position; - body_shape_position_recovered.getOrigin() += out_recover_position; + body_shape_position_recovered.getOrigin() += r_recover_position; kin_shape.shape->getAabb(body_shape_position_recovered, minAabb, maxAabb); dynamicsWorld->getBroadphase()->aabbTest(minAabb, maxAabb, recover_broad_result); @@ -1032,66 +1036,33 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran if (!p_body->get_bt_collision_object()->checkCollideWith(otherObject) || !otherObject->checkCollideWith(p_body->get_bt_collision_object())) continue; - if (otherObject->getCollisionShape()->isCompound()) { /// Execute GJK test against all shapes + if (otherObject->getCollisionShape()->isCompound()) { // Each convex shape btCompoundShape *cs = static_cast<btCompoundShape *>(otherObject->getCollisionShape()); for (int x = cs->getNumChildShapes() - 1; 0 <= x; --x) { - if (!cs->getChildShape(x)->isConvex()) - continue; + if (cs->getChildShape(x)->isConvex()) { + if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(cs->getChildShape(x)), otherObject, x, body_shape_position, otherObject->getWorldTransform() * cs->getChildTransform(x), r_recover_position, r_recover_result)) { - // Initialize GJK input - gjk_input.m_transformA = body_shape_position; - gjk_input.m_transformA.getOrigin() += out_recover_position; - gjk_input.m_transformB = otherObject->getWorldTransform() * cs->getChildTransform(x); + penetration = true; + } + } else { + if (RFP_convex_world_test(kin_shape.shape, cs->getChildShape(x), p_body->get_bt_collision_object(), otherObject, kinIndex, x, body_shape_position, otherObject->getWorldTransform() * cs->getChildTransform(x), r_recover_position, r_recover_result)) { - // Perform GJK test - btPointCollector result; - btGjkPairDetector gjk_pair_detector(kin_shape.shape, static_cast<const btConvexShape *>(cs->getChildShape(x)), gjk_simplex_solver, gjk_epa_pen_solver); - gjk_pair_detector.getClosestPoints(gjk_input, result, 0); - if (0 > result.m_distance) { - // Has penetration - out_recover_position += result.m_normalOnBInWorld * (result.m_distance * -1); - penetration = true; - - if (recover_result) { - - recover_result->hasPenetration = true; - recover_result->other_collision_object = otherObject; - recover_result->other_compound_shape_index = x; - recover_result->penetration_distance = result.m_distance; - recover_result->pointNormalWorld = result.m_normalOnBInWorld; - recover_result->pointWorld = result.m_pointInWorld; + penetration = true; } } } - } else if (otherObject->getCollisionShape()->isConvex()) { /// Execute GJK test against object shape + if (RFP_convex_convex_test(kin_shape.shape, static_cast<const btConvexShape *>(otherObject->getCollisionShape()), otherObject, 0, body_shape_position, otherObject->getWorldTransform(), r_recover_position, r_recover_result)) { - // Initialize GJK input - gjk_input.m_transformA = body_shape_position; - gjk_input.m_transformA.getOrigin() += out_recover_position; - gjk_input.m_transformB = otherObject->getWorldTransform(); - - // Perform GJK test - btPointCollector result; - btGjkPairDetector gjk_pair_detector(kin_shape.shape, static_cast<const btConvexShape *>(otherObject->getCollisionShape()), gjk_simplex_solver, gjk_epa_pen_solver); - gjk_pair_detector.getClosestPoints(gjk_input, result, 0); - if (0 > result.m_distance) { - // Has penetration - out_recover_position += result.m_normalOnBInWorld * (result.m_distance * -1); penetration = true; + } + } else { + if (RFP_convex_world_test(kin_shape.shape, otherObject->getCollisionShape(), p_body->get_bt_collision_object(), otherObject, kinIndex, 0, body_shape_position, otherObject->getWorldTransform(), r_recover_position, r_recover_result)) { - if (recover_result) { - - recover_result->hasPenetration = true; - recover_result->other_collision_object = otherObject; - recover_result->other_compound_shape_index = 0; - recover_result->penetration_distance = result.m_distance; - recover_result->pointNormalWorld = result.m_normalOnBInWorld; - recover_result->pointWorld = result.m_pointInWorld; - } + penetration = true; } } } @@ -1099,3 +1070,70 @@ bool SpaceBullet::recover_from_penetration(RigidBodyBullet *p_body, const btTran return penetration; } + +bool SpaceBullet::RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btVector3 &r_recover_position, RecoverResult *r_recover_result) { + + // Initialize GJK input + btGjkPairDetector::ClosestPointInput gjk_input; + gjk_input.m_transformA = p_transformA; + gjk_input.m_transformA.getOrigin() += r_recover_position; + gjk_input.m_transformB = p_transformB; + + // Perform GJK test + btPointCollector result; + btGjkPairDetector gjk_pair_detector(p_shapeA, p_shapeB, gjk_simplex_solver, gjk_epa_pen_solver); + gjk_pair_detector.getClosestPoints(gjk_input, result, 0); + if (0 > result.m_distance) { + // Has penetration + r_recover_position += result.m_normalOnBInWorld * (result.m_distance * -1); + + if (r_recover_result) { + + r_recover_result->hasPenetration = true; + r_recover_result->other_collision_object = p_objectB; + r_recover_result->other_compound_shape_index = p_shapeId_B; + r_recover_result->penetration_distance = result.m_distance; + r_recover_result->pointNormalWorld = result.m_normalOnBInWorld; + r_recover_result->pointWorld = result.m_pointInWorld; + } + return true; + } + return false; +} + +bool SpaceBullet::RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btVector3 &r_recover_position, RecoverResult *r_recover_result) { + + /// Contact test + + btTransform p_recovered_transformA(p_transformA); + p_recovered_transformA.getOrigin() += r_recover_position; + + btCollisionObjectWrapper obA(NULL, p_shapeA, p_objectA, p_recovered_transformA, -1, p_shapeId_A); + btCollisionObjectWrapper obB(NULL, p_shapeB, p_objectB, p_transformB, -1, p_shapeId_B); + + btCollisionAlgorithm *algorithm = dispatcher->findAlgorithm(&obA, &obB, NULL, BT_CLOSEST_POINT_ALGORITHMS); + if (algorithm) { + GodotDeepPenetrationContactResultCallback contactPointResult(&obA, &obB); + //discrete collision detection query + algorithm->processCollision(&obA, &obB, dynamicsWorld->getDispatchInfo(), &contactPointResult); + + algorithm->~btCollisionAlgorithm(); + dispatcher->freeCollisionAlgorithm(algorithm); + + if (contactPointResult.hasHit()) { + r_recover_position += contactPointResult.m_pointNormalWorld * (contactPointResult.m_penetration_distance * -1); + + if (r_recover_result) { + + r_recover_result->hasPenetration = true; + r_recover_result->other_collision_object = p_objectB; + r_recover_result->other_compound_shape_index = p_shapeId_B; + r_recover_result->penetration_distance = contactPointResult.m_penetration_distance; + r_recover_result->pointNormalWorld = contactPointResult.m_pointNormalWorld; + r_recover_result->pointWorld = contactPointResult.m_pointWorld; + } + return true; + } + } + return false; +} diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h index d9206f8046..99bcfb8563 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -69,13 +69,13 @@ private: public: BulletPhysicsDirectSpaceState(SpaceBullet *p_space); - virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION); - virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION, bool p_pick_ray = false); - virtual int 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 = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION); - virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION, ShapeRestInfo *r_info = NULL); + virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); + virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_pick_ray = false); + virtual int 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 = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); + virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, ShapeRestInfo *r_info = NULL); /// Returns the list of contacts pairs in this order: Local contact, other body contact - virtual bool 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 = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION); - virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_layer = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION); + virtual bool 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 = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); + virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF); virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const; }; @@ -189,6 +189,12 @@ private: : hasPenetration(false) {} }; - bool recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_from, btVector3 &out_recover_position, RecoverResult *recover_result = NULL); + bool recover_from_penetration(RigidBodyBullet *p_body, const btTransform &p_from, btVector3 &r_recover_position, RecoverResult *r_recover_result = NULL); + /// This is an API that recover a kinematic object from penetration + /// This allow only Convex Convex test and it always use GJK algorithm, With this API we don't benefit of Bullet special accelerated functions + bool RFP_convex_convex_test(const btConvexShape *p_shapeA, const btConvexShape *p_shapeB, btCollisionObject *p_objectB, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btVector3 &r_recover_position, RecoverResult *r_recover_result); + /// This is an API that recover a kinematic object from penetration + /// Using this we leave Bullet to select the best algorithm, For example GJK in case we have Convex Convex, or a Bullet accelerated algorithm + bool RFP_convex_world_test(const btConvexShape *p_shapeA, const btCollisionShape *p_shapeB, btCollisionObject *p_objectA, btCollisionObject *p_objectB, int p_shapeId_A, int p_shapeId_B, const btTransform &p_transformA, const btTransform &p_transformB, btVector3 &r_recover_position, RecoverResult *r_recover_result); }; #endif diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index c50886ad3c..1e18ec0d18 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -505,7 +505,7 @@ uint32_t NetworkedMultiplayerENet::_gen_unique_id() const { hash = hash_djb2_one_32( (uint32_t)OS::get_singleton()->get_unix_time(), hash); hash = hash_djb2_one_32( - (uint32_t)OS::get_singleton()->get_data_dir().hash64(), hash); + (uint32_t)OS::get_singleton()->get_user_data_dir().hash64(), hash); /* hash = hash_djb2_one_32( (uint32_t)OS::get_singleton()->get_unique_id().hash64(), hash ); diff --git a/modules/etc/image_etc.cpp b/modules/etc/image_etc.cpp index dc7d23bbd7..941df41694 100644 --- a/modules/etc/image_etc.cpp +++ b/modules/etc/image_etc.cpp @@ -129,7 +129,7 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f PoolVector<uint8_t>::Read r = img->get_data().read(); int target_size = Image::get_image_data_size(imgw, imgh, etc_format, p_img->has_mipmaps() ? -1 : 0); - int mmc = p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0; + int mmc = 1 + (p_img->has_mipmaps() ? Image::get_image_required_mipmaps(imgw, imgh, etc_format) : 0); PoolVector<uint8_t> dst_data; dst_data.resize(target_size); @@ -155,7 +155,7 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f print_line("begin encoding, format: " + Image::get_format_name(etc_format)); uint64_t t = OS::get_singleton()->get_ticks_msec(); - for (int i = 0; i < mmc + 1; i++) { + for (int i = 0; i < mmc; i++) { // convert source image to internal etc2comp format (which is equivalent to Image::FORMAT_RGBAF) // NOTE: We can alternatively add a case to Image::convert to handle Image::FORMAT_RGBAF conversion. int mipmap_ofs = 0, mipmap_size = 0, mipmap_w = 0, mipmap_h = 0; @@ -163,9 +163,9 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f const uint8_t *src = &r[mipmap_ofs]; Etc::ColorFloatRGBA *src_rgba_f = new Etc::ColorFloatRGBA[mipmap_w * mipmap_h]; - for (int i = 0; i < mipmap_w * mipmap_h; i++) { - int si = i * 4; // RGBA8 - src_rgba_f[i] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]); + for (int j = 0; j < mipmap_w * mipmap_h; j++) { + int si = j * 4; // RGBA8 + src_rgba_f[j] = Etc::ColorFloatRGBA::ConvertFromRGBA8(src[si], src[si + 1], src[si + 2], src[si + 3]); } unsigned char *etc_data = NULL; @@ -173,15 +173,17 @@ static void _compress_etc(Image *p_img, float p_lossy_quality, bool force_etc1_f unsigned int extended_width = 0, extended_height = 0; Etc::Encode((float *)src_rgba_f, mipmap_w, mipmap_h, etc2comp_etc_format, error_metric, effort, num_cpus, num_cpus, &etc_data, &etc_data_len, &extended_width, &extended_height, &encoding_time); + CRASH_COND(wofs + etc_data_len > target_size); memcpy(&w[wofs], etc_data, etc_data_len); wofs += etc_data_len; delete[] etc_data; delete[] src_rgba_f; } + print_line("time encoding: " + rtos(OS::get_singleton()->get_ticks_msec() - t)); - p_img->create(imgw, imgh, mmc > 1 ? true : false, etc_format, dst_data); + p_img->create(imgw, imgh, p_img->has_mipmaps(), etc_format, dst_data); } static void _compress_etc1(Image *p_img, float p_lossy_quality) { diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 66b8d5cbdd..54d0672a5b 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -19,19 +19,27 @@ def _spaced(e): return e if e[-1] == '*' else e + ' ' def _build_gdnative_api_struct_header(api): - ext_wrappers = '' + gdnative_api_init_macro = [ + '\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;' + ] for name in api['extensions']: - ext_wrappers += ' extern const godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;' + gdnative_api_init_macro.append( + '\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;'.format(name)) - ext_init = 'for (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ' - ext_init += 'switch (_gdnative_wrapper_api_struct->extensions[i]->type) {' + gdnative_api_init_macro.append('\t_gdnative_wrapper_api_struct = options->api_struct;') + gdnative_api_init_macro.append('\tfor (int i = 0; i < _gdnative_wrapper_api_struct->num_extensions; i++) { ') + gdnative_api_init_macro.append('\t\tswitch (_gdnative_wrapper_api_struct->extensions[i]->type) {') for name in api['extensions']: - ext_init += 'case GDNATIVE_EXT_' + api['extensions'][name]['type'] + ': ' - ext_init += '_gdnative_wrapper_' + name + '_api_struct = (' + 'godot_gdnative_ext_' + name + '_api_struct *) _gdnative_wrapper_api_struct->extensions[i]; break;' - - ext_init += '}' + gdnative_api_init_macro.append( + '\t\t\tcase GDNATIVE_EXT_%s:' % api['extensions'][name]['type']) + gdnative_api_init_macro.append( + '\t\t\t\t_gdnative_wrapper_{0}_api_struct = (godot_gdnative_ext_{0}_api_struct *)' + ' _gdnative_wrapper_api_struct->extensions[i];'.format(name)) + gdnative_api_init_macro.append('\t\t\t\tbreak;') + gdnative_api_init_macro.append('\t\t}') + gdnative_api_init_macro.append('\t}') out = [ '/* THIS FILE IS GENERATED DO NOT EDIT */', @@ -43,25 +51,12 @@ def _build_gdnative_api_struct_header(api): '#include <nativescript/godot_nativescript.h>', '#include <pluginscript/godot_pluginscript.h>', '', - '#define GDNATIVE_API_INIT(options) do { extern const godot_gdnative_api_struct *_gdnative_wrapper_api_struct;' + ext_wrappers + ' _gdnative_wrapper_api_struct = options->api_struct; ' + ext_init + ' } while (0)', + '#define GDNATIVE_API_INIT(options) do { \\\n' + ' \\\n'.join(gdnative_api_init_macro) + ' \\\n } while (0)', '', '#ifdef __cplusplus', 'extern "C" {', '#endif', '', - 'typedef struct godot_gdnative_api_version {', - '\tunsigned int major;', - '\tunsigned int minor;', - '} godot_gdnative_api_version;', - '', - 'typedef struct godot_gdnative_api_struct godot_gdnative_api_struct;', - '', - 'struct godot_gdnative_api_struct {', - '\tunsigned int type;', - '\tgodot_gdnative_api_version version;', - '\tconst godot_gdnative_api_struct *next;', - '};', - '', 'enum GDNATIVE_API_TYPES {', '\tGDNATIVE_' + api['core']['type'] + ',' ] @@ -192,7 +187,7 @@ def _build_gdnative_wrapper_code(api): ] for name in api['extensions']: - out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct;') + out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct = 0;') out += [''] diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 44d6dffc85..0132ef3c5d 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -64,7 +64,6 @@ void GDNativeLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("get_current_library_path"), &GDNativeLibrary::get_current_library_path); ClassDB::bind_method(D_METHOD("get_current_dependencies"), &GDNativeLibrary::get_current_dependencies); - ClassDB::bind_method(D_METHOD("is_current_library_statically_linked"), &GDNativeLibrary::is_current_library_statically_linked); ClassDB::bind_method(D_METHOD("should_load_once"), &GDNativeLibrary::should_load_once); ClassDB::bind_method(D_METHOD("is_singleton"), &GDNativeLibrary::is_singleton); @@ -109,6 +108,9 @@ Ref<GDNativeLibrary> GDNative::get_library() { return library; } +extern "C" void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have); +extern "C" void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what); + bool GDNative::initialize() { if (library.is_null()) { ERR_PRINT("No library set, can't initialize GDNative object"); @@ -116,12 +118,18 @@ bool GDNative::initialize() { } String lib_path = library->get_current_library_path(); - if (lib_path.empty() && !library->is_current_library_statically_linked()) { + if (lib_path.empty()) { ERR_PRINT("No library set for this platform"); return false; } #ifdef IPHONE_ENABLED - String path = lib_path.replace("res://", "dylibs/"); + // on iOS we use static linking + String path = ""; +#elif defined(ANDROID_ENABLED) + // On Android dynamic libraries are located separately from resource assets, + // we should pass library name to dlopen(). The library name is flattened + // during export. + String path = lib_path.get_file(); #else String path = ProjectSettings::get_singleton()->globalize_path(lib_path); #endif @@ -137,7 +145,7 @@ bool GDNative::initialize() { } Error err = OS::get_singleton()->open_dynamic_library(path, native_handle); - if (err != OK && !library->is_current_library_statically_linked()) { + if (err != OK) { return false; } @@ -146,13 +154,12 @@ bool GDNative::initialize() { // we cheat here a little bit. you saw nothing initialized = true; - err = get_symbol(library->get_symbol_prefix() + init_symbol, library_init); + err = get_symbol(library->get_symbol_prefix() + init_symbol, library_init, false); initialized = false; if (err || !library_init) { - if (!library->is_current_library_statically_linked()) - OS::get_singleton()->close_dynamic_library(native_handle); + OS::get_singleton()->close_dynamic_library(native_handle); native_handle = NULL; ERR_PRINT("Failed to obtain godot_gdnative_init symbol"); return false; @@ -168,6 +175,8 @@ bool GDNative::initialize() { options.core_api_hash = ClassDB::get_api_hash(ClassDB::API_CORE); options.editor_api_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); options.no_api_hash = ClassDB::get_api_hash(ClassDB::API_NONE); + options.report_version_mismatch = &_gdnative_report_version_mismatch; + options.report_loading_error = &_gdnative_report_loading_error; options.gd_native_library = (godot_object *)(get_library().ptr()); options.active_library_path = (godot_string *)&path; @@ -277,7 +286,7 @@ Variant GDNative::call_native(StringName p_native_call_type, StringName p_proced return *(Variant *)&result; } -Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle) { +Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional) { if (!initialized) { ERR_PRINT("No valid library handle, can't get symbol from GDNative object"); @@ -288,7 +297,7 @@ Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle) { native_handle, p_procedure_name, r_handle, - true); + p_optional); return result; } @@ -369,40 +378,8 @@ RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_or } } - bool is_statically_linked = false; - { - - List<String> static_linking_keys; - config->get_section_keys("static_linking", &static_linking_keys); - - for (List<String>::Element *E = static_linking_keys.front(); E; E = E->next()) { - String key = E->get(); - - Vector<String> tags = key.split("."); - - bool skip = false; - - for (int i = 0; i < tags.size(); i++) { - bool has_feature = OS::get_singleton()->has_feature(tags[i]); - - if (!has_feature) { - skip = true; - break; - } - } - - if (skip) { - continue; - } - - is_statically_linked = config->get_value("static_linking", key); - break; - } - } - lib->current_library_path = entry_lib_path; lib->current_dependencies = dependency_paths; - lib->current_library_statically_linked = is_statically_linked; return lib; } diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index 061dff9267..bb260bdd1b 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -55,7 +55,6 @@ class GDNativeLibrary : public Resource { String current_library_path; Vector<String> current_dependencies; - bool current_library_statically_linked; bool singleton; bool load_once; @@ -75,9 +74,6 @@ public: _FORCE_INLINE_ Vector<String> get_current_dependencies() const { return current_dependencies; } - _FORCE_INLINE_ bool is_current_library_statically_linked() const { - return current_library_statically_linked; - } // things that are a property of the library itself, not platform specific _FORCE_INLINE_ bool should_load_once() const { @@ -103,12 +99,10 @@ public: static void _bind_methods(); }; -typedef godot_variant (*native_call_cb)(void *, godot_array *); - struct GDNativeCallRegistry { static GDNativeCallRegistry *singleton; - inline GDNativeCallRegistry *get_singleton() { + inline static GDNativeCallRegistry *get_singleton() { return singleton; } @@ -147,7 +141,7 @@ public: Variant call_native(StringName p_native_call_type, StringName p_procedure_name, Array p_arguments = Array()); - Error get_symbol(StringName p_procedure_name, void *&r_handle); + Error get_symbol(StringName p_procedure_name, void *&r_handle, bool p_optional = true); }; class GDNativeLibraryResourceLoader : public ResourceFormatLoader { diff --git a/modules/gdnative/gdnative/aabb.cpp b/modules/gdnative/gdnative/aabb.cpp new file mode 100644 index 0000000000..6c89bcdceb --- /dev/null +++ b/modules/gdnative/gdnative/aabb.cpp @@ -0,0 +1,217 @@ +/*************************************************************************/ +/* aabb.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#include "gdnative/aabb.h" + +#include "core/math/aabb.h" +#include "core/variant.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void GDAPI godot_aabb_new(godot_aabb *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size) { + const Vector3 *pos = (const Vector3 *)p_pos; + const Vector3 *size = (const Vector3 *)p_size; + AABB *dest = (AABB *)r_dest; + *dest = AABB(*pos, *size); +} + +godot_vector3 GDAPI godot_aabb_get_position(const godot_aabb *p_self) { + godot_vector3 raw_ret; + const AABB *self = (const AABB *)p_self; + Vector3 *ret = (Vector3 *)&raw_ret; + *ret = self->position; + return raw_ret; +} + +void GDAPI godot_aabb_set_position(const godot_aabb *p_self, const godot_vector3 *p_v) { + AABB *self = (AABB *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + self->position = *v; +} + +godot_vector3 GDAPI godot_aabb_get_size(const godot_aabb *p_self) { + godot_vector3 raw_ret; + const AABB *self = (const AABB *)p_self; + Vector3 *ret = (Vector3 *)&raw_ret; + *ret = self->size; + return raw_ret; +} + +void GDAPI godot_aabb_set_size(const godot_aabb *p_self, const godot_vector3 *p_v) { + AABB *self = (AABB *)p_self; + const Vector3 *v = (const Vector3 *)p_v; + self->size = *v; +} + +godot_string GDAPI godot_aabb_as_string(const godot_aabb *p_self) { + godot_string ret; + const AABB *self = (const AABB *)p_self; + memnew_placement(&ret, String(*self)); + return ret; +} + +godot_real GDAPI godot_aabb_get_area(const godot_aabb *p_self) { + const AABB *self = (const AABB *)p_self; + return self->get_area(); +} + +godot_bool GDAPI godot_aabb_has_no_area(const godot_aabb *p_self) { + const AABB *self = (const AABB *)p_self; + return self->has_no_area(); +} + +godot_bool GDAPI godot_aabb_has_no_surface(const godot_aabb *p_self) { + const AABB *self = (const AABB *)p_self; + return self->has_no_surface(); +} + +godot_bool GDAPI godot_aabb_intersects(const godot_aabb *p_self, const godot_aabb *p_with) { + const AABB *self = (const AABB *)p_self; + const AABB *with = (const AABB *)p_with; + return self->intersects(*with); +} + +godot_bool GDAPI godot_aabb_encloses(const godot_aabb *p_self, const godot_aabb *p_with) { + const AABB *self = (const AABB *)p_self; + const AABB *with = (const AABB *)p_with; + return self->encloses(*with); +} + +godot_aabb GDAPI godot_aabb_merge(const godot_aabb *p_self, const godot_aabb *p_with) { + godot_aabb dest; + const AABB *self = (const AABB *)p_self; + const AABB *with = (const AABB *)p_with; + *((AABB *)&dest) = self->merge(*with); + return dest; +} + +godot_aabb GDAPI godot_aabb_intersection(const godot_aabb *p_self, const godot_aabb *p_with) { + godot_aabb dest; + const AABB *self = (const AABB *)p_self; + const AABB *with = (const AABB *)p_with; + *((AABB *)&dest) = self->intersection(*with); + return dest; +} + +godot_bool GDAPI godot_aabb_intersects_plane(const godot_aabb *p_self, const godot_plane *p_plane) { + const AABB *self = (const AABB *)p_self; + const Plane *plane = (const Plane *)p_plane; + return self->intersects_plane(*plane); +} + +godot_bool GDAPI godot_aabb_intersects_segment(const godot_aabb *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to) { + const AABB *self = (const AABB *)p_self; + const Vector3 *from = (const Vector3 *)p_from; + const Vector3 *to = (const Vector3 *)p_to; + return self->intersects_segment(*from, *to); +} + +godot_bool GDAPI godot_aabb_has_point(const godot_aabb *p_self, const godot_vector3 *p_point) { + const AABB *self = (const AABB *)p_self; + const Vector3 *point = (const Vector3 *)p_point; + return self->has_point(*point); +} + +godot_vector3 GDAPI godot_aabb_get_support(const godot_aabb *p_self, const godot_vector3 *p_dir) { + godot_vector3 dest; + const AABB *self = (const AABB *)p_self; + const Vector3 *dir = (const Vector3 *)p_dir; + *((Vector3 *)&dest) = self->get_support(*dir); + return dest; +} + +godot_vector3 GDAPI godot_aabb_get_longest_axis(const godot_aabb *p_self) { + godot_vector3 dest; + const AABB *self = (const AABB *)p_self; + *((Vector3 *)&dest) = self->get_longest_axis(); + return dest; +} + +godot_int GDAPI godot_aabb_get_longest_axis_index(const godot_aabb *p_self) { + const AABB *self = (const AABB *)p_self; + return self->get_longest_axis_index(); +} + +godot_real GDAPI godot_aabb_get_longest_axis_size(const godot_aabb *p_self) { + const AABB *self = (const AABB *)p_self; + return self->get_longest_axis_size(); +} + +godot_vector3 GDAPI godot_aabb_get_shortest_axis(const godot_aabb *p_self) { + godot_vector3 dest; + const AABB *self = (const AABB *)p_self; + *((Vector3 *)&dest) = self->get_shortest_axis(); + return dest; +} + +godot_int GDAPI godot_aabb_get_shortest_axis_index(const godot_aabb *p_self) { + const AABB *self = (const AABB *)p_self; + return self->get_shortest_axis_index(); +} + +godot_real GDAPI godot_aabb_get_shortest_axis_size(const godot_aabb *p_self) { + const AABB *self = (const AABB *)p_self; + return self->get_shortest_axis_size(); +} + +godot_aabb GDAPI godot_aabb_expand(const godot_aabb *p_self, const godot_vector3 *p_to_point) { + godot_aabb dest; + const AABB *self = (const AABB *)p_self; + const Vector3 *to_point = (const Vector3 *)p_to_point; + *((AABB *)&dest) = self->expand(*to_point); + return dest; +} + +godot_aabb GDAPI godot_aabb_grow(const godot_aabb *p_self, const godot_real p_by) { + godot_aabb dest; + const AABB *self = (const AABB *)p_self; + + *((AABB *)&dest) = self->grow(p_by); + return dest; +} + +godot_vector3 GDAPI godot_aabb_get_endpoint(const godot_aabb *p_self, const godot_int p_idx) { + godot_vector3 dest; + const AABB *self = (const AABB *)p_self; + + *((Vector3 *)&dest) = self->get_endpoint(p_idx); + return dest; +} + +godot_bool GDAPI godot_aabb_operator_equal(const godot_aabb *p_self, const godot_aabb *p_b) { + const AABB *self = (const AABB *)p_self; + const AABB *b = (const AABB *)p_b; + return *self == *b; +} + +#ifdef __cplusplus +} +#endif diff --git a/modules/gdnative/gdnative/array.cpp b/modules/gdnative/gdnative/array.cpp index e0d9514985..8351c43574 100644 --- a/modules/gdnative/gdnative/array.cpp +++ b/modules/gdnative/gdnative/array.cpp @@ -302,6 +302,17 @@ void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, con self->sort_custom((Object *)p_obj, *func); } +godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before) { + Array *self = (Array *)p_self; + return self->bsearch((const Variant *)p_value, p_before); +} + +godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before) { + Array *self = (Array *)p_self; + const String *func = (const String *)p_func; + return self->bsearch_custom((const Variant *)p_value, (Object *)p_obj, *func, p_before); +} + void GDAPI godot_array_destroy(godot_array *p_self) { ((Array *)p_self)->~Array(); } diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp index 6dfa7ec20b..92a88e354b 100644 --- a/modules/gdnative/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative/gdnative.cpp @@ -36,6 +36,8 @@ #include "os/os.h" #include "variant.h" +#include "modules/gdnative/gdnative.h" + #ifdef __cplusplus extern "C" { #endif @@ -113,6 +115,10 @@ godot_dictionary GDAPI godot_get_global_constants() { } // System functions +void GDAPI godot_register_native_call_type(const char *p_call_type, native_call_cb p_callback) { + GDNativeCallRegistry::get_singleton()->register_native_call_type(StringName(p_call_type), p_callback); +} + void GDAPI *godot_alloc(int p_bytes) { return memalloc(p_bytes); } @@ -137,6 +143,32 @@ void GDAPI godot_print(const godot_string *p_message) { print_line(*(String *)p_message); } +void _gdnative_report_version_mismatch(const godot_object *p_library, const char *p_ext, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have) { + String message = "Error loading GDNative file "; + GDNativeLibrary *library = (GDNativeLibrary *)p_library; + + message += library->get_current_library_path() + ": Extension \"" + p_ext + "\" can't be loaded.\n"; + + Dictionary versions; + versions["have_major"] = p_have.major; + versions["have_minor"] = p_have.minor; + versions["want_major"] = p_want.major; + versions["want_minor"] = p_want.minor; + + message += String("Got version {have_major}.{have_minor} but needs {want_major}.{want_minor}!").format(versions); + + _err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr()); +} + +void _gdnative_report_loading_error(const godot_object *p_library, const char *p_what) { + String message = "Error loading GDNative file "; + GDNativeLibrary *library = (GDNativeLibrary *)p_library; + + message += library->get_current_library_path() + ": " + p_what; + + _err_print_error("gdnative_init", library->get_current_library_path().utf8().ptr(), 0, message.utf8().ptr()); +} + #ifdef __cplusplus } #endif diff --git a/modules/gdnative/gdnative/node_path.cpp b/modules/gdnative/gdnative/node_path.cpp index 2bd278e050..8dfe151f91 100644 --- a/modules/gdnative/gdnative/node_path.cpp +++ b/modules/gdnative/gdnative/node_path.cpp @@ -91,10 +91,10 @@ godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, co return dest; } -godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self) { +godot_string GDAPI godot_node_path_get_concatenated_subnames(const godot_node_path *p_self) { godot_string dest; const NodePath *self = (const NodePath *)p_self; - memnew_placement(&dest, String(self->get_property())); + memnew_placement(&dest, String(self->get_concatenated_subnames())); return dest; } diff --git a/modules/gdnative/gdnative/rect3.cpp b/modules/gdnative/gdnative/rect3.cpp deleted file mode 100644 index 8e088743b4..0000000000 --- a/modules/gdnative/gdnative/rect3.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/*************************************************************************/ -/* rect3.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#include "gdnative/rect3.h" - -#include "core/math/rect3.h" -#include "core/variant.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size) { - const Vector3 *pos = (const Vector3 *)p_pos; - const Vector3 *size = (const Vector3 *)p_size; - Rect3 *dest = (Rect3 *)r_dest; - *dest = Rect3(*pos, *size); -} - -godot_vector3 GDAPI godot_rect3_get_position(const godot_rect3 *p_self) { - godot_vector3 raw_ret; - const Rect3 *self = (const Rect3 *)p_self; - Vector3 *ret = (Vector3 *)&raw_ret; - *ret = self->position; - return raw_ret; -} - -void GDAPI godot_rect3_set_position(const godot_rect3 *p_self, const godot_vector3 *p_v) { - Rect3 *self = (Rect3 *)p_self; - const Vector3 *v = (const Vector3 *)p_v; - self->position = *v; -} - -godot_vector3 GDAPI godot_rect3_get_size(const godot_rect3 *p_self) { - godot_vector3 raw_ret; - const Rect3 *self = (const Rect3 *)p_self; - Vector3 *ret = (Vector3 *)&raw_ret; - *ret = self->size; - return raw_ret; -} - -void GDAPI godot_rect3_set_size(const godot_rect3 *p_self, const godot_vector3 *p_v) { - Rect3 *self = (Rect3 *)p_self; - const Vector3 *v = (const Vector3 *)p_v; - self->size = *v; -} - -godot_string GDAPI godot_rect3_as_string(const godot_rect3 *p_self) { - godot_string ret; - const Rect3 *self = (const Rect3 *)p_self; - memnew_placement(&ret, String(*self)); - return ret; -} - -godot_real GDAPI godot_rect3_get_area(const godot_rect3 *p_self) { - const Rect3 *self = (const Rect3 *)p_self; - return self->get_area(); -} - -godot_bool GDAPI godot_rect3_has_no_area(const godot_rect3 *p_self) { - const Rect3 *self = (const Rect3 *)p_self; - return self->has_no_area(); -} - -godot_bool GDAPI godot_rect3_has_no_surface(const godot_rect3 *p_self) { - const Rect3 *self = (const Rect3 *)p_self; - return self->has_no_surface(); -} - -godot_bool GDAPI godot_rect3_intersects(const godot_rect3 *p_self, const godot_rect3 *p_with) { - const Rect3 *self = (const Rect3 *)p_self; - const Rect3 *with = (const Rect3 *)p_with; - return self->intersects(*with); -} - -godot_bool GDAPI godot_rect3_encloses(const godot_rect3 *p_self, const godot_rect3 *p_with) { - const Rect3 *self = (const Rect3 *)p_self; - const Rect3 *with = (const Rect3 *)p_with; - return self->encloses(*with); -} - -godot_rect3 GDAPI godot_rect3_merge(const godot_rect3 *p_self, const godot_rect3 *p_with) { - godot_rect3 dest; - const Rect3 *self = (const Rect3 *)p_self; - const Rect3 *with = (const Rect3 *)p_with; - *((Rect3 *)&dest) = self->merge(*with); - return dest; -} - -godot_rect3 GDAPI godot_rect3_intersection(const godot_rect3 *p_self, const godot_rect3 *p_with) { - godot_rect3 dest; - const Rect3 *self = (const Rect3 *)p_self; - const Rect3 *with = (const Rect3 *)p_with; - *((Rect3 *)&dest) = self->intersection(*with); - return dest; -} - -godot_bool GDAPI godot_rect3_intersects_plane(const godot_rect3 *p_self, const godot_plane *p_plane) { - const Rect3 *self = (const Rect3 *)p_self; - const Plane *plane = (const Plane *)p_plane; - return self->intersects_plane(*plane); -} - -godot_bool GDAPI godot_rect3_intersects_segment(const godot_rect3 *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to) { - const Rect3 *self = (const Rect3 *)p_self; - const Vector3 *from = (const Vector3 *)p_from; - const Vector3 *to = (const Vector3 *)p_to; - return self->intersects_segment(*from, *to); -} - -godot_bool GDAPI godot_rect3_has_point(const godot_rect3 *p_self, const godot_vector3 *p_point) { - const Rect3 *self = (const Rect3 *)p_self; - const Vector3 *point = (const Vector3 *)p_point; - return self->has_point(*point); -} - -godot_vector3 GDAPI godot_rect3_get_support(const godot_rect3 *p_self, const godot_vector3 *p_dir) { - godot_vector3 dest; - const Rect3 *self = (const Rect3 *)p_self; - const Vector3 *dir = (const Vector3 *)p_dir; - *((Vector3 *)&dest) = self->get_support(*dir); - return dest; -} - -godot_vector3 GDAPI godot_rect3_get_longest_axis(const godot_rect3 *p_self) { - godot_vector3 dest; - const Rect3 *self = (const Rect3 *)p_self; - *((Vector3 *)&dest) = self->get_longest_axis(); - return dest; -} - -godot_int GDAPI godot_rect3_get_longest_axis_index(const godot_rect3 *p_self) { - const Rect3 *self = (const Rect3 *)p_self; - return self->get_longest_axis_index(); -} - -godot_real GDAPI godot_rect3_get_longest_axis_size(const godot_rect3 *p_self) { - const Rect3 *self = (const Rect3 *)p_self; - return self->get_longest_axis_size(); -} - -godot_vector3 GDAPI godot_rect3_get_shortest_axis(const godot_rect3 *p_self) { - godot_vector3 dest; - const Rect3 *self = (const Rect3 *)p_self; - *((Vector3 *)&dest) = self->get_shortest_axis(); - return dest; -} - -godot_int GDAPI godot_rect3_get_shortest_axis_index(const godot_rect3 *p_self) { - const Rect3 *self = (const Rect3 *)p_self; - return self->get_shortest_axis_index(); -} - -godot_real GDAPI godot_rect3_get_shortest_axis_size(const godot_rect3 *p_self) { - const Rect3 *self = (const Rect3 *)p_self; - return self->get_shortest_axis_size(); -} - -godot_rect3 GDAPI godot_rect3_expand(const godot_rect3 *p_self, const godot_vector3 *p_to_point) { - godot_rect3 dest; - const Rect3 *self = (const Rect3 *)p_self; - const Vector3 *to_point = (const Vector3 *)p_to_point; - *((Rect3 *)&dest) = self->expand(*to_point); - return dest; -} - -godot_rect3 GDAPI godot_rect3_grow(const godot_rect3 *p_self, const godot_real p_by) { - godot_rect3 dest; - const Rect3 *self = (const Rect3 *)p_self; - - *((Rect3 *)&dest) = self->grow(p_by); - return dest; -} - -godot_vector3 GDAPI godot_rect3_get_endpoint(const godot_rect3 *p_self, const godot_int p_idx) { - godot_vector3 dest; - const Rect3 *self = (const Rect3 *)p_self; - - *((Vector3 *)&dest) = self->get_endpoint(p_idx); - return dest; -} - -godot_bool GDAPI godot_rect3_operator_equal(const godot_rect3 *p_self, const godot_rect3 *p_b) { - const Rect3 *self = (const Rect3 *)p_self; - const Rect3 *b = (const Rect3 *)p_b; - return *self == *b; -} - -#ifdef __cplusplus -} -#endif diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 781b8754bd..67a037736c 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -89,11 +89,6 @@ wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, cons return self->operator[](p_idx); } -const char GDAPI *godot_string_c_str(const godot_string *p_self) { - const String *self = (const String *)p_self; - return self->utf8().get_data(); -} - const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self) { const String *self = (const String *)p_self; return self->c_str(); diff --git a/modules/gdnative/gdnative/transform.cpp b/modules/gdnative/gdnative/transform.cpp index 96b2ec8a7a..b07fcffcb6 100644 --- a/modules/gdnative/gdnative/transform.cpp +++ b/modules/gdnative/gdnative/transform.cpp @@ -198,20 +198,20 @@ godot_vector3 GDAPI godot_transform_xform_inv_vector3(const godot_transform *p_s return raw_dest; } -godot_rect3 GDAPI godot_transform_xform_rect3(const godot_transform *p_self, const godot_rect3 *p_v) { - godot_rect3 raw_dest; - Rect3 *dest = (Rect3 *)&raw_dest; +godot_aabb GDAPI godot_transform_xform_aabb(const godot_transform *p_self, const godot_aabb *p_v) { + godot_aabb raw_dest; + AABB *dest = (AABB *)&raw_dest; const Transform *self = (const Transform *)p_self; - const Rect3 *v = (const Rect3 *)p_v; + const AABB *v = (const AABB *)p_v; *dest = self->xform(*v); return raw_dest; } -godot_rect3 GDAPI godot_transform_xform_inv_rect3(const godot_transform *p_self, const godot_rect3 *p_v) { - godot_rect3 raw_dest; - Rect3 *dest = (Rect3 *)&raw_dest; +godot_aabb GDAPI godot_transform_xform_inv_aabb(const godot_transform *p_self, const godot_aabb *p_v) { + godot_aabb raw_dest; + AABB *dest = (AABB *)&raw_dest; const Transform *self = (const Transform *)p_self; - const Rect3 *v = (const Rect3 *)p_v; + const AABB *v = (const AABB *)p_v; *dest = self->xform_inv(*v); return raw_dest; } diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp index 0c31bc643c..6483d19d74 100644 --- a/modules/gdnative/gdnative/variant.cpp +++ b/modules/gdnative/gdnative/variant.cpp @@ -118,10 +118,10 @@ void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_qua memnew_placement_custom(dest, Variant, Variant(*quat)); } -void GDAPI godot_variant_new_rect3(godot_variant *r_dest, const godot_rect3 *p_rect3) { +void GDAPI godot_variant_new_aabb(godot_variant *r_dest, const godot_aabb *p_aabb) { Variant *dest = (Variant *)r_dest; - Rect3 *rect3 = (Rect3 *)p_rect3; - memnew_placement_custom(dest, Variant, Variant(*rect3)); + AABB *aabb = (AABB *)p_aabb; + memnew_placement_custom(dest, Variant, Variant(*aabb)); } void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis) { @@ -304,10 +304,10 @@ godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self) { return raw_dest; } -godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_self) { - godot_rect3 raw_dest; +godot_aabb GDAPI godot_variant_as_aabb(const godot_variant *p_self) { + godot_aabb raw_dest; const Variant *self = (const Variant *)p_self; - Rect3 *dest = (Rect3 *)&raw_dest; + AABB *dest = (AABB *)&raw_dest; *dest = *self; return raw_dest; } diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 770fb429c7..488ed93206 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -2680,6 +2680,26 @@ ] }, { + "name": "godot_array_bsearch", + "return_type": "godot_int", + "arguments": [ + ["godot_array *", "p_self"], + ["const godot_variant *", "p_value"], + ["const godot_bool", "p_before"] + ] + }, + { + "name": "godot_array_bsearch_custom", + "return_type": "godot_int", + "arguments": [ + ["godot_array *", "p_self"], + ["const godot_variant *", "p_value"], + ["godot_object *", "p_obj"], + ["const godot_string *", "p_func"], + ["const godot_bool", "p_before"] + ] + }, + { "name": "godot_array_destroy", "return_type": "void", "arguments": [ @@ -2898,7 +2918,7 @@ ] }, { - "name": "godot_node_path_get_property", + "name": "godot_node_path_get_concatenated_subnames", "return_type": "godot_string", "arguments": [ ["const godot_node_path *", "p_self"] @@ -3221,209 +3241,209 @@ ] }, { - "name": "godot_rect3_new", + "name": "godot_aabb_new", "return_type": "void", "arguments": [ - ["godot_rect3 *", "r_dest"], + ["godot_aabb *", "r_dest"], ["const godot_vector3 *", "p_pos"], ["const godot_vector3 *", "p_size"] ] }, { - "name": "godot_rect3_get_position", + "name": "godot_aabb_get_position", "return_type": "godot_vector3", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_set_position", + "name": "godot_aabb_set_position", "return_type": "void", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_vector3 *", "p_v"] ] }, { - "name": "godot_rect3_get_size", + "name": "godot_aabb_get_size", "return_type": "godot_vector3", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_set_size", + "name": "godot_aabb_set_size", "return_type": "void", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_vector3 *", "p_v"] ] }, { - "name": "godot_rect3_as_string", + "name": "godot_aabb_as_string", "return_type": "godot_string", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_get_area", + "name": "godot_aabb_get_area", "return_type": "godot_real", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_has_no_area", + "name": "godot_aabb_has_no_area", "return_type": "godot_bool", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_has_no_surface", + "name": "godot_aabb_has_no_surface", "return_type": "godot_bool", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_intersects", + "name": "godot_aabb_intersects", "return_type": "godot_bool", "arguments": [ - ["const godot_rect3 *", "p_self"], - ["const godot_rect3 *", "p_with"] + ["const godot_aabb *", "p_self"], + ["const godot_aabb *", "p_with"] ] }, { - "name": "godot_rect3_encloses", + "name": "godot_aabb_encloses", "return_type": "godot_bool", "arguments": [ - ["const godot_rect3 *", "p_self"], - ["const godot_rect3 *", "p_with"] + ["const godot_aabb *", "p_self"], + ["const godot_aabb *", "p_with"] ] }, { - "name": "godot_rect3_merge", - "return_type": "godot_rect3", + "name": "godot_aabb_merge", + "return_type": "godot_aabb", "arguments": [ - ["const godot_rect3 *", "p_self"], - ["const godot_rect3 *", "p_with"] + ["const godot_aabb *", "p_self"], + ["const godot_aabb *", "p_with"] ] }, { - "name": "godot_rect3_intersection", - "return_type": "godot_rect3", + "name": "godot_aabb_intersection", + "return_type": "godot_aabb", "arguments": [ - ["const godot_rect3 *", "p_self"], - ["const godot_rect3 *", "p_with"] + ["const godot_aabb *", "p_self"], + ["const godot_aabb *", "p_with"] ] }, { - "name": "godot_rect3_intersects_plane", + "name": "godot_aabb_intersects_plane", "return_type": "godot_bool", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_plane *", "p_plane"] ] }, { - "name": "godot_rect3_intersects_segment", + "name": "godot_aabb_intersects_segment", "return_type": "godot_bool", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_vector3 *", "p_from"], ["const godot_vector3 *", "p_to"] ] }, { - "name": "godot_rect3_has_point", + "name": "godot_aabb_has_point", "return_type": "godot_bool", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_vector3 *", "p_point"] ] }, { - "name": "godot_rect3_get_support", + "name": "godot_aabb_get_support", "return_type": "godot_vector3", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_vector3 *", "p_dir"] ] }, { - "name": "godot_rect3_get_longest_axis", + "name": "godot_aabb_get_longest_axis", "return_type": "godot_vector3", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_get_longest_axis_index", + "name": "godot_aabb_get_longest_axis_index", "return_type": "godot_int", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_get_longest_axis_size", + "name": "godot_aabb_get_longest_axis_size", "return_type": "godot_real", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_get_shortest_axis", + "name": "godot_aabb_get_shortest_axis", "return_type": "godot_vector3", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_get_shortest_axis_index", + "name": "godot_aabb_get_shortest_axis_index", "return_type": "godot_int", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_get_shortest_axis_size", + "name": "godot_aabb_get_shortest_axis_size", "return_type": "godot_real", "arguments": [ - ["const godot_rect3 *", "p_self"] + ["const godot_aabb *", "p_self"] ] }, { - "name": "godot_rect3_expand", - "return_type": "godot_rect3", + "name": "godot_aabb_expand", + "return_type": "godot_aabb", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_vector3 *", "p_to_point"] ] }, { - "name": "godot_rect3_grow", - "return_type": "godot_rect3", + "name": "godot_aabb_grow", + "return_type": "godot_aabb", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_real", "p_by"] ] }, { - "name": "godot_rect3_get_endpoint", + "name": "godot_aabb_get_endpoint", "return_type": "godot_vector3", "arguments": [ - ["const godot_rect3 *", "p_self"], + ["const godot_aabb *", "p_self"], ["const godot_int", "p_idx"] ] }, { - "name": "godot_rect3_operator_equal", + "name": "godot_aabb_operator_equal", "return_type": "godot_bool", "arguments": [ - ["const godot_rect3 *", "p_self"], - ["const godot_rect3 *", "p_b"] + ["const godot_aabb *", "p_self"], + ["const godot_aabb *", "p_b"] ] }, { @@ -3632,19 +3652,19 @@ ] }, { - "name": "godot_transform_xform_rect3", - "return_type": "godot_rect3", + "name": "godot_transform_xform_aabb", + "return_type": "godot_aabb", "arguments": [ ["const godot_transform *", "p_self"], - ["const godot_rect3 *", "p_v"] + ["const godot_aabb *", "p_v"] ] }, { - "name": "godot_transform_xform_inv_rect3", - "return_type": "godot_rect3", + "name": "godot_transform_xform_inv_aabb", + "return_type": "godot_aabb", "arguments": [ ["const godot_transform *", "p_self"], - ["const godot_rect3 *", "p_v"] + ["const godot_aabb *", "p_v"] ] }, { @@ -3930,11 +3950,11 @@ ] }, { - "name": "godot_variant_new_rect3", + "name": "godot_variant_new_aabb", "return_type": "void", "arguments": [ ["godot_variant *", "r_dest"], - ["const godot_rect3 *", "p_rect3"] + ["const godot_aabb *", "p_aabb"] ] }, { @@ -4135,8 +4155,8 @@ ] }, { - "name": "godot_variant_as_rect3", - "return_type": "godot_rect3", + "name": "godot_variant_as_aabb", + "return_type": "godot_aabb", "arguments": [ ["const godot_variant *", "p_self"] ] @@ -4362,13 +4382,6 @@ ] }, { - "name": "godot_string_c_str", - "return_type": "const char *", - "arguments": [ - ["const godot_string *", "p_self"] - ] - }, - { "name": "godot_string_unicode_str", "return_type": "const wchar_t *", "arguments": [ @@ -5556,6 +5569,14 @@ ] }, { + "name": "godot_register_native_call_type", + "return_type": "void", + "arguments": [ + ["const char *", "call_type"], + ["native_call_cb", "p_callback"] + ] + }, + { "name": "godot_alloc", "return_type": "void *", "arguments": [ diff --git a/modules/gdnative/include/gdnative/aabb.h b/modules/gdnative/include/gdnative/aabb.h new file mode 100644 index 0000000000..34339fa242 --- /dev/null +++ b/modules/gdnative/include/gdnative/aabb.h @@ -0,0 +1,117 @@ +/*************************************************************************/ +/* aabb.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ +#ifndef GODOT_AABB_H +#define GODOT_AABB_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +#define GODOT_AABB_SIZE 24 + +#ifndef GODOT_CORE_API_GODOT_AABB_TYPE_DEFINED +#define GODOT_CORE_API_GODOT_AABB_TYPE_DEFINED +typedef struct { + uint8_t _dont_touch_that[GODOT_AABB_SIZE]; +} godot_aabb; +#endif + +// reduce extern "C" nesting for VS2013 +#ifdef __cplusplus +} +#endif + +#include <gdnative/gdnative.h> +#include <gdnative/plane.h> +#include <gdnative/vector3.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void GDAPI godot_aabb_new(godot_aabb *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size); + +godot_vector3 GDAPI godot_aabb_get_position(const godot_aabb *p_self); +void GDAPI godot_aabb_set_position(const godot_aabb *p_self, const godot_vector3 *p_v); + +godot_vector3 GDAPI godot_aabb_get_size(const godot_aabb *p_self); +void GDAPI godot_aabb_set_size(const godot_aabb *p_self, const godot_vector3 *p_v); + +godot_string GDAPI godot_aabb_as_string(const godot_aabb *p_self); + +godot_real GDAPI godot_aabb_get_area(const godot_aabb *p_self); + +godot_bool GDAPI godot_aabb_has_no_area(const godot_aabb *p_self); + +godot_bool GDAPI godot_aabb_has_no_surface(const godot_aabb *p_self); + +godot_bool GDAPI godot_aabb_intersects(const godot_aabb *p_self, const godot_aabb *p_with); + +godot_bool GDAPI godot_aabb_encloses(const godot_aabb *p_self, const godot_aabb *p_with); + +godot_aabb GDAPI godot_aabb_merge(const godot_aabb *p_self, const godot_aabb *p_with); + +godot_aabb GDAPI godot_aabb_intersection(const godot_aabb *p_self, const godot_aabb *p_with); + +godot_bool GDAPI godot_aabb_intersects_plane(const godot_aabb *p_self, const godot_plane *p_plane); + +godot_bool GDAPI godot_aabb_intersects_segment(const godot_aabb *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to); + +godot_bool GDAPI godot_aabb_has_point(const godot_aabb *p_self, const godot_vector3 *p_point); + +godot_vector3 GDAPI godot_aabb_get_support(const godot_aabb *p_self, const godot_vector3 *p_dir); + +godot_vector3 GDAPI godot_aabb_get_longest_axis(const godot_aabb *p_self); + +godot_int GDAPI godot_aabb_get_longest_axis_index(const godot_aabb *p_self); + +godot_real GDAPI godot_aabb_get_longest_axis_size(const godot_aabb *p_self); + +godot_vector3 GDAPI godot_aabb_get_shortest_axis(const godot_aabb *p_self); + +godot_int GDAPI godot_aabb_get_shortest_axis_index(const godot_aabb *p_self); + +godot_real GDAPI godot_aabb_get_shortest_axis_size(const godot_aabb *p_self); + +godot_aabb GDAPI godot_aabb_expand(const godot_aabb *p_self, const godot_vector3 *p_to_point); + +godot_aabb GDAPI godot_aabb_grow(const godot_aabb *p_self, const godot_real p_by); + +godot_vector3 GDAPI godot_aabb_get_endpoint(const godot_aabb *p_self, const godot_int p_idx); + +godot_bool GDAPI godot_aabb_operator_equal(const godot_aabb *p_self, const godot_aabb *p_b); + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_AABB_H diff --git a/modules/gdnative/include/gdnative/array.h b/modules/gdnative/include/gdnative/array.h index 01ae61e280..484ffd10ba 100644 --- a/modules/gdnative/include/gdnative/array.h +++ b/modules/gdnative/include/gdnative/array.h @@ -124,6 +124,10 @@ void GDAPI godot_array_sort(godot_array *p_self); void GDAPI godot_array_sort_custom(godot_array *p_self, godot_object *p_obj, const godot_string *p_func); +godot_int GDAPI godot_array_bsearch(godot_array *p_self, const godot_variant *p_value, const godot_bool p_before); + +godot_int GDAPI godot_array_bsearch_custom(godot_array *p_self, const godot_variant *p_value, godot_object *p_obj, const godot_string *p_func, const godot_bool p_before); + void GDAPI godot_array_destroy(godot_array *p_self); #ifdef __cplusplus diff --git a/modules/gdnative/include/gdnative/gdnative.h b/modules/gdnative/include/gdnative/gdnative.h index a479eced16..6e69d43469 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/modules/gdnative/include/gdnative/gdnative.h @@ -53,7 +53,7 @@ extern "C" { // This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!! #ifdef _WIN32 -#define GDN_EXPORT +#define GDN_EXPORT __declspec(dllexport) #else #define GDN_EXPORT #endif @@ -169,9 +169,9 @@ typedef void godot_object; #include <gdnative/quat.h> -/////// Rect3 +/////// AABB -#include <gdnative/rect3.h> +#include <gdnative/aabb.h> /////// Basis @@ -229,13 +229,28 @@ void GDAPI godot_method_bind_ptrcall(godot_method_bind *p_method_bind, godot_obj godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, godot_object *p_instance, const godot_variant **p_args, const int p_arg_count, godot_variant_call_error *p_call_error); ////// Script API -struct godot_gdnative_api_struct; // Forward declaration +typedef struct godot_gdnative_api_version { + unsigned int major; + unsigned int minor; +} godot_gdnative_api_version; + +typedef struct godot_gdnative_api_struct godot_gdnative_api_struct; + +struct godot_gdnative_api_struct { + unsigned int type; + godot_gdnative_api_version version; + const godot_gdnative_api_struct *next; +}; + +#define GDNATIVE_VERSION_COMPATIBLE(want, have) (want.major == have.major && want.minor <= have.minor) typedef struct { godot_bool in_editor; uint64_t core_api_hash; uint64_t editor_api_hash; uint64_t no_api_hash; + void (*report_version_mismatch)(const godot_object *p_library, const char *p_what, godot_gdnative_api_version p_want, godot_gdnative_api_version p_have); + void (*report_loading_error)(const godot_object *p_library, const char *p_what); godot_object *gd_native_library; // pointer to GDNativeLibrary that is being initialized const struct godot_gdnative_core_api_struct *api_struct; const godot_string *active_library_path; @@ -259,6 +274,9 @@ typedef godot_variant (*godot_gdnative_procedure_fn)(godot_array *); ////// System Functions +typedef godot_variant (*native_call_cb)(void *, godot_array *); +void GDAPI godot_register_native_call_type(const char *p_call_type, native_call_cb p_callback); + //using these will help Godot track how much memory is in use in debug mode void GDAPI *godot_alloc(int p_bytes); void GDAPI *godot_realloc(void *p_ptr, int p_bytes); diff --git a/modules/gdnative/include/gdnative/node_path.h b/modules/gdnative/include/gdnative/node_path.h index 42446175d8..b5a59fd325 100644 --- a/modules/gdnative/include/gdnative/node_path.h +++ b/modules/gdnative/include/gdnative/node_path.h @@ -73,7 +73,7 @@ godot_int GDAPI godot_node_path_get_subname_count(const godot_node_path *p_self) godot_string GDAPI godot_node_path_get_subname(const godot_node_path *p_self, const godot_int p_idx); -godot_string GDAPI godot_node_path_get_property(const godot_node_path *p_self); +godot_string GDAPI godot_node_path_get_concatenated_subnames(const godot_node_path *p_self); godot_bool GDAPI godot_node_path_is_empty(const godot_node_path *p_self); diff --git a/modules/gdnative/include/gdnative/rect3.h b/modules/gdnative/include/gdnative/rect3.h deleted file mode 100644 index f603a9268a..0000000000 --- a/modules/gdnative/include/gdnative/rect3.h +++ /dev/null @@ -1,117 +0,0 @@ -/*************************************************************************/ -/* rect3.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ -#ifndef GODOT_RECT3_H -#define GODOT_RECT3_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <stdint.h> - -#define GODOT_RECT3_SIZE 24 - -#ifndef GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED -#define GODOT_CORE_API_GODOT_RECT3_TYPE_DEFINED -typedef struct { - uint8_t _dont_touch_that[GODOT_RECT3_SIZE]; -} godot_rect3; -#endif - -// reduce extern "C" nesting for VS2013 -#ifdef __cplusplus -} -#endif - -#include <gdnative/gdnative.h> -#include <gdnative/plane.h> -#include <gdnative/vector3.h> - -#ifdef __cplusplus -extern "C" { -#endif - -void GDAPI godot_rect3_new(godot_rect3 *r_dest, const godot_vector3 *p_pos, const godot_vector3 *p_size); - -godot_vector3 GDAPI godot_rect3_get_position(const godot_rect3 *p_self); -void GDAPI godot_rect3_set_position(const godot_rect3 *p_self, const godot_vector3 *p_v); - -godot_vector3 GDAPI godot_rect3_get_size(const godot_rect3 *p_self); -void GDAPI godot_rect3_set_size(const godot_rect3 *p_self, const godot_vector3 *p_v); - -godot_string GDAPI godot_rect3_as_string(const godot_rect3 *p_self); - -godot_real GDAPI godot_rect3_get_area(const godot_rect3 *p_self); - -godot_bool GDAPI godot_rect3_has_no_area(const godot_rect3 *p_self); - -godot_bool GDAPI godot_rect3_has_no_surface(const godot_rect3 *p_self); - -godot_bool GDAPI godot_rect3_intersects(const godot_rect3 *p_self, const godot_rect3 *p_with); - -godot_bool GDAPI godot_rect3_encloses(const godot_rect3 *p_self, const godot_rect3 *p_with); - -godot_rect3 GDAPI godot_rect3_merge(const godot_rect3 *p_self, const godot_rect3 *p_with); - -godot_rect3 GDAPI godot_rect3_intersection(const godot_rect3 *p_self, const godot_rect3 *p_with); - -godot_bool GDAPI godot_rect3_intersects_plane(const godot_rect3 *p_self, const godot_plane *p_plane); - -godot_bool GDAPI godot_rect3_intersects_segment(const godot_rect3 *p_self, const godot_vector3 *p_from, const godot_vector3 *p_to); - -godot_bool GDAPI godot_rect3_has_point(const godot_rect3 *p_self, const godot_vector3 *p_point); - -godot_vector3 GDAPI godot_rect3_get_support(const godot_rect3 *p_self, const godot_vector3 *p_dir); - -godot_vector3 GDAPI godot_rect3_get_longest_axis(const godot_rect3 *p_self); - -godot_int GDAPI godot_rect3_get_longest_axis_index(const godot_rect3 *p_self); - -godot_real GDAPI godot_rect3_get_longest_axis_size(const godot_rect3 *p_self); - -godot_vector3 GDAPI godot_rect3_get_shortest_axis(const godot_rect3 *p_self); - -godot_int GDAPI godot_rect3_get_shortest_axis_index(const godot_rect3 *p_self); - -godot_real GDAPI godot_rect3_get_shortest_axis_size(const godot_rect3 *p_self); - -godot_rect3 GDAPI godot_rect3_expand(const godot_rect3 *p_self, const godot_vector3 *p_to_point); - -godot_rect3 GDAPI godot_rect3_grow(const godot_rect3 *p_self, const godot_real p_by); - -godot_vector3 GDAPI godot_rect3_get_endpoint(const godot_rect3 *p_self, const godot_int p_idx); - -godot_bool GDAPI godot_rect3_operator_equal(const godot_rect3 *p_self, const godot_rect3 *p_b); - -#ifdef __cplusplus -} -#endif - -#endif // GODOT_RECT3_H diff --git a/modules/gdnative/include/gdnative/string.h b/modules/gdnative/include/gdnative/string.h index 29510313c9..10358ceade 100644 --- a/modules/gdnative/include/gdnative/string.h +++ b/modules/gdnative/include/gdnative/string.h @@ -51,6 +51,7 @@ typedef struct { } #endif +#include <gdnative/array.h> #include <gdnative/gdnative.h> #include <gdnative/variant.h> @@ -67,7 +68,6 @@ void GDAPI godot_string_get_data(const godot_string *p_self, char *p_dest, int * wchar_t GDAPI *godot_string_operator_index(godot_string *p_self, const godot_int p_idx); wchar_t GDAPI godot_string_operator_index_const(const godot_string *p_self, const godot_int p_idx); -const char GDAPI *godot_string_c_str(const godot_string *p_self); const wchar_t GDAPI *godot_string_unicode_str(const godot_string *p_self); godot_bool GDAPI godot_string_operator_equal(const godot_string *p_self, const godot_string *p_b); diff --git a/modules/gdnative/include/gdnative/transform.h b/modules/gdnative/include/gdnative/transform.h index 8f50b01fb5..3b5c189bdf 100644 --- a/modules/gdnative/include/gdnative/transform.h +++ b/modules/gdnative/include/gdnative/transform.h @@ -98,9 +98,9 @@ godot_vector3 GDAPI godot_transform_xform_vector3(const godot_transform *p_self, godot_vector3 GDAPI godot_transform_xform_inv_vector3(const godot_transform *p_self, const godot_vector3 *p_v); -godot_rect3 GDAPI godot_transform_xform_rect3(const godot_transform *p_self, const godot_rect3 *p_v); +godot_aabb GDAPI godot_transform_xform_aabb(const godot_transform *p_self, const godot_aabb *p_v); -godot_rect3 GDAPI godot_transform_xform_inv_rect3(const godot_transform *p_self, const godot_rect3 *p_v); +godot_aabb GDAPI godot_transform_xform_inv_aabb(const godot_transform *p_self, const godot_aabb *p_v); #ifdef __cplusplus } diff --git a/modules/gdnative/include/gdnative/variant.h b/modules/gdnative/include/gdnative/variant.h index 3d744ef1f2..06cafcfa63 100644 --- a/modules/gdnative/include/gdnative/variant.h +++ b/modules/gdnative/include/gdnative/variant.h @@ -62,7 +62,7 @@ typedef enum godot_variant_type { GODOT_VARIANT_TYPE_TRANSFORM2D, GODOT_VARIANT_TYPE_PLANE, GODOT_VARIANT_TYPE_QUAT, // 10 - GODOT_VARIANT_TYPE_RECT3, + GODOT_VARIANT_TYPE_AABB, GODOT_VARIANT_TYPE_BASIS, GODOT_VARIANT_TYPE_TRANSFORM, @@ -104,6 +104,7 @@ typedef struct godot_variant_call_error { } #endif +#include <gdnative/aabb.h> #include <gdnative/array.h> #include <gdnative/basis.h> #include <gdnative/color.h> @@ -113,7 +114,6 @@ typedef struct godot_variant_call_error { #include <gdnative/pool_arrays.h> #include <gdnative/quat.h> #include <gdnative/rect2.h> -#include <gdnative/rect3.h> #include <gdnative/rid.h> #include <gdnative/string.h> #include <gdnative/transform.h> @@ -145,7 +145,7 @@ void GDAPI godot_variant_new_vector3(godot_variant *r_dest, const godot_vector3 void GDAPI godot_variant_new_transform2d(godot_variant *r_dest, const godot_transform2d *p_t2d); void GDAPI godot_variant_new_plane(godot_variant *r_dest, const godot_plane *p_plane); void GDAPI godot_variant_new_quat(godot_variant *r_dest, const godot_quat *p_quat); -void GDAPI godot_variant_new_rect3(godot_variant *r_dest, const godot_rect3 *p_rect3); +void GDAPI godot_variant_new_aabb(godot_variant *r_dest, const godot_aabb *p_aabb); void GDAPI godot_variant_new_basis(godot_variant *r_dest, const godot_basis *p_basis); void GDAPI godot_variant_new_transform(godot_variant *r_dest, const godot_transform *p_trans); void GDAPI godot_variant_new_color(godot_variant *r_dest, const godot_color *p_color); @@ -173,7 +173,7 @@ godot_vector3 GDAPI godot_variant_as_vector3(const godot_variant *p_self); godot_transform2d GDAPI godot_variant_as_transform2d(const godot_variant *p_self); godot_plane GDAPI godot_variant_as_plane(const godot_variant *p_self); godot_quat GDAPI godot_variant_as_quat(const godot_variant *p_self); -godot_rect3 GDAPI godot_variant_as_rect3(const godot_variant *p_self); +godot_aabb GDAPI godot_variant_as_aabb(const godot_variant *p_self); godot_basis GDAPI godot_variant_as_basis(const godot_variant *p_self); godot_transform GDAPI godot_variant_as_transform(const godot_variant *p_self); godot_color GDAPI godot_variant_as_color(const godot_variant *p_self); diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 29b0a6719c..34099bf528 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -123,6 +123,11 @@ protected: virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features); }; +struct LibrarySymbol { + char *name; + bool is_required; +}; + void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) { if (p_type != "GDNativeLibrary") { return; @@ -136,7 +141,6 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty Ref<ConfigFile> config = lib->get_config_file(); - String entry_lib_path; { List<String> entry_keys; @@ -161,14 +165,12 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty continue; } - entry_lib_path = config->get_value("entry", key); - break; + String entry_lib_path = config->get_value("entry", key); + add_shared_object(entry_lib_path, tags); } } - Vector<String> dependency_paths; { - List<String> dependency_keys; config->get_section_keys("dependencies", &dependency_keys); @@ -191,47 +193,54 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty continue; } - dependency_paths = config->get_value("dependencies", key); - break; + Vector<String> dependency_paths = config->get_value("dependencies", key); + for (int i = 0; i < dependency_paths.size(); i++) { + add_shared_object(dependency_paths[i], tags); + } } } - bool is_statically_linked = false; - { - - List<String> static_linking_keys; - config->get_section_keys("static_linking", &static_linking_keys); - - for (List<String>::Element *E = static_linking_keys.front(); E; E = E->next()) { - String key = E->get(); - - Vector<String> tags = key.split("."); - - bool skip = false; - - for (int i = 0; i < tags.size(); i++) { - bool has_feature = p_features.has(tags[i]); - - if (!has_feature) { - skip = true; - break; + if (p_features.has("iOS")) { + // Register symbols in the "fake" dynamic lookup table, because dlsym does not work well on iOS. + LibrarySymbol expected_symbols[] = { + { "gdnative_init", true }, + { "gdnative_terminate", false }, + { "nativescript_init", false }, + { "nativescript_frame", false }, + { "nativescript_thread_enter", false }, + { "nativescript_thread_exit", false }, + { "gdnative_singleton", false } + }; + String declare_pattern = "extern \"C\" void $name(void)$weak;\n"; + String additional_code = "extern void register_dynamic_symbol(char *name, void *address);\n" + "extern void add_ios_init_callback(void (*cb)());\n"; + String linker_flags = ""; + for (int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) { + String full_name = lib->get_symbol_prefix() + expected_symbols[i].name; + String code = declare_pattern.replace("$name", full_name); + code = code.replace("$weak", expected_symbols[i].is_required ? "" : " __attribute__((weak))"); + additional_code += code; + + if (!expected_symbols[i].is_required) { + if (linker_flags.length() > 0) { + linker_flags += " "; } + linker_flags += "-Wl,-U,_" + full_name; } - - if (skip) { - continue; - } - - is_statically_linked = config->get_value("static_linking", key); - break; } - } - if (!is_statically_linked) - add_shared_object(entry_lib_path); + additional_code += String("void $prefixinit() {\n").replace("$prefix", lib->get_symbol_prefix()); + String register_pattern = " if (&$name) register_dynamic_symbol((char *)\"$name\", (void *)$name);\n"; + for (int i = 0; i < sizeof(expected_symbols) / sizeof(expected_symbols[0]); ++i) { + String full_name = lib->get_symbol_prefix() + expected_symbols[i].name; + additional_code += register_pattern.replace("$name", full_name); + } + additional_code += "}\n"; + additional_code += String("struct $prefixstruct {$prefixstruct() {add_ios_init_callback($prefixinit);}};\n").replace("$prefix", lib->get_symbol_prefix()); + additional_code += String("$prefixstruct $prefixstruct_instance;\n").replace("$prefix", lib->get_symbol_prefix()); - for (int i = 0; i < dependency_paths.size(); i++) { - add_shared_object(dependency_paths[i]); + add_ios_cpp_code(additional_code); + add_ios_linker_flags(linker_flags); } } @@ -271,9 +280,7 @@ void register_gdnative_types() { #ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { - EditorNode::add_init_callback(editor_init_callback); - } + EditorNode::add_init_callback(editor_init_callback); #endif ClassDB::register_class<GDNativeLibrary>(); @@ -371,7 +378,7 @@ void unregister_gdnative_types() { print_line(String("poolarray:\t") + itos(sizeof(PoolByteArray))); print_line(String("quat:\t") + itos(sizeof(Quat))); print_line(String("rect2:\t") + itos(sizeof(Rect2))); - print_line(String("rect3:\t") + itos(sizeof(Rect3))); + print_line(String("aabb:\t") + itos(sizeof(AABB))); print_line(String("rid:\t") + itos(sizeof(RID))); print_line(String("string:\t") + itos(sizeof(String))); print_line(String("transform:\t") + itos(sizeof(Transform))); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 55ea8a5f24..41a810ff00 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -100,7 +100,7 @@ GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argco #endif instance->owner->set_script_instance(instance); -/* STEP 2, INITIALIZE AND CONSRTUCT */ + /* STEP 2, INITIALIZE AND CONSRTUCT */ #ifndef NO_THREADS GDScriptLanguage::singleton->lock->lock(); @@ -615,6 +615,23 @@ ScriptLanguage *GDScript::get_language() const { return GDScriptLanguage::get_singleton(); } +void GDScript::get_constants(Map<StringName, Variant> *p_constants) { + + if (p_constants) { + for (Map<StringName, Variant>::Element *E = constants.front(); E; E = E->next()) { + (*p_constants)[E->key()] = E->value(); + } + } +} + +void GDScript::get_members(Set<StringName> *p_members) { + if (p_members) { + for (Set<StringName>::Element *E = members.front(); E; E = E->next()) { + p_members->insert(E->get()); + } + } +} + Variant GDScript::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { GDScript *top = this; diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 3f6f431938..6e5d59ad0e 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -198,6 +198,9 @@ public: return -1; } + virtual void get_constants(Map<StringName, Variant> *p_constants); + virtual void get_members(Set<StringName> *p_members); + GDScript(); ~GDScript(); }; @@ -219,7 +222,7 @@ class GDScriptInstance : public ScriptInstance { void _ml_call_reversed(GDScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount); public: - _FORCE_INLINE_ Object *get_owner() { return owner; } + virtual Object *get_owner() { return owner; } virtual bool set(const StringName &p_name, const Variant &p_value); virtual bool get(const StringName &p_name, Variant &r_ret) const; @@ -407,7 +410,8 @@ public: virtual String debug_get_stack_level_source(int p_level) const; virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); - virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); + virtual ScriptInstance *debug_get_stack_level_instance(int p_level); + virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1); virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1); virtual void reload_all_scripts(); diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 3121a61436..4cd6472b7f 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1686,21 +1686,44 @@ Error GDScriptCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, cons base_class = p->subclasses[base]; break; } + + if (p->constants.has(base)) { + + base_class = p->constants[base]; + if (base_class.is_null()) { + _set_error("Constant is not a class: " + base, p_class); + return ERR_SCRIPT_FAILED; + } + break; + } + p = p->_owner; } if (base_class.is_valid()) { + String ident = base; + for (int i = 1; i < p_class->extends_class.size(); i++) { String subclass = p_class->extends_class[i]; + ident += ("." + subclass); + if (base_class->subclasses.has(subclass)) { base_class = base_class->subclasses[subclass]; + } else if (base_class->constants.has(subclass)) { + + Ref<GDScript> new_base_class = base_class->constants[subclass]; + if (new_base_class.is_null()) { + _set_error("Constant is not a class: " + ident, p_class); + return ERR_SCRIPT_FAILED; + } + base_class = new_base_class; } else { - _set_error("Could not find subclass: " + subclass, p_class); + _set_error("Could not find subclass: " + ident, p_class); return ERR_FILE_NOT_FOUND; } } diff --git a/modules/gdscript/gdscript_editor.cpp b/modules/gdscript/gdscript_editor.cpp index a74b8a8483..5a76acea6e 100644 --- a/modules/gdscript/gdscript_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -33,7 +33,7 @@ #include "gdscript_compiler.h" #include "global_constants.h" #include "os/file_access.h" -#include "project_settings.h" +#include "core/engine.h" #ifdef TOOLS_ENABLED #include "editor/editor_file_system.h" @@ -280,10 +280,62 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> * p_values->push_back(instance->debug_get_member_by_index(E->get().index)); } } -void GDScriptLanguage::debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { - //no globals are really reachable in gdscript +ScriptInstance *GDScriptLanguage::debug_get_stack_level_instance(int p_level) { + + ERR_FAIL_COND_V(_debug_parse_err_line >= 0, NULL); + ERR_FAIL_INDEX_V(p_level, _debug_call_stack_pos, NULL); + + int l = _debug_call_stack_pos - p_level - 1; + ScriptInstance *instance = _call_stack[l].instance; + + return instance; } + +void GDScriptLanguage::debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) { + + const Map<StringName, int> &name_idx = GDScriptLanguage::get_singleton()->get_global_map(); + const Variant *globals = GDScriptLanguage::get_singleton()->get_global_array(); + + List<Pair<String, Variant> > cinfo; + get_public_constants(&cinfo); + + for (const Map<StringName, int>::Element *E = name_idx.front(); E; E = E->next()) { + + if (ClassDB::class_exists(E->key()) || Engine::get_singleton()->has_singleton(E->key())) + continue; + + bool is_script_constant = false; + for (List<Pair<String, Variant> >::Element *CE = cinfo.front(); CE; CE = CE->next()) { + if (CE->get().first == E->key()) { + is_script_constant = true; + break; + } + } + if (is_script_constant) + continue; + + const Variant &var = globals[E->value()]; + if (Object *obj = var) { + if (Object::cast_to<GDScriptNativeClass>(obj)) + continue; + } + + bool skip = false; + for (int i = 0; i < GlobalConstants::get_global_constant_count(); i++) { + if (E->key() == GlobalConstants::get_global_constant_name(i)) { + skip = true; + break; + } + } + if (skip) + continue; + + p_globals->push_back(E->key()); + p_values->push_back(var); + } +} + String GDScriptLanguage::debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { if (_debug_parse_err_line >= 0) @@ -1743,7 +1795,7 @@ static void _find_type_arguments(GDScriptCompletionContext &context, const GDScr } } else { -//regular method + //regular method #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) if (p_argidx < m->get_argument_count()) { diff --git a/modules/gdscript/gdscript_functions.cpp b/modules/gdscript/gdscript_functions.cpp index 467dbf3e56..ca0a9582a7 100644 --- a/modules/gdscript/gdscript_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -84,6 +84,8 @@ const char *GDScriptFunctions::get_func_name(Function p_func) { "rad2deg", "linear2db", "db2linear", + "polar2cartesian", + "cartesian2polar", "wrapi", "wrapf", "max", @@ -408,6 +410,22 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ VALIDATE_ARG_NUM(0); r_ret = Math::db2linear((double)*p_args[0]); } break; + case MATH_POLAR2CARTESIAN: { + VALIDATE_ARG_COUNT(2); + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double r = *p_args[0]; + double th = *p_args[1]; + r_ret = Vector2(r * Math::cos(th), r * Math::sin(th)); + } break; + case MATH_CARTESIAN2POLAR: { + VALIDATE_ARG_COUNT(2); + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double x = *p_args[0]; + double y = *p_args[1]; + r_ret = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x)); + } break; case MATH_WRAP: { VALIDATE_ARG_COUNT(3); r_ret = Math::wrapi((int64_t)*p_args[0], (int64_t)*p_args[1], (int64_t)*p_args[2]); @@ -642,7 +660,7 @@ void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_ } //str+="\n"; - OS::get_singleton()->printerr("%s\n", str.utf8().get_data()); + print_error(str); r_ret = Variant(); } break; @@ -1296,6 +1314,8 @@ bool GDScriptFunctions::is_deterministic(Function p_func) { case MATH_RAD2DEG: case MATH_LINEAR2DB: case MATH_DB2LINEAR: + case MATH_POLAR2CARTESIAN: + case MATH_CARTESIAN2POLAR: case MATH_WRAP: case MATH_WRAPF: case LOGIC_MAX: @@ -1526,6 +1546,16 @@ MethodInfo GDScriptFunctions::get_info(Function p_func) { mi.return_val.type = Variant::REAL; return mi; } break; + case MATH_POLAR2CARTESIAN: { + MethodInfo mi("polar2cartesian", PropertyInfo(Variant::REAL, "r"), PropertyInfo(Variant::REAL, "th")); + mi.return_val.type = Variant::VECTOR2; + return mi; + } break; + case MATH_CARTESIAN2POLAR: { + MethodInfo mi("cartesian2polar", PropertyInfo(Variant::REAL, "x"), PropertyInfo(Variant::REAL, "y")); + mi.return_val.type = Variant::VECTOR2; + return mi; + } break; case MATH_WRAP: { MethodInfo mi("wrapi", PropertyInfo(Variant::INT, "value"), PropertyInfo(Variant::INT, "min"), PropertyInfo(Variant::INT, "max")); mi.return_val.type = Variant::INT; diff --git a/modules/gdscript/gdscript_functions.h b/modules/gdscript/gdscript_functions.h index ecbede83a8..d1c5815cec 100644 --- a/modules/gdscript/gdscript_functions.h +++ b/modules/gdscript/gdscript_functions.h @@ -75,6 +75,8 @@ public: MATH_RAD2DEG, MATH_LINEAR2DB, MATH_DB2LINEAR, + MATH_POLAR2CARTESIAN, + MATH_CARTESIAN2POLAR, MATH_WRAP, MATH_WRAPF, LOGIC_MAX, diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 29b9865b1d..bee9ef1998 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -2971,18 +2971,37 @@ void GDScriptParser::_parse_extends(ClassNode *p_class) { } while (true) { - if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER) { - _set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class)."); - return; - } + switch (tokenizer->get_token()) { + + case GDScriptTokenizer::TK_IDENTIFIER: { + + StringName identifier = tokenizer->get_token_identifier(); + p_class->extends_class.push_back(identifier); + } + break; - StringName identifier = tokenizer->get_token_identifier(); - p_class->extends_class.push_back(identifier); + case GDScriptTokenizer::TK_PERIOD: + break; + + default: { + + _set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class)."); + return; + } + } tokenizer->advance(1); - if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD) - return; + + switch (tokenizer->get_token()) { + + case GDScriptTokenizer::TK_IDENTIFIER: + case GDScriptTokenizer::TK_PERIOD: + continue; + + default: + return; + } } } @@ -3758,22 +3777,82 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { current_export.hint = PROPERTY_HINT_NONE; } - } else if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER) { + } else { - String identifier = tokenizer->get_token_identifier(); - if (!ClassDB::is_parent_class(identifier, "Resource")) { + parenthesis++; + Node *subexpr = _parse_and_reduce_expression(p_class, true, true); + if (!subexpr) { + if (_recover_from_completion()) { + break; + } + return; + } + parenthesis--; + if (subexpr->type != Node::TYPE_CONSTANT) { current_export = PropertyInfo(); - _set_error("Export hint not a type or resource."); + _set_error("Expected a constant expression."); } - current_export.type = Variant::OBJECT; - current_export.hint = PROPERTY_HINT_RESOURCE_TYPE; - current_export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; + Variant constant = static_cast<ConstantNode *>(subexpr)->value; - current_export.hint_string = identifier; + if (constant.get_type() == Variant::OBJECT) { + GDScriptNativeClass *native_class = Object::cast_to<GDScriptNativeClass>(constant); - tokenizer->advance(); + if (native_class && ClassDB::is_parent_class(native_class->get_name(), "Resource")) { + current_export.type = Variant::OBJECT; + current_export.hint = PROPERTY_HINT_RESOURCE_TYPE; + current_export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; + + current_export.hint_string = native_class->get_name(); + + } else { + current_export = PropertyInfo(); + _set_error("Export hint not a resource type."); + } + } else if (constant.get_type() == Variant::DICTIONARY) { + // Enumeration + bool is_flags = false; + + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { + tokenizer->advance(); + + if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FLAGS") { + is_flags = true; + tokenizer->advance(); + } else { + current_export = PropertyInfo(); + _set_error("Expected 'FLAGS' after comma."); + } + } + + current_export.type = Variant::INT; + current_export.hint = is_flags ? PROPERTY_HINT_FLAGS : PROPERTY_HINT_ENUM; + Dictionary enum_values = constant; + + List<Variant> keys; + enum_values.get_key_list(&keys); + + 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) + current_export.hint_string += ","; + else + first = false; + + current_export.hint_string += E->get().operator String().camelcase_to_underscore(true).capitalize().xml_escape(); + if (!is_flags) { + current_export.hint_string += ":"; + current_export.hint_string += enum_values[E->get()].operator String().xml_escape(); + } + } + } + } else { + current_export = PropertyInfo(); + _set_error("Expected type for export."); + return; + } } if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { diff --git a/modules/gdscript/gdscript_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 174bb02967..e3a0af8ee6 100644 --- a/modules/gdscript/gdscript_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -148,7 +148,7 @@ static const _bit _type_list[] = { { Variant::RECT2, "Rect2" }, { Variant::TRANSFORM2D, "Transform2D" }, { Variant::VECTOR3, "Vector3" }, - { Variant::RECT3, "Rect3" }, + { Variant::AABB, "AABB" }, { Variant::PLANE, "Plane" }, { Variant::QUAT, "Quat" }, { Variant::BASIS, "Basis" }, @@ -253,9 +253,9 @@ bool GDScriptTokenizer::is_token_literal(int p_offset, bool variable_safe) const case TK_BUILT_IN_FUNC: case TK_OP_IN: - //case TK_OP_NOT: - //case TK_OP_OR: - //case TK_OP_AND: + //case TK_OP_NOT: + //case TK_OP_OR: + //case TK_OP_AND: case TK_PR_CLASS: case TK_PR_CONST: @@ -1125,7 +1125,7 @@ void GDScriptTokenizerText::advance(int p_amount) { _advance(); } -////////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////////// #define BYTECODE_VERSION 12 diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index bceb2b7db7..3a5d0fd3fc 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -623,6 +623,16 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu return do_input_action(p_camera, mm->get_position(), false); } + Ref<InputEventPanGesture> pan_gesture = p_event; + if (pan_gesture.is_valid()) { + + if (pan_gesture->get_command() || pan_gesture->get_shift()) { + const real_t delta = pan_gesture->get_delta().y; + floor->set_value(floor->get_value() + SGN(delta)); + return true; + } + } + return false; } @@ -1137,7 +1147,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { for (int i = 0; i < 12; i++) { - Rect3 base(Vector3(0, 0, 0), Vector3(1, 1, 1)); + AABB base(Vector3(0, 0, 0), Vector3(1, 1, 1)); Vector3 a, b; base.get_edge(i, a, b); lines.push_back(a); diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 161e130a07..dfa5e720ae 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -346,7 +346,7 @@ static String variant_type_to_managed_name(const String &p_var_type_name) { Variant::TRANSFORM2D, Variant::PLANE, Variant::QUAT, - Variant::RECT3, + Variant::AABB, Variant::BASIS, Variant::TRANSFORM, Variant::COLOR, diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index a293cc2c50..59a2b73dbc 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -1721,7 +1721,7 @@ void BindingsGenerator::_default_argument_from_variant(const Variant &p_val, Arg r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; break; case Variant::PLANE: - case Variant::RECT3: + case Variant::AABB: case Variant::COLOR: r_iarg.default_argument = "new Color(1, 1, 1, 1)"; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_VAL; @@ -1793,7 +1793,7 @@ void BindingsGenerator::_populate_builtin_type_interfaces() { INSERT_STRUCT_TYPE(Basis, "real_t*") INSERT_STRUCT_TYPE(Quat, "real_t*") INSERT_STRUCT_TYPE(Transform, "real_t*") - INSERT_STRUCT_TYPE(Rect3, "real_t*") + INSERT_STRUCT_TYPE(AABB, "real_t*") INSERT_STRUCT_TYPE(Color, "real_t*") INSERT_STRUCT_TYPE(Plane, "real_t*") diff --git a/modules/mono/glue/cs_files/Rect3.cs b/modules/mono/glue/cs_files/AABB.cs index 617d33e7fd..e6e12f7ba3 100644 --- a/modules/mono/glue/cs_files/Rect3.cs +++ b/modules/mono/glue/cs_files/AABB.cs @@ -1,15 +1,15 @@ using System; -// file: core/math/rect3.h +// file: core/math/aabb.h // commit: 7ad14e7a3e6f87ddc450f7e34621eb5200808451 -// file: core/math/rect3.cpp +// file: core/math/aabb.cpp // commit: bd282ff43f23fe845f29a3e25c8efc01bd65ffb0 // file: core/variant_call.cpp // commit: 5ad9be4c24e9d7dc5672fdc42cea896622fe5685 namespace Godot { - public struct Rect3 : IEquatable<Rect3> + public struct AABB : IEquatable<AABB> { private Vector3 position; private Vector3 size; @@ -38,7 +38,7 @@ namespace Godot } } - public bool encloses(Rect3 with) + public bool Encloses(AABB with) { Vector3 src_min = position; Vector3 src_max = position + size; @@ -53,7 +53,7 @@ namespace Godot (src_max.z > dst_max.z)); } - public Rect3 expand(Vector3 to_point) + public AABB Expand(Vector3 to_point) { Vector3 begin = position; Vector3 end = position + size; @@ -72,15 +72,15 @@ namespace Godot if (to_point.z > end.z) end.z = to_point.z; - return new Rect3(begin, end - begin); + return new AABB(begin, end - begin); } - public float get_area() + public float GetArea() { return size.x * size.y * size.z; } - public Vector3 get_endpoint(int idx) + public Vector3 GetEndpoint(int idx) { switch (idx) { @@ -105,7 +105,7 @@ namespace Godot } } - public Vector3 get_longest_axis() + public Vector3 GetLongestAxis() { Vector3 axis = new Vector3(1f, 0f, 0f); float max_size = size.x; @@ -125,7 +125,7 @@ namespace Godot return axis; } - public Vector3.Axis get_longest_axis_index() + public Vector3.Axis GetLongestAxisIndex() { Vector3.Axis axis = Vector3.Axis.X; float max_size = size.x; @@ -145,7 +145,7 @@ namespace Godot return axis; } - public float get_longest_axis_size() + public float GetLongestAxisSize() { float max_size = size.x; @@ -158,7 +158,7 @@ namespace Godot return max_size; } - public Vector3 get_shortest_axis() + public Vector3 GetShortestAxis() { Vector3 axis = new Vector3(1f, 0f, 0f); float max_size = size.x; @@ -178,7 +178,7 @@ namespace Godot return axis; } - public Vector3.Axis get_shortest_axis_index() + public Vector3.Axis GetShortestAxisIndex() { Vector3.Axis axis = Vector3.Axis.X; float max_size = size.x; @@ -198,7 +198,7 @@ namespace Godot return axis; } - public float get_shortest_axis_size() + public float GetShortestAxisSize() { float max_size = size.x; @@ -211,7 +211,7 @@ namespace Godot return max_size; } - public Vector3 get_support(Vector3 dir) + public Vector3 GetSupport(Vector3 dir) { Vector3 half_extents = size * 0.5f; Vector3 ofs = position + half_extents; @@ -222,9 +222,9 @@ namespace Godot (dir.z > 0f) ? -half_extents.z : half_extents.z); } - public Rect3 grow(float by) + public AABB Grow(float by) { - Rect3 res = this; + AABB res = this; res.position.x -= by; res.position.y -= by; @@ -236,17 +236,17 @@ namespace Godot return res; } - public bool has_no_area() + public bool HasNoArea() { return size.x <= 0f || size.y <= 0f || size.z <= 0f; } - public bool has_no_surface() + public bool HasNoSurface() { return size.x <= 0f && size.y <= 0f && size.z <= 0f; } - public bool has_point(Vector3 point) + public bool HasPoint(Vector3 point) { if (point.x < position.x) return false; @@ -264,7 +264,7 @@ namespace Godot return true; } - public Rect3 intersection(Rect3 with) + public AABB Intersection(AABB with) { Vector3 src_min = position; Vector3 src_max = position + size; @@ -275,7 +275,7 @@ namespace Godot if (src_min.x > dst_max.x || src_max.x < dst_min.x) { - return new Rect3(); + return new AABB(); } else { @@ -285,7 +285,7 @@ namespace Godot if (src_min.y > dst_max.y || src_max.y < dst_min.y) { - return new Rect3(); + return new AABB(); } else { @@ -295,7 +295,7 @@ namespace Godot if (src_min.z > dst_max.z || src_max.z < dst_min.z) { - return new Rect3(); + return new AABB(); } else { @@ -303,10 +303,10 @@ namespace Godot max.z = (src_max.z < dst_max.z) ? src_max.z : dst_max.z; } - return new Rect3(min, max - min); + return new AABB(min, max - min); } - public bool intersects(Rect3 with) + public bool Intersects(AABB with) { if (position.x >= (with.position.x + with.size.x)) return false; @@ -324,7 +324,7 @@ namespace Godot return true; } - public bool intersects_plane(Plane plane) + public bool IntersectsPlane(Plane plane) { Vector3[] points = { @@ -343,7 +343,7 @@ namespace Godot for (int i = 0; i < 8; i++) { - if (plane.distance_to(points[i]) > 0) + if (plane.DistanceTo(points[i]) > 0) over = true; else under = true; @@ -352,7 +352,7 @@ namespace Godot return under && over; } - public bool intersects_segment(Vector3 from, Vector3 to) + public bool IntersectsSegment(Vector3 from, Vector3 to) { float min = 0f; float max = 1f; @@ -398,7 +398,7 @@ namespace Godot return true; } - public Rect3 merge(Rect3 with) + public AABB Merge(AABB with) { Vector3 beg_1 = position; Vector3 beg_2 = with.position; @@ -417,36 +417,36 @@ namespace Godot (end_1.z > end_2.z) ? end_1.z : end_2.z ); - return new Rect3(min, max - min); + return new AABB(min, max - min); } - public Rect3(Vector3 position, Vector3 size) + public AABB(Vector3 position, Vector3 size) { this.position = position; this.size = size; } - public static bool operator ==(Rect3 left, Rect3 right) + public static bool operator ==(AABB left, AABB right) { return left.Equals(right); } - public static bool operator !=(Rect3 left, Rect3 right) + public static bool operator !=(AABB left, AABB right) { return !left.Equals(right); } public override bool Equals(object obj) { - if (obj is Rect3) + if (obj is AABB) { - return Equals((Rect3)obj); + return Equals((AABB)obj); } return false; } - public bool Equals(Rect3 other) + public bool Equals(AABB other) { return position == other.position && size == other.size; } diff --git a/modules/mono/glue/cs_files/Basis.cs b/modules/mono/glue/cs_files/Basis.cs index c50e783349..ea92b1641b 100644 --- a/modules/mono/glue/cs_files/Basis.cs +++ b/modules/mono/glue/cs_files/Basis.cs @@ -56,9 +56,9 @@ namespace Godot { return new Vector3 ( - new Vector3(this[0, 0], this[1, 0], this[2, 0]).length(), - new Vector3(this[0, 1], this[1, 1], this[2, 1]).length(), - new Vector3(this[0, 2], this[1, 2], this[2, 2]).length() + new Vector3(this[0, 0], this[1, 0], this[2, 0]).Length(), + new Vector3(this[0, 1], this[1, 1], this[2, 1]).Length(), + new Vector3(this[0, 2], this[1, 2], this[2, 2]).Length() ); } } @@ -133,7 +133,7 @@ namespace Godot } } - internal static Basis create_from_axes(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis) + internal static Basis CreateFromAxes(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis) { return new Basis ( @@ -143,21 +143,21 @@ namespace Godot ); } - public float determinant() + public float Determinant() { return this[0, 0] * (this[1, 1] * this[2, 2] - this[2, 1] * this[1, 2]) - this[1, 0] * (this[0, 1] * this[2, 2] - this[2, 1] * this[0, 2]) + this[2, 0] * (this[0, 1] * this[1, 2] - this[1, 1] * this[0, 2]); } - public Vector3 get_axis(int axis) + public Vector3 GetAxis(int axis) { return new Vector3(this[0, axis], this[1, axis], this[2, axis]); } - public Vector3 get_euler() + public Vector3 GetEuler() { - Basis m = this.orthonormalized(); + Basis m = this.Orthonormalized(); Vector3 euler; euler.z = 0.0f; @@ -169,26 +169,26 @@ namespace Godot { if (mxy > -1.0f) { - euler.x = Mathf.asin(-mxy); - euler.y = Mathf.atan2(m.x[2], m.z[2]); - euler.z = Mathf.atan2(m.y[0], m.y[1]); + euler.x = Mathf.Asin(-mxy); + euler.y = Mathf.Atan2(m.x[2], m.z[2]); + euler.z = Mathf.Atan2(m.y[0], m.y[1]); } else { euler.x = Mathf.PI * 0.5f; - euler.y = -Mathf.atan2(-m.x[1], m.x[0]); + euler.y = -Mathf.Atan2(-m.x[1], m.x[0]); } } else { euler.x = -Mathf.PI * 0.5f; - euler.y = -Mathf.atan2(m.x[1], m.x[0]); + euler.y = -Mathf.Atan2(m.x[1], m.x[0]); } return euler; } - public int get_orthogonal_index() + public int GetOrthogonalIndex() { Basis orth = this; @@ -218,7 +218,7 @@ namespace Godot return 0; } - public Basis inverse() + public Basis Inverse() { Basis inv = this; @@ -259,27 +259,27 @@ namespace Godot return inv; } - public Basis orthonormalized() + public Basis Orthonormalized() { - Vector3 xAxis = get_axis(0); - Vector3 yAxis = get_axis(1); - Vector3 zAxis = get_axis(2); + Vector3 xAxis = GetAxis(0); + Vector3 yAxis = GetAxis(1); + Vector3 zAxis = GetAxis(2); - xAxis.normalize(); - yAxis = (yAxis - xAxis * (xAxis.dot(yAxis))); - yAxis.normalize(); - zAxis = (zAxis - xAxis * (xAxis.dot(zAxis)) - yAxis * (yAxis.dot(zAxis))); - zAxis.normalize(); + xAxis.Normalize(); + yAxis = (yAxis - xAxis * (xAxis.Dot(yAxis))); + yAxis.Normalize(); + zAxis = (zAxis - xAxis * (xAxis.Dot(zAxis)) - yAxis * (yAxis.Dot(zAxis))); + zAxis.Normalize(); - return Basis.create_from_axes(xAxis, yAxis, zAxis); + return Basis.CreateFromAxes(xAxis, yAxis, zAxis); } - public Basis rotated(Vector3 axis, float phi) + public Basis Rotated(Vector3 axis, float phi) { return new Basis(axis, phi) * this; } - public Basis scaled(Vector3 scale) + public Basis Scaled(Vector3 scale) { Basis m = this; @@ -296,22 +296,22 @@ namespace Godot return m; } - public float tdotx(Vector3 with) + public float Tdotx(Vector3 with) { return this[0, 0] * with[0] + this[1, 0] * with[1] + this[2, 0] * with[2]; } - public float tdoty(Vector3 with) + public float Tdoty(Vector3 with) { return this[0, 1] * with[0] + this[1, 1] * with[1] + this[2, 1] * with[2]; } - public float tdotz(Vector3 with) + public float Tdotz(Vector3 with) { return this[0, 2] * with[0] + this[1, 2] * with[1] + this[2, 2] * with[2]; } - public Basis transposed() + public Basis Transposed() { Basis tr = this; @@ -330,17 +330,17 @@ namespace Godot return tr; } - public Vector3 xform(Vector3 v) + public Vector3 Xform(Vector3 v) { return new Vector3 ( - this[0].dot(v), - this[1].dot(v), - this[2].dot(v) + this[0].Dot(v), + this[1].Dot(v), + this[2].Dot(v) ); } - public Vector3 xform_inv(Vector3 v) + public Vector3 XformInv(Vector3 v) { return new Vector3 ( @@ -354,7 +354,7 @@ namespace Godot float trace = x[0] + y[1] + z[2]; if (trace > 0.0f) { - float s = Mathf.sqrt(trace + 1.0f) * 2f; + float s = Mathf.Sqrt(trace + 1.0f) * 2f; float inv_s = 1f / s; return new Quat( (z[1] - y[2]) * inv_s, @@ -363,7 +363,7 @@ namespace Godot s * 0.25f ); } else if (x[0] > y[1] && x[0] > z[2]) { - float s = Mathf.sqrt(x[0] - y[1] - z[2] + 1.0f) * 2f; + float s = Mathf.Sqrt(x[0] - y[1] - z[2] + 1.0f) * 2f; float inv_s = 1f / s; return new Quat( s * 0.25f, @@ -372,7 +372,7 @@ namespace Godot (z[1] - y[2]) * inv_s ); } else if (y[1] > z[2]) { - float s = Mathf.sqrt(-x[0] + y[1] - z[2] + 1.0f) * 2f; + float s = Mathf.Sqrt(-x[0] + y[1] - z[2] + 1.0f) * 2f; float inv_s = 1f / s; return new Quat( (x[1] + y[0]) * inv_s, @@ -381,7 +381,7 @@ namespace Godot (x[2] - z[0]) * inv_s ); } else { - float s = Mathf.sqrt(-x[0] - y[1] + z[2] + 1.0f) * 2f; + float s = Mathf.Sqrt(-x[0] - y[1] + z[2] + 1.0f) * 2f; float inv_s = 1f / s; return new Quat( (x[2] + z[0]) * inv_s, @@ -394,7 +394,7 @@ namespace Godot public Basis(Quat quat) { - float s = 2.0f / quat.length_squared(); + float s = 2.0f / quat.LengthSquared(); float xs = quat.x * s; float ys = quat.y * s; @@ -418,8 +418,8 @@ namespace Godot { Vector3 axis_sq = new Vector3(axis.x * axis.x, axis.y * axis.y, axis.z * axis.z); - float cosine = Mathf.cos(phi); - float sine = Mathf.sin(phi); + float cosine = Mathf.Cos(phi); + float sine = Mathf.Sin(phi); this.x = new Vector3 ( @@ -461,9 +461,9 @@ namespace Godot { return new Basis ( - right.tdotx(left[0]), right.tdoty(left[0]), right.tdotz(left[0]), - right.tdotx(left[1]), right.tdoty(left[1]), right.tdotz(left[1]), - right.tdotx(left[2]), right.tdoty(left[2]), right.tdotz(left[2]) + right.Tdotx(left[0]), right.Tdoty(left[0]), right.Tdotz(left[0]), + right.Tdotx(left[1]), right.Tdoty(left[1]), right.Tdotz(left[1]), + right.Tdotx(left[2]), right.Tdoty(left[2]), right.Tdotz(left[2]) ); } diff --git a/modules/mono/glue/cs_files/Color.cs b/modules/mono/glue/cs_files/Color.cs index 0a00f83d47..db0e1fb744 100644 --- a/modules/mono/glue/cs_files/Color.cs +++ b/modules/mono/glue/cs_files/Color.cs @@ -45,8 +45,8 @@ namespace Godot { get { - float max = Mathf.max(r, Mathf.max(g, b)); - float min = Mathf.min(r, Mathf.min(g, b)); + float max = Mathf.Max(r, Mathf.Max(g, b)); + float min = Mathf.Min(r, Mathf.Min(g, b)); float delta = max - min; @@ -71,7 +71,7 @@ namespace Godot } set { - this = from_hsv(value, s, v); + this = FromHsv(value, s, v); } } @@ -79,8 +79,8 @@ namespace Godot { get { - float max = Mathf.max(r, Mathf.max(g, b)); - float min = Mathf.min(r, Mathf.min(g, b)); + float max = Mathf.Max(r, Mathf.Max(g, b)); + float min = Mathf.Min(r, Mathf.Min(g, b)); float delta = max - min; @@ -88,7 +88,7 @@ namespace Godot } set { - this = from_hsv(h, value, v); + this = FromHsv(h, value, v); } } @@ -96,11 +96,11 @@ namespace Godot { get { - return Mathf.max(r, Mathf.max(g, b)); + return Mathf.Max(r, Mathf.Max(g, b)); } set { - this = from_hsv(h, s, value); + this = FromHsv(h, s, value); } } @@ -154,10 +154,10 @@ namespace Godot } } - public static void to_hsv(Color color, out float hue, out float saturation, out float value) + public static void ToHsv(Color color, out float hue, out float saturation, out float value) { - int max = Mathf.max(color.r8, Mathf.max(color.g8, color.b8)); - int min = Mathf.min(color.r8, Mathf.min(color.g8, color.b8)); + int max = Mathf.Max(color.r8, Mathf.Max(color.g8, color.b8)); + int min = Mathf.Min(color.r8, Mathf.Min(color.g8, color.b8)); float delta = max - min; @@ -184,7 +184,7 @@ namespace Godot value = max / 255f; } - public static Color from_hsv(float hue, float saturation, float value, float alpha = 1.0f) + public static Color FromHsv(float hue, float saturation, float value, float alpha = 1.0f) { if (saturation == 0) { @@ -221,7 +221,7 @@ namespace Godot } } - public Color blend(Color over) + public Color Blend(Color over) { Color res; @@ -242,7 +242,7 @@ namespace Godot return res; } - public Color contrasted() + public Color Contrasted() { return new Color( (r + 0.5f) % 1.0f, @@ -251,12 +251,12 @@ namespace Godot ); } - public float gray() + public float Gray() { return (r + g + b) / 3.0f; } - public Color inverted() + public Color Inverted() { return new Color( 1.0f - r, @@ -265,7 +265,7 @@ namespace Godot ); } - public Color linear_interpolate(Color b, float t) + public Color LinearInterpolate(Color b, float t) { Color res = this; @@ -277,7 +277,7 @@ namespace Godot return res; } - public int to_32() + public int To32() { int c = (byte)(a * 255); c <<= 8; @@ -290,7 +290,7 @@ namespace Godot return c; } - public int to_ARGB32() + public int ToArgb32() { int c = (byte)(a * 255); c <<= 8; @@ -303,7 +303,7 @@ namespace Godot return c; } - public string to_html(bool include_alpha = true) + public string ToHtml(bool include_alpha = true) { String txt = string.Empty; @@ -375,7 +375,7 @@ namespace Godot private String _to_hex(float val) { - int v = (int)Mathf.clamp(val * 255.0f, 0, 255); + int v = (int)Mathf.Clamp(val * 255.0f, 0, 255); string ret = string.Empty; @@ -396,7 +396,7 @@ namespace Godot return ret; } - internal static bool html_is_valid(string color) + internal static bool HtmlIsValid(string color) { if (color.Length == 0) return false; diff --git a/modules/mono/glue/cs_files/GD.cs b/modules/mono/glue/cs_files/GD.cs index 40a42d23b4..99fc289161 100644 --- a/modules/mono/glue/cs_files/GD.cs +++ b/modules/mono/glue/cs_files/GD.cs @@ -6,32 +6,32 @@ namespace Godot { /*{GodotGlobalConstants}*/ - public static object bytes2var(byte[] bytes) + public static object Bytes2Var(byte[] bytes) { return NativeCalls.godot_icall_Godot_bytes2var(bytes); } - public static object convert(object what, int type) + public static object Convert(object what, int type) { return NativeCalls.godot_icall_Godot_convert(what, type); } - public static float db2linear(float db) + public static float Db2Linear(float db) { return (float)Math.Exp(db * 0.11512925464970228420089957273422); } - public static float dectime(float value, float amount, float step) + public static float Dectime(float value, float amount, float step) { float sgn = value < 0 ? -1.0f : 1.0f; - float val = Mathf.abs(value); + float val = Mathf.Abs(value); val -= amount * step; if (val < 0.0f) val = 0.0f; return val * sgn; } - public static FuncRef funcref(Object instance, string funcname) + public static FuncRef Funcref(Object instance, string funcname) { var ret = new FuncRef(); ret.SetInstance(instance); @@ -39,57 +39,57 @@ namespace Godot return ret; } - public static int hash(object var) + public static int Hash(object var) { return NativeCalls.godot_icall_Godot_hash(var); } - public static Object instance_from_id(int instance_id) + public static Object InstanceFromId(int instanceId) { - return NativeCalls.godot_icall_Godot_instance_from_id(instance_id); + return NativeCalls.godot_icall_Godot_instance_from_id(instanceId); } - public static double linear2db(double linear) + public static double Linear2Db(double linear) { return Math.Log(linear) * 8.6858896380650365530225783783321; } - public static Resource load(string path) + public static Resource Load(string path) { return ResourceLoader.Load(path); } - public static void print(params object[] what) + public static void Print(params object[] what) { NativeCalls.godot_icall_Godot_print(what); } - public static void print_stack() + public static void PrintStack() { - print(System.Environment.StackTrace); + Print(System.Environment.StackTrace); } - public static void printerr(params object[] what) + public static void Printerr(params object[] what) { NativeCalls.godot_icall_Godot_printerr(what); } - public static void printraw(params object[] what) + public static void Printraw(params object[] what) { NativeCalls.godot_icall_Godot_printraw(what); } - public static void prints(params object[] what) + public static void Prints(params object[] what) { NativeCalls.godot_icall_Godot_prints(what); } - public static void printt(params object[] what) + public static void Printt(params object[] what) { NativeCalls.godot_icall_Godot_printt(what); } - public static int[] range(int length) + public static int[] Range(int length) { int[] ret = new int[length]; @@ -101,7 +101,7 @@ namespace Godot return ret; } - public static int[] range(int from, int to) + public static int[] Range(int from, int to) { if (to < from) return new int[0]; @@ -116,7 +116,7 @@ namespace Godot return ret; } - public static int[] range(int from, int to, int increment) + public static int[] Range(int from, int to, int increment) { if (to < from && increment > 0) return new int[0]; @@ -153,37 +153,37 @@ namespace Godot return ret; } - public static void seed(int seed) + public static void Seed(int seed) { NativeCalls.godot_icall_Godot_seed(seed); } - public static string str(params object[] what) + public static string Str(params object[] what) { return NativeCalls.godot_icall_Godot_str(what); } - public static object str2var(string str) + public static object Str2Var(string str) { return NativeCalls.godot_icall_Godot_str2var(str); } - public static bool type_exists(string type) + public static bool TypeExists(string type) { return NativeCalls.godot_icall_Godot_type_exists(type); } - public static byte[] var2bytes(object var) + public static byte[] Var2Bytes(object var) { return NativeCalls.godot_icall_Godot_var2bytes(var); } - public static string var2str(object var) + public static string Var2Str(object var) { return NativeCalls.godot_icall_Godot_var2str(var); } - public static WeakRef weakref(Object obj) + public static WeakRef Weakref(Object obj) { return NativeCalls.godot_icall_Godot_weakref(Object.GetPtr(obj)); } diff --git a/modules/mono/glue/cs_files/Mathf.cs b/modules/mono/glue/cs_files/Mathf.cs index cb0eb1acdd..6951ace4fc 100644 --- a/modules/mono/glue/cs_files/Mathf.cs +++ b/modules/mono/glue/cs_files/Mathf.cs @@ -10,37 +10,42 @@ namespace Godot private const float Deg2RadConst = 0.0174532924f; private const float Rad2DegConst = 57.29578f; - public static float abs(float s) + public static float Abs(float s) { return Math.Abs(s); } - public static float acos(float s) + public static float Acos(float s) { return (float)Math.Acos(s); } - public static float asin(float s) + public static float Asin(float s) { return (float)Math.Asin(s); } - public static float atan(float s) + public static float Atan(float s) { return (float)Math.Atan(s); } - public static float atan2(float x, float y) + public static float Atan2(float x, float y) { return (float)Math.Atan2(x, y); } - public static float ceil(float s) + public static Vector2 Cartesian2Polar(float x, float y) + { + return new Vector2(Sqrt(x * x + y * y), Atan2(y, x)); + } + + public static float Ceil(float s) { return (float)Math.Ceiling(s); } - public static float clamp(float val, float min, float max) + public static float Clamp(float val, float min, float max) { if (val < min) { @@ -54,32 +59,32 @@ namespace Godot return val; } - public static float cos(float s) + public static float Cos(float s) { return (float)Math.Cos(s); } - public static float cosh(float s) + public static float Cosh(float s) { return (float)Math.Cosh(s); } - public static int decimals(float step) + public static int Decimals(float step) { - return decimals(step); + return Decimals(step); } - public static int decimals(decimal step) + public static int Decimals(decimal step) { return BitConverter.GetBytes(decimal.GetBits(step)[3])[2]; } - public static float deg2rad(float deg) + public static float Deg2Rad(float deg) { return deg * Deg2RadConst; } - public static float ease(float s, float curve) + public static float Ease(float s, float curve) { if (s < 0f) { @@ -94,35 +99,35 @@ namespace Godot { if (curve < 1.0f) { - return 1.0f - pow(1.0f - s, 1.0f / curve); + return 1.0f - Pow(1.0f - s, 1.0f / curve); } - return pow(s, curve); + return Pow(s, curve); } else if (curve < 0f) { if (s < 0.5f) { - return pow(s * 2.0f, -curve) * 0.5f; + return Pow(s * 2.0f, -curve) * 0.5f; } - return (1.0f - pow(1.0f - (s - 0.5f) * 2.0f, -curve)) * 0.5f + 0.5f; + return (1.0f - Pow(1.0f - (s - 0.5f) * 2.0f, -curve)) * 0.5f + 0.5f; } return 0f; } - public static float exp(float s) + public static float Exp(float s) { return (float)Math.Exp(s); } - public static float floor(float s) + public static float Floor(float s) { return (float)Math.Floor(s); } - public static float fposmod(float x, float y) + public static float Fposmod(float x, float y) { if (x >= 0f) { @@ -134,37 +139,37 @@ namespace Godot } } - public static float lerp(float from, float to, float weight) + public static float Lerp(float from, float to, float weight) { - return from + (to - from) * clamp(weight, 0f, 1f); + return from + (to - from) * Clamp(weight, 0f, 1f); } - public static float log(float s) + public static float Log(float s) { return (float)Math.Log(s); } - public static int max(int a, int b) + public static int Max(int a, int b) { return (a > b) ? a : b; } - public static float max(float a, float b) + public static float Max(float a, float b) { return (a > b) ? a : b; } - public static int min(int a, int b) + public static int Min(int a, int b) { return (a < b) ? a : b; } - public static float min(float a, float b) + public static float Min(float a, float b) { return (a < b) ? a : b; } - public static int nearest_po2(int val) + public static int NearestPo2(int val) { val--; val |= val >> 1; @@ -176,57 +181,62 @@ namespace Godot return val; } - public static float pow(float x, float y) + public static Vector2 Polar2Cartesian(float r, float th) + { + return new Vector2(r * Cos(th), r * Sin(th)); + } + + public static float Pow(float x, float y) { return (float)Math.Pow(x, y); } - public static float rad2deg(float rad) + public static float Rad2Deg(float rad) { return rad * Rad2DegConst; } - public static float round(float s) + public static float Round(float s) { return (float)Math.Round(s); } - public static float sign(float s) + public static float Sign(float s) { return (s < 0f) ? -1f : 1f; } - public static float sin(float s) + public static float Sin(float s) { return (float)Math.Sin(s); } - public static float sinh(float s) + public static float Sinh(float s) { return (float)Math.Sinh(s); } - public static float sqrt(float s) + public static float Sqrt(float s) { return (float)Math.Sqrt(s); } - public static float stepify(float s, float step) + public static float Stepify(float s, float step) { if (step != 0f) { - s = floor(s / step + 0.5f) * step; + s = Floor(s / step + 0.5f) * step; } return s; } - public static float tan(float s) + public static float Tan(float s) { return (float)Math.Tan(s); } - public static float tanh(float s) + public static float Tanh(float s) { return (float)Math.Tanh(s); } diff --git a/modules/mono/glue/cs_files/Plane.cs b/modules/mono/glue/cs_files/Plane.cs index 37f70aca1e..6365e71826 100644 --- a/modules/mono/glue/cs_files/Plane.cs +++ b/modules/mono/glue/cs_files/Plane.cs @@ -52,44 +52,44 @@ namespace Godot } } - public float distance_to(Vector3 point) + public float DistanceTo(Vector3 point) { - return normal.dot(point) - d; + return normal.Dot(point) - d; } - public Vector3 get_any_point() + public Vector3 GetAnyPoint() { return normal * d; } - public bool has_point(Vector3 point, float epsilon = Mathf.Epsilon) + public bool HasPoint(Vector3 point, float epsilon = Mathf.Epsilon) { - float dist = normal.dot(point) - d; - return Mathf.abs(dist) <= epsilon; + float dist = normal.Dot(point) - d; + return Mathf.Abs(dist) <= epsilon; } - public Vector3 intersect_3(Plane b, Plane c) + public Vector3 Intersect3(Plane b, Plane c) { - float denom = normal.cross(b.normal).dot(c.normal); + float denom = normal.Cross(b.normal).Dot(c.normal); - if (Mathf.abs(denom) <= Mathf.Epsilon) + if (Mathf.Abs(denom) <= Mathf.Epsilon) return new Vector3(); - Vector3 result = (b.normal.cross(c.normal) * this.d) + - (c.normal.cross(normal) * b.d) + - (normal.cross(b.normal) * c.d); + Vector3 result = (b.normal.Cross(c.normal) * this.d) + + (c.normal.Cross(normal) * b.d) + + (normal.Cross(b.normal) * c.d); return result / denom; } - public Vector3 intersect_ray(Vector3 from, Vector3 dir) + public Vector3 IntersectRay(Vector3 from, Vector3 dir) { - float den = normal.dot(dir); + float den = normal.Dot(dir); - if (Mathf.abs(den) <= Mathf.Epsilon) + if (Mathf.Abs(den) <= Mathf.Epsilon) return new Vector3(); - float dist = (normal.dot(from) - d) / den; + float dist = (normal.Dot(from) - d) / den; // This is a ray, before the emiting pos (from) does not exist if (dist > Mathf.Epsilon) @@ -98,15 +98,15 @@ namespace Godot return from + dir * -dist; } - public Vector3 intersect_segment(Vector3 begin, Vector3 end) + public Vector3 IntersectSegment(Vector3 begin, Vector3 end) { Vector3 segment = begin - end; - float den = normal.dot(segment); + float den = normal.Dot(segment); - if (Mathf.abs(den) <= Mathf.Epsilon) + if (Mathf.Abs(den) <= Mathf.Epsilon) return new Vector3(); - float dist = (normal.dot(begin) - d) / den; + float dist = (normal.Dot(begin) - d) / den; if (dist < -Mathf.Epsilon || dist > (1.0f + Mathf.Epsilon)) return new Vector3(); @@ -114,14 +114,14 @@ namespace Godot return begin + segment * -dist; } - public bool is_point_over(Vector3 point) + public bool IsPointOver(Vector3 point) { - return normal.dot(point) > d; + return normal.Dot(point) > d; } - public Plane normalized() + public Plane Normalized() { - float len = normal.length(); + float len = normal.Length(); if (len == 0) return new Plane(0, 0, 0, 0); @@ -129,9 +129,9 @@ namespace Godot return new Plane(normal / len, d / len); } - public Vector3 project(Vector3 point) + public Vector3 Project(Vector3 point) { - return point - normal * distance_to(point); + return point - normal * DistanceTo(point); } public Plane(float a, float b, float c, float d) @@ -148,9 +148,9 @@ namespace Godot public Plane(Vector3 v1, Vector3 v2, Vector3 v3) { - normal = (v1 - v3).cross(v1 - v2); - normal.normalize(); - d = normal.dot(v1); + normal = (v1 - v3).Cross(v1 - v2); + normal.Normalize(); + d = normal.Dot(v1); } public static Plane operator -(Plane plane) diff --git a/modules/mono/glue/cs_files/Quat.cs b/modules/mono/glue/cs_files/Quat.cs index 9b4b7fb297..c0ac41c5d7 100644 --- a/modules/mono/glue/cs_files/Quat.cs +++ b/modules/mono/glue/cs_files/Quat.cs @@ -58,40 +58,40 @@ namespace Godot } } - public Quat cubic_slerp(Quat b, Quat preA, Quat postB, float t) + public Quat CubicSlerp(Quat b, Quat preA, Quat postB, float t) { float t2 = (1.0f - t) * t * 2f; - Quat sp = slerp(b, t); - Quat sq = preA.slerpni(postB, t); - return sp.slerpni(sq, t2); + Quat sp = Slerp(b, t); + Quat sq = preA.Slerpni(postB, t); + return sp.Slerpni(sq, t2); } - public float dot(Quat b) + public float Dot(Quat b) { return x * b.x + y * b.y + z * b.z + w * b.w; } - public Quat inverse() + public Quat Inverse() { return new Quat(-x, -y, -z, w); } - public float length() + public float Length() { - return Mathf.sqrt(length_squared()); + return Mathf.Sqrt(LengthSquared()); } - public float length_squared() + public float LengthSquared() { - return dot(this); + return Dot(this); } - public Quat normalized() + public Quat Normalized() { - return this / length(); + return this / Length(); } - public void set(float x, float y, float z, float w) + public void Set(float x, float y, float z, float w) { this.x = x; this.y = y; @@ -99,7 +99,7 @@ namespace Godot this.w = w; } - public Quat slerp(Quat b, float t) + public Quat Slerp(Quat b, float t) { // Calculate cosine float cosom = x * b.x + y * b.y + z * b.z + w * b.w; @@ -128,10 +128,10 @@ namespace Godot if ((1.0 - cosom) > Mathf.Epsilon) { // Standard case (Slerp) - float omega = Mathf.acos(cosom); - sinom = Mathf.sin(omega); - scale0 = Mathf.sin((1.0f - t) * omega) / sinom; - scale1 = Mathf.sin(t * omega) / sinom; + float omega = Mathf.Acos(cosom); + sinom = Mathf.Sin(omega); + scale0 = Mathf.Sin((1.0f - t) * omega) / sinom; + scale1 = Mathf.Sin(t * omega) / sinom; } else { @@ -150,19 +150,19 @@ namespace Godot ); } - public Quat slerpni(Quat b, float t) + public Quat Slerpni(Quat b, float t) { - float dot = this.dot(b); + float dot = this.Dot(b); - if (Mathf.abs(dot) > 0.9999f) + if (Mathf.Abs(dot) > 0.9999f) { return this; } - float theta = Mathf.acos(dot); - float sinT = 1.0f / Mathf.sin(theta); - float newFactor = Mathf.sin(t * theta) * sinT; - float invFactor = Mathf.sin((1.0f - t) * theta) * sinT; + float theta = Mathf.Acos(dot); + float sinT = 1.0f / Mathf.Sin(theta); + float newFactor = Mathf.Sin(t * theta) * sinT; + float invFactor = Mathf.Sin((1.0f - t) * theta) * sinT; return new Quat ( @@ -173,10 +173,10 @@ namespace Godot ); } - public Vector3 xform(Vector3 v) + public Vector3 Xform(Vector3 v) { Quat q = this * v; - q *= this.inverse(); + q *= this.Inverse(); return new Vector3(q.x, q.y, q.z); } @@ -190,7 +190,7 @@ namespace Godot public Quat(Vector3 axis, float angle) { - float d = axis.length(); + float d = axis.Length(); if (d == 0f) { @@ -201,12 +201,12 @@ namespace Godot } else { - float s = Mathf.sin(angle * 0.5f) / d; + float s = Mathf.Sin(angle * 0.5f) / d; x = axis.x * s; y = axis.y * s; z = axis.z * s; - w = Mathf.cos(angle * 0.5f); + w = Mathf.Cos(angle * 0.5f); } } diff --git a/modules/mono/glue/cs_files/Rect2.cs b/modules/mono/glue/cs_files/Rect2.cs index 019342134a..f2718d7b7a 100644 --- a/modules/mono/glue/cs_files/Rect2.cs +++ b/modules/mono/glue/cs_files/Rect2.cs @@ -28,36 +28,36 @@ namespace Godot public float Area { - get { return get_area(); } + get { return GetArea(); } } - public Rect2 clip(Rect2 b) + public Rect2 Clip(Rect2 b) { Rect2 newRect = b; - if (!intersects(newRect)) + if (!Intersects(newRect)) return new Rect2(); - newRect.position.x = Mathf.max(b.position.x, position.x); - newRect.position.y = Mathf.max(b.position.y, position.y); + newRect.position.x = Mathf.Max(b.position.x, position.x); + newRect.position.y = Mathf.Max(b.position.y, position.y); Vector2 bEnd = b.position + b.size; Vector2 end = position + size; - newRect.size.x = Mathf.min(bEnd.x, end.x) - newRect.position.x; - newRect.size.y = Mathf.min(bEnd.y, end.y) - newRect.position.y; + newRect.size.x = Mathf.Min(bEnd.x, end.x) - newRect.position.x; + newRect.size.y = Mathf.Min(bEnd.y, end.y) - newRect.position.y; return newRect; } - public bool encloses(Rect2 b) + public bool Encloses(Rect2 b) { return (b.position.x >= position.x) && (b.position.y >= position.y) && ((b.position.x + b.size.x) < (position.x + size.x)) && ((b.position.y + b.size.y) < (position.y + size.y)); } - public Rect2 expand(Vector2 to) + public Rect2 Expand(Vector2 to) { Rect2 expanded = this; @@ -80,12 +80,12 @@ namespace Godot return expanded; } - public float get_area() + public float GetArea() { return size.x * size.y; } - public Rect2 grow(float by) + public Rect2 Grow(float by) { Rect2 g = this; @@ -97,7 +97,7 @@ namespace Godot return g; } - public Rect2 grow_individual(float left, float top, float right, float bottom) + public Rect2 GrowIndividual(float left, float top, float right, float bottom) { Rect2 g = this; @@ -109,11 +109,11 @@ namespace Godot return g; } - public Rect2 grow_margin(int margin, float by) + public Rect2 GrowMargin(int margin, float by) { Rect2 g = this; - g.grow_individual((GD.MARGIN_LEFT == margin) ? by : 0, + g.GrowIndividual((GD.MARGIN_LEFT == margin) ? by : 0, (GD.MARGIN_TOP == margin) ? by : 0, (GD.MARGIN_RIGHT == margin) ? by : 0, (GD.MARGIN_BOTTOM == margin) ? by : 0); @@ -121,12 +121,12 @@ namespace Godot return g; } - public bool has_no_area() + public bool HasNoArea() { return size.x <= 0 || size.y <= 0; } - public bool has_point(Vector2 point) + public bool HasPoint(Vector2 point) { if (point.x < position.x) return false; @@ -141,7 +141,7 @@ namespace Godot return true; } - public bool intersects(Rect2 b) + public bool Intersects(Rect2 b) { if (position.x > (b.position.x + b.size.x)) return false; @@ -155,15 +155,15 @@ namespace Godot return true; } - public Rect2 merge(Rect2 b) + public Rect2 Merge(Rect2 b) { Rect2 newRect; - newRect.position.x = Mathf.min(b.position.x, position.x); - newRect.position.y = Mathf.min(b.position.y, position.y); + newRect.position.x = Mathf.Min(b.position.x, position.x); + newRect.position.y = Mathf.Min(b.position.y, position.y); - newRect.size.x = Mathf.max(b.position.x + b.size.x, position.x + size.x); - newRect.size.y = Mathf.max(b.position.y + b.size.y, position.y + size.y); + newRect.size.x = Mathf.Max(b.position.x + b.size.x, position.x + size.x); + newRect.size.y = Mathf.Max(b.position.y + b.size.y, position.y + size.y); newRect.size = newRect.size - newRect.position; // Make relative again diff --git a/modules/mono/glue/cs_files/StringExtensions.cs b/modules/mono/glue/cs_files/StringExtensions.cs index 96041827aa..5c3ceff97d 100644 --- a/modules/mono/glue/cs_files/StringExtensions.cs +++ b/modules/mono/glue/cs_files/StringExtensions.cs @@ -10,15 +10,15 @@ namespace Godot { public static class StringExtensions { - private static int get_slice_count(this string instance, string splitter) + private static int GetSliceCount(this string instance, string splitter) { - if (instance.empty() || splitter.empty()) + if (instance.Empty() || splitter.Empty()) return 0; int pos = 0; int slices = 1; - while ((pos = instance.find(splitter, pos)) >= 0) + while ((pos = instance.Find(splitter, pos)) >= 0) { slices++; pos += splitter.Length; @@ -27,9 +27,9 @@ namespace Godot return slices; } - private static string get_slicec(this string instance, char splitter, int slice) + private static string GetSlicec(this string instance, char splitter, int slice) { - if (!instance.empty() && slice >= 0) + if (!instance.Empty() && slice >= 0) { int i = 0; int prev = 0; @@ -60,7 +60,7 @@ namespace Godot // <summary> // If the string is a path to a file, return the path to the file without the extension. // </summary> - public static string basename(this string instance) + public static string Basename(this string instance) { int index = instance.LastIndexOf('.'); @@ -73,7 +73,7 @@ namespace Godot // <summary> // Return true if the strings begins with the given string. // </summary> - public static bool begins_with(this string instance, string text) + public static bool BeginsWith(this string instance, string text) { return instance.StartsWith(text); } @@ -81,7 +81,7 @@ namespace Godot // <summary> // Return the bigrams (pairs of consecutive letters) of this string. // </summary> - public static string[] bigrams(this string instance) + public static string[] Bigrams(this string instance) { string[] b = new string[instance.Length - 1]; @@ -96,7 +96,7 @@ namespace Godot // <summary> // Return a copy of the string with special characters escaped using the C language standard. // </summary> - public static string c_escape(this string instance) + public static string CEscape(this string instance) { StringBuilder sb = new StringBuilder(string.Copy(instance)); @@ -118,7 +118,7 @@ namespace Godot // <summary> // Return a copy of the string with escaped characters replaced by their meanings according to the C language standard. // </summary> - public static string c_unescape(this string instance) + public static string CUnescape(this string instance) { StringBuilder sb = new StringBuilder(string.Copy(instance)); @@ -140,14 +140,14 @@ namespace Godot // <summary> // Change the case of some letters. Replace underscores with spaces, convert all letters to lowercase then capitalize first and every letter following the space character. For [code]capitalize camelCase mixed_with_underscores[/code] it will return [code]Capitalize Camelcase Mixed With Underscores[/code]. // </summary> - public static string capitalize(this string instance) + public static string Capitalize(this string instance) { string aux = instance.Replace("_", " ").ToLower(); string cap = string.Empty; - for (int i = 0; i < aux.get_slice_count(" "); i++) + for (int i = 0; i < aux.GetSliceCount(" "); i++) { - string slice = aux.get_slicec(' ', i); + string slice = aux.GetSlicec(' ', i); if (slice.Length > 0) { slice = char.ToUpper(slice[0]) + slice.Substring(1); @@ -163,12 +163,12 @@ namespace Godot // <summary> // Perform a case-sensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater. // </summary> - public static int casecmp_to(this string instance, string to) + public static int CasecmpTo(this string instance, string to) { - if (instance.empty()) - return to.empty() ? 0 : -1; + if (instance.Empty()) + return to.Empty() ? 0 : -1; - if (to.empty()) + if (to.Empty()) return 1; int instance_idx = 0; @@ -195,7 +195,7 @@ namespace Godot // <summary> // Return true if the string is empty. // </summary> - public static bool empty(this string instance) + public static bool Empty(this string instance) { return string.IsNullOrEmpty(instance); } @@ -203,7 +203,7 @@ namespace Godot // <summary> // Return true if the strings ends with the given string. // </summary> - public static bool ends_with(this string instance, string text) + public static bool EndsWith(this string instance, string text) { return instance.EndsWith(text); } @@ -211,7 +211,7 @@ namespace Godot // <summary> // Erase [code]chars[/code] characters from the string starting from [code]pos[/code]. // </summary> - public static void erase(this StringBuilder instance, int pos, int chars) + public static void Erase(this StringBuilder instance, int pos, int chars) { instance.Remove(pos, chars); } @@ -219,9 +219,9 @@ namespace Godot // <summary> // If the string is a path to a file, return the extension. // </summary> - public static string extension(this string instance) + public static string Extension(this string instance) { - int pos = instance.find_last("."); + int pos = instance.FindLast("."); if (pos < 0) return instance; @@ -232,7 +232,7 @@ namespace Godot // <summary> // Find the first occurrence of a substring, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed. // </summary> - public static int find(this string instance, string what, int from = 0) + public static int Find(this string instance, string what, int from = 0) { return instance.IndexOf(what, StringComparison.OrdinalIgnoreCase); } @@ -240,7 +240,7 @@ namespace Godot // <summary> // Find the last occurrence of a substring, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed. // </summary> - public static int find_last(this string instance, string what) + public static int FindLast(this string instance, string what) { return instance.LastIndexOf(what, StringComparison.OrdinalIgnoreCase); } @@ -248,7 +248,7 @@ namespace Godot // <summary> // Find the first occurrence of a substring but search as case-insensitive, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed. // </summary> - public static int findn(this string instance, string what, int from = 0) + public static int FindN(this string instance, string what, int from = 0) { return instance.IndexOf(what, StringComparison.Ordinal); } @@ -256,9 +256,9 @@ namespace Godot // <summary> // If the string is a path to a file, return the base directory. // </summary> - public static string get_base_dir(this string instance) + public static string GetBaseDir(this string instance) { - int basepos = instance.find("://"); + int basepos = instance.Find("://"); string rs = string.Empty; string @base = string.Empty; @@ -271,7 +271,7 @@ namespace Godot } else { - if (instance.begins_with("/")) + if (instance.BeginsWith("/")) { rs = instance.Substring(1, instance.Length); @base = "/"; @@ -282,7 +282,7 @@ namespace Godot } } - int sep = Mathf.max(rs.find_last("/"), rs.find_last("\\")); + int sep = Mathf.Max(rs.FindLast("/"), rs.FindLast("\\")); if (sep == -1) return @base; @@ -293,9 +293,9 @@ namespace Godot // <summary> // If the string is a path to a file, return the file and ignore the base directory. // </summary> - public static string get_file(this string instance) + public static string GetFile(this string instance) { - int sep = Mathf.max(instance.find_last("/"), instance.find_last("\\")); + int sep = Mathf.Max(instance.FindLast("/"), instance.FindLast("\\")); if (sep == -1) return instance; @@ -306,7 +306,7 @@ namespace Godot // <summary> // Hash the string and return a 32 bits integer. // </summary> - public static int hash(this string instance) + public static int Hash(this string instance) { int index = 0; int hashv = 5381; @@ -321,7 +321,7 @@ namespace Godot // <summary> // Convert a string containing an hexadecimal number into an int. // </summary> - public static int hex_to_int(this string instance) + public static int HexToInt(this string instance) { int sign = 1; @@ -340,7 +340,7 @@ namespace Godot // <summary> // Insert a substring at a given position. // </summary> - public static string insert(this string instance, int pos, string what) + public static string Insert(this string instance, int pos, string what) { return instance.Insert(pos, what); } @@ -348,7 +348,7 @@ namespace Godot // <summary> // If the string is a path to a file or directory, return true if the path is absolute. // </summary> - public static bool is_abs_path(this string instance) + public static bool IsAbsPath(this string instance) { return System.IO.Path.IsPathRooted(instance); } @@ -356,7 +356,7 @@ namespace Godot // <summary> // If the string is a path to a file or directory, return true if the path is relative. // </summary> - public static bool is_rel_path(this string instance) + public static bool IsRelPath(this string instance) { return !System.IO.Path.IsPathRooted(instance); } @@ -364,7 +364,7 @@ namespace Godot // <summary> // Check whether this string is a subsequence of the given string. // </summary> - public static bool is_subsequence_of(this string instance, string text, bool case_insensitive) + public static bool IsSubsequenceOf(this string instance, string text, bool case_insensitive) { int len = instance.Length; @@ -407,23 +407,23 @@ namespace Godot // <summary> // Check whether this string is a subsequence of the given string, considering case. // </summary> - public static bool is_subsequence_of(this string instance, string text) + public static bool IsSubsequenceOf(this string instance, string text) { - return instance.is_subsequence_of(text, false); + return instance.IsSubsequenceOf(text, false); } // <summary> // Check whether this string is a subsequence of the given string, without considering case. // </summary> - public static bool is_subsequence_ofi(this string instance, string text) + public static bool IsSubsequenceOfI(this string instance, string text) { - return instance.is_subsequence_of(text, true); + return instance.IsSubsequenceOf(text, true); } // <summary> // Check whether the string contains a valid float. // </summary> - public static bool is_valid_float(this string instance) + public static bool IsValidFloat(this string instance) { float f; return float.TryParse(instance, out f); @@ -432,15 +432,15 @@ namespace Godot // <summary> // Check whether the string contains a valid color in HTML notation. // </summary> - public static bool is_valid_html_color(this string instance) + public static bool IsValidHtmlColor(this string instance) { - return Color.html_is_valid(instance); + return Color.HtmlIsValid(instance); } // <summary> // Check whether the string is a valid identifier. As is common in programming languages, a valid identifier may contain only letters, digits and underscores (_) and the first character may not be a digit. // </summary> - public static bool is_valid_identifier(this string instance) + public static bool IsValidIdentifier(this string instance) { int len = instance.Length; @@ -467,7 +467,7 @@ namespace Godot // <summary> // Check whether the string contains a valid integer. // </summary> - public static bool is_valid_integer(this string instance) + public static bool IsValidInteger(this string instance) { int f; return int.TryParse(instance, out f); @@ -476,7 +476,7 @@ namespace Godot // <summary> // Check whether the string contains a valid IP address. // </summary> - public static bool is_valid_ip_address(this string instance) + public static bool IsValidIpAddress(this string instance) { string[] ip = instance.split("."); @@ -486,7 +486,7 @@ namespace Godot for (int i = 0; i < ip.Length; i++) { string n = ip[i]; - if (!n.is_valid_integer()) + if (!n.IsValidInteger()) return false; int val = n.to_int(); @@ -500,7 +500,7 @@ namespace Godot // <summary> // Return a copy of the string with special characters escaped using the JSON standard. // </summary> - public static string json_escape(this string instance) + public static string JsonEscape(this string instance) { StringBuilder sb = new StringBuilder(string.Copy(instance)); @@ -519,7 +519,7 @@ namespace Godot // <summary> // Return an amount of characters from the left of the string. // </summary> - public static string left(this string instance, int pos) + public static string Left(this string instance, int pos) { if (pos <= 0) return string.Empty; @@ -533,7 +533,7 @@ namespace Godot /// <summary> /// Return the length of the string in characters. /// </summary> - public static int length(this string instance) + public static int Length(this string instance) { return instance.Length; } @@ -541,7 +541,7 @@ namespace Godot // <summary> // Do a simple expression match, where '*' matches zero or more arbitrary characters and '?' matches any single character except '.'. // </summary> - public static bool expr_match(this string instance, string expr, bool case_sensitive) + public static bool ExprMatch(this string instance, string expr, bool caseSensitive) { if (expr.Length == 0 || instance.Length == 0) return false; @@ -551,21 +551,21 @@ namespace Godot case '\0': return instance[0] == 0; case '*': - return expr_match(expr + 1, instance, case_sensitive) || (instance[0] != 0 && expr_match(expr, instance + 1, case_sensitive)); + return ExprMatch(expr + 1, instance, caseSensitive) || (instance[0] != 0 && ExprMatch(expr, instance + 1, caseSensitive)); case '?': - return instance[0] != 0 && instance[0] != '.' && expr_match(expr + 1, instance + 1, case_sensitive); + return instance[0] != 0 && instance[0] != '.' && ExprMatch(expr + 1, instance + 1, caseSensitive); default: - return (case_sensitive ? instance[0] == expr[0] : char.ToUpper(instance[0]) == char.ToUpper(expr[0])) && - expr_match(expr + 1, instance + 1, case_sensitive); + return (caseSensitive ? instance[0] == expr[0] : char.ToUpper(instance[0]) == char.ToUpper(expr[0])) && + ExprMatch(expr + 1, instance + 1, caseSensitive); } } // <summary> // Do a simple case sensitive expression match, using ? and * wildcards (see [method expr_match]). // </summary> - public static bool match(this string instance, string expr) + public static bool Match(this string instance, string expr) { - return instance.expr_match(expr, true); + return instance.ExprMatch(expr, true); } // <summary> @@ -573,13 +573,13 @@ namespace Godot // </summary> public static bool matchn(this string instance, string expr) { - return instance.expr_match(expr, false); + return instance.ExprMatch(expr, false); } // <summary> // Return the MD5 hash of the string as an array of bytes. // </summary> - public static byte[] md5_buffer(this string instance) + public static byte[] Md5Buffer(this string instance) { return NativeCalls.godot_icall_String_md5_buffer(instance); } @@ -587,7 +587,7 @@ namespace Godot // <summary> // Return the MD5 hash of the string as a string. // </summary> - public static string md5_text(this string instance) + public static string Md5Text(this string instance) { return NativeCalls.godot_icall_String_md5_text(instance); } @@ -595,12 +595,12 @@ namespace Godot // <summary> // Perform a case-insensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater. // </summary> - public static int nocasecmp_to(this string instance, string to) + public static int NocasecmpTo(this string instance, string to) { - if (instance.empty()) - return to.empty() ? 0 : -1; + if (instance.Empty()) + return to.Empty() ? 0 : -1; - if (to.empty()) + if (to.Empty()) return 1; int instance_idx = 0; @@ -627,7 +627,7 @@ namespace Godot // <summary> // Return the character code at position [code]at[/code]. // </summary> - public static int ord_at(this string instance, int at) + public static int OrdAt(this string instance, int at) { return instance[at]; } @@ -635,9 +635,9 @@ namespace Godot // <summary> // Format a number to have an exact number of [code]digits[/code] after the decimal point. // </summary> - public static string pad_decimals(this string instance, int digits) + public static string PadDecimals(this string instance, int digits) { - int c = instance.find("."); + int c = instance.Find("."); if (c == -1) { @@ -671,10 +671,10 @@ namespace Godot // <summary> // Format a number to have an exact number of [code]digits[/code] before the decimal point. // </summary> - public static string pad_zeros(this string instance, int digits) + public static string PadZeros(this string instance, int digits) { string s = instance; - int end = s.find("."); + int end = s.Find("."); if (end == -1) end = s.Length; @@ -704,7 +704,7 @@ namespace Godot // <summary> // Decode a percent-encoded string. See [method percent_encode]. // </summary> - public static string percent_decode(this string instance) + public static string PercentDecode(this string instance) { return Uri.UnescapeDataString(instance); } @@ -712,7 +712,7 @@ namespace Godot // <summary> // Percent-encode a string. This is meant to encode parameters in a URL when sending a HTTP GET request and bodies of form-urlencoded POST request. // </summary> - public static string percent_encode(this string instance) + public static string PercentEncode(this string instance) { return Uri.EscapeDataString(instance); } @@ -720,7 +720,7 @@ namespace Godot // <summary> // If the string is a path, this concatenates [code]file[/code] at the end of the string as a subpath. E.g. [code]"this/is".plus_file("path") == "this/is/path"[/code]. // </summary> - public static string plus_file(this string instance, string file) + public static string PlusFile(this string instance, string file) { if (instance.Length > 0 && instance[instance.Length - 1] == '/') return instance + file; @@ -731,7 +731,7 @@ namespace Godot // <summary> // Replace occurrences of a substring for different ones inside the string. // </summary> - public static string replace(this string instance, string what, string forwhat) + public static string Replace(this string instance, string what, string forwhat) { return instance.Replace(what, forwhat); } @@ -739,7 +739,7 @@ namespace Godot // <summary> // Replace occurrences of a substring for different ones inside the string, but search case-insensitive. // </summary> - public static string replacen(this string instance, string what, string forwhat) + public static string Replacen(this string instance, string what, string forwhat) { return Regex.Replace(instance, what, forwhat, RegexOptions.IgnoreCase); } @@ -747,7 +747,7 @@ namespace Godot // <summary> // Perform a search for a substring, but start from the end of the string instead of the beginning. // </summary> - public static int rfind(this string instance, string what, int from = -1) + public static int Rfind(this string instance, string what, int from = -1) { return NativeCalls.godot_icall_String_rfind(instance, what, from); } @@ -755,7 +755,7 @@ namespace Godot // <summary> // Perform a search for a substring, but start from the end of the string instead of the beginning. Also search case-insensitive. // </summary> - public static int rfindn(this string instance, string what, int from = -1) + public static int Rfindn(this string instance, string what, int from = -1) { return NativeCalls.godot_icall_String_rfindn(instance, what, from); } @@ -763,7 +763,7 @@ namespace Godot // <summary> // Return the right side of the string from a given position. // </summary> - public static string right(this string instance, int pos) + public static string Right(this string instance, int pos) { if (pos >= instance.Length) return instance; @@ -774,7 +774,7 @@ namespace Godot return instance.Substring(pos, (instance.Length - pos)); } - public static byte[] sha256_buffer(this string instance) + public static byte[] Sha256Buffer(this string instance) { return NativeCalls.godot_icall_String_sha256_buffer(instance); } @@ -782,7 +782,7 @@ namespace Godot // <summary> // Return the SHA-256 hash of the string as a string. // </summary> - public static string sha256_text(this string instance) + public static string Sha256Text(this string instance) { return NativeCalls.godot_icall_String_sha256_text(instance); } @@ -790,7 +790,7 @@ namespace Godot // <summary> // Return the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar. // </summary> - public static float similarity(this string instance, string text) + public static float Similarity(this string instance, string text) { if (instance == text) { @@ -803,11 +803,11 @@ namespace Godot return 0.0f; } - string[] src_bigrams = instance.bigrams(); - string[] tgt_bigrams = text.bigrams(); + string[] srcBigrams = instance.Bigrams(); + string[] tgtBigrams = text.Bigrams(); - int src_size = src_bigrams.Length; - int tgt_size = tgt_bigrams.Length; + int src_size = srcBigrams.Length; + int tgt_size = tgtBigrams.Length; float sum = src_size + tgt_size; float inter = 0; @@ -816,7 +816,7 @@ namespace Godot { for (int j = 0; j < tgt_size; j++) { - if (src_bigrams[i] == tgt_bigrams[j]) + if (srcBigrams[i] == tgtBigrams[j]) { inter++; break; @@ -846,7 +846,7 @@ namespace Godot while (true) { - int end = instance.find(divisor, from); + int end = instance.Find(divisor, from); if (end < 0) end = len; if (allow_empty || (end > from)) diff --git a/modules/mono/glue/cs_files/Transform.cs b/modules/mono/glue/cs_files/Transform.cs index 74271e758b..5214100d36 100644 --- a/modules/mono/glue/cs_files/Transform.cs +++ b/modules/mono/glue/cs_files/Transform.cs @@ -9,38 +9,38 @@ namespace Godot public Basis basis; public Vector3 origin; - public Transform affine_inverse() + public Transform AffineInverse() { - Basis basisInv = basis.inverse(); - return new Transform(basisInv, basisInv.xform(-origin)); + Basis basisInv = basis.Inverse(); + return new Transform(basisInv, basisInv.Xform(-origin)); } - public Transform inverse() + public Transform Inverse() { - Basis basisTr = basis.transposed(); - return new Transform(basisTr, basisTr.xform(-origin)); + Basis basisTr = basis.Transposed(); + return new Transform(basisTr, basisTr.Xform(-origin)); } - public Transform looking_at(Vector3 target, Vector3 up) + public Transform LookingAt(Vector3 target, Vector3 up) { Transform t = this; t.set_look_at(origin, target, up); return t; } - public Transform orthonormalized() + public Transform Orthonormalized() { - return new Transform(basis.orthonormalized(), origin); + return new Transform(basis.Orthonormalized(), origin); } - public Transform rotated(Vector3 axis, float phi) + public Transform Rotated(Vector3 axis, float phi) { return new Transform(new Basis(axis, phi), new Vector3()) * this; } - public Transform scaled(Vector3 scale) + public Transform Scaled(Vector3 scale) { - return new Transform(basis.scaled(scale), origin * scale); + return new Transform(basis.Scaled(scale), origin * scale); } public void set_look_at(Vector3 eye, Vector3 target, Vector3 up) @@ -49,44 +49,44 @@ namespace Godot // Z vector Vector3 zAxis = eye - target; - zAxis.normalize(); + zAxis.Normalize(); Vector3 yAxis = up; - Vector3 xAxis = yAxis.cross(zAxis); + Vector3 xAxis = yAxis.Cross(zAxis); // Recompute Y = Z cross X - yAxis = zAxis.cross(xAxis); + yAxis = zAxis.Cross(xAxis); - xAxis.normalize(); - yAxis.normalize(); + xAxis.Normalize(); + yAxis.Normalize(); - basis = Basis.create_from_axes(xAxis, yAxis, zAxis); + basis = Basis.CreateFromAxes(xAxis, yAxis, zAxis); origin = eye; } - public Transform translated(Vector3 ofs) + public Transform Translated(Vector3 ofs) { return new Transform(basis, new Vector3 ( - origin[0] += basis[0].dot(ofs), - origin[1] += basis[1].dot(ofs), - origin[2] += basis[2].dot(ofs) + origin[0] += basis[0].Dot(ofs), + origin[1] += basis[1].Dot(ofs), + origin[2] += basis[2].Dot(ofs) )); } - public Vector3 xform(Vector3 v) + public Vector3 Xform(Vector3 v) { return new Vector3 ( - basis[0].dot(v) + origin.x, - basis[1].dot(v) + origin.y, - basis[2].dot(v) + origin.z + basis[0].Dot(v) + origin.x, + basis[1].Dot(v) + origin.y, + basis[2].Dot(v) + origin.z ); } - public Vector3 xform_inv(Vector3 v) + public Vector3 XformInv(Vector3 v) { Vector3 vInv = v - origin; @@ -100,7 +100,7 @@ namespace Godot public Transform(Vector3 xAxis, Vector3 yAxis, Vector3 zAxis, Vector3 origin) { - this.basis = Basis.create_from_axes(xAxis, yAxis, zAxis); + this.basis = Basis.CreateFromAxes(xAxis, yAxis, zAxis); this.origin = origin; } @@ -118,7 +118,7 @@ namespace Godot public static Transform operator *(Transform left, Transform right) { - left.origin = left.xform(right.origin); + left.origin = left.Xform(right.origin); left.basis *= right.basis; return left; } diff --git a/modules/mono/glue/cs_files/Transform2D.cs b/modules/mono/glue/cs_files/Transform2D.cs index 526dc767c6..fe7c5b5706 100644 --- a/modules/mono/glue/cs_files/Transform2D.cs +++ b/modules/mono/glue/cs_files/Transform2D.cs @@ -29,12 +29,12 @@ namespace Godot public float Rotation { - get { return Mathf.atan2(y.x, o.y); } + get { return Mathf.Atan2(y.x, o.y); } } public Vector2 Scale { - get { return new Vector2(x.length(), y.length()); } + get { return new Vector2(x.Length(), y.Length()); } } public Vector2 this[int index] @@ -103,7 +103,7 @@ namespace Godot } } - public Transform2D affine_inverse() + public Transform2D AffineInverse() { Transform2D inv = this; @@ -128,22 +128,22 @@ namespace Godot this[0] *= new Vector2(idet, -idet); this[1] *= new Vector2(-idet, idet); - this[2] = basis_xform(-this[2]); + this[2] = BasisXform(-this[2]); return inv; } - public Vector2 basis_xform(Vector2 v) + public Vector2 BasisXform(Vector2 v) { - return new Vector2(tdotx(v), tdoty(v)); + return new Vector2(Tdotx(v), Tdoty(v)); } - public Vector2 basis_xform_inv(Vector2 v) + public Vector2 BasisXformInv(Vector2 v) { - return new Vector2(x.dot(v), y.dot(v)); + return new Vector2(x.Dot(v), y.Dot(v)); } - public Transform2D interpolate_with(Transform2D m, float c) + public Transform2D InterpolateWith(Transform2D m, float c) { float r1 = Rotation; float r2 = m.Rotation; @@ -152,10 +152,10 @@ namespace Godot Vector2 s2 = m.Scale; // Slerp rotation - Vector2 v1 = new Vector2(Mathf.cos(r1), Mathf.sin(r1)); - Vector2 v2 = new Vector2(Mathf.cos(r2), Mathf.sin(r2)); + Vector2 v1 = new Vector2(Mathf.Cos(r1), Mathf.Sin(r1)); + Vector2 v2 = new Vector2(Mathf.Cos(r2), Mathf.Sin(r2)); - float dot = v1.dot(v2); + float dot = v1.Dot(v2); // Clamp dot to [-1, 1] dot = (dot < -1.0f) ? -1.0f : ((dot > 1.0f) ? 1.0f : dot); @@ -165,13 +165,13 @@ namespace Godot if (dot > 0.9995f) { // Linearly interpolate to avoid numerical precision issues - v = v1.linear_interpolate(v2, c).normalized(); + v = v1.LinearInterpolate(v2, c).Normalized(); } else { - float angle = c * Mathf.acos(dot); - Vector2 v3 = (v2 - v1 * dot).normalized(); - v = v1 * Mathf.cos(angle) + v3 * Mathf.sin(angle); + float angle = c * Mathf.Acos(dot); + Vector2 v3 = (v2 - v1 * dot).Normalized(); + v = v1 * Mathf.Cos(angle) + v3 * Mathf.Sin(angle); } // Extract parameters @@ -179,15 +179,15 @@ namespace Godot Vector2 p2 = m.Origin; // Construct matrix - Transform2D res = new Transform2D(Mathf.atan2(v.y, v.x), p1.linear_interpolate(p2, c)); - Vector2 scale = s1.linear_interpolate(s2, c); + Transform2D res = new Transform2D(Mathf.Atan2(v.y, v.x), p1.LinearInterpolate(p2, c)); + Vector2 scale = s1.LinearInterpolate(s2, c); res.x *= scale; res.y *= scale; return res; } - public Transform2D inverse() + public Transform2D Inverse() { Transform2D inv = this; @@ -196,21 +196,21 @@ namespace Godot inv.x.y = inv.y.x; inv.y.x = temp; - inv.o = inv.basis_xform(-inv.o); + inv.o = inv.BasisXform(-inv.o); return inv; } - public Transform2D orthonormalized() + public Transform2D Orthonormalized() { Transform2D on = this; Vector2 onX = on.x; Vector2 onY = on.y; - onX.normalize(); - onY = onY - onX * (onX.dot(onY)); - onY.normalize(); + onX.Normalize(); + onY = onY - onX * (onX.Dot(onY)); + onY.Normalize(); on.x = onX; on.y = onY; @@ -218,12 +218,12 @@ namespace Godot return on; } - public Transform2D rotated(float phi) + public Transform2D Rotated(float phi) { return this * new Transform2D(phi, new Vector2()); } - public Transform2D scaled(Vector2 scale) + public Transform2D Scaled(Vector2 scale) { Transform2D copy = this; copy.x *= scale; @@ -232,32 +232,32 @@ namespace Godot return copy; } - private float tdotx(Vector2 with) + private float Tdotx(Vector2 with) { return this[0, 0] * with[0] + this[1, 0] * with[1]; } - private float tdoty(Vector2 with) + private float Tdoty(Vector2 with) { return this[0, 1] * with[0] + this[1, 1] * with[1]; } - public Transform2D translated(Vector2 offset) + public Transform2D Translated(Vector2 offset) { Transform2D copy = this; - copy.o += copy.basis_xform(offset); + copy.o += copy.BasisXform(offset); return copy; } - public Vector2 xform(Vector2 v) + public Vector2 Xform(Vector2 v) { - return new Vector2(tdotx(v), tdoty(v)) + o; + return new Vector2(Tdotx(v), Tdoty(v)) + o; } - public Vector2 xform_inv(Vector2 v) + public Vector2 XformInv(Vector2 v) { Vector2 vInv = v - o; - return new Vector2(x.dot(vInv), y.dot(vInv)); + return new Vector2(x.Dot(vInv), y.Dot(vInv)); } public Transform2D(Vector2 xAxis, Vector2 yAxis, Vector2 origin) @@ -275,8 +275,8 @@ namespace Godot public Transform2D(float rot, Vector2 pos) { - float cr = Mathf.cos(rot); - float sr = Mathf.sin(rot); + float cr = Mathf.Cos(rot); + float sr = Mathf.Sin(rot); x.x = cr; y.y = cr; x.y = -sr; @@ -286,14 +286,14 @@ namespace Godot public static Transform2D operator *(Transform2D left, Transform2D right) { - left.o = left.xform(right.o); + left.o = left.Xform(right.o); float x0, x1, y0, y1; - x0 = left.tdotx(right.x); - x1 = left.tdoty(right.x); - y0 = left.tdotx(right.y); - y1 = left.tdoty(right.y); + x0 = left.Tdotx(right.x); + x1 = left.Tdoty(right.x); + y0 = left.Tdotx(right.y); + y1 = left.Tdoty(right.y); left.x.x = x0; left.x.y = x1; diff --git a/modules/mono/glue/cs_files/Vector2.cs b/modules/mono/glue/cs_files/Vector2.cs index 28fedc365b..238775bda2 100644 --- a/modules/mono/glue/cs_files/Vector2.cs +++ b/modules/mono/glue/cs_files/Vector2.cs @@ -46,57 +46,57 @@ namespace Godot } } - internal void normalize() + internal void Normalize() { float length = x * x + y * y; if (length != 0f) { - length = Mathf.sqrt(length); + length = Mathf.Sqrt(length); x /= length; y /= length; } } - private float cross(Vector2 b) + private float Cross(Vector2 b) { return x * b.y - y * b.x; } - public Vector2 abs() + public Vector2 Abs() { - return new Vector2(Mathf.abs(x), Mathf.abs(y)); + return new Vector2(Mathf.Abs(x), Mathf.Abs(y)); } - public float angle() + public float Angle() { - return Mathf.atan2(y, x); + return Mathf.Atan2(y, x); } - public float angle_to(Vector2 to) + public float AngleTo(Vector2 to) { - return Mathf.atan2(cross(to), dot(to)); + return Mathf.Atan2(Cross(to), Dot(to)); } - public float angle_to_point(Vector2 to) + public float AngleToPoint(Vector2 to) { - return Mathf.atan2(x - to.x, y - to.y); + return Mathf.Atan2(x - to.x, y - to.y); } - public float aspect() + public float Aspect() { return x / y; } - public Vector2 bounce(Vector2 n) + public Vector2 Bounce(Vector2 n) { - return -reflect(n); + return -Reflect(n); } - public Vector2 clamped(float length) + public Vector2 Clamped(float length) { Vector2 v = this; - float l = this.length(); + float l = this.Length(); if (l > 0 && length < l) { @@ -107,7 +107,7 @@ namespace Godot return v; } - public Vector2 cubic_interpolate(Vector2 b, Vector2 preA, Vector2 postB, float t) + public Vector2 CubicInterpolate(Vector2 b, Vector2 preA, Vector2 postB, float t) { Vector2 p0 = preA; Vector2 p1 = this; @@ -123,42 +123,42 @@ namespace Godot (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t3); } - public float distance_squared_to(Vector2 to) + public float DistanceSquaredTo(Vector2 to) { return (x - to.x) * (x - to.x) + (y - to.y) * (y - to.y); } - public float distance_to(Vector2 to) + public float DistanceTo(Vector2 to) { - return Mathf.sqrt((x - to.x) * (x - to.x) + (y - to.y) * (y - to.y)); + return Mathf.Sqrt((x - to.x) * (x - to.x) + (y - to.y) * (y - to.y)); } - public float dot(Vector2 with) + public float Dot(Vector2 with) { return x * with.x + y * with.y; } - public Vector2 floor() + public Vector2 Floor() { - return new Vector2(Mathf.floor(x), Mathf.floor(y)); + return new Vector2(Mathf.Floor(x), Mathf.Floor(y)); } - public bool is_normalized() + public bool IsNormalized() { - return Mathf.abs(length_squared() - 1.0f) < Mathf.Epsilon; + return Mathf.Abs(LengthSquared() - 1.0f) < Mathf.Epsilon; } - public float length() + public float Length() { - return Mathf.sqrt(x * x + y * y); + return Mathf.Sqrt(x * x + y * y); } - public float length_squared() + public float LengthSquared() { return x * x + y * y; } - public Vector2 linear_interpolate(Vector2 b, float t) + public Vector2 LinearInterpolate(Vector2 b, float t) { Vector2 res = this; @@ -168,35 +168,35 @@ namespace Godot return res; } - public Vector2 normalized() + public Vector2 Normalized() { Vector2 result = this; - result.normalize(); + result.Normalize(); return result; } - public Vector2 reflect(Vector2 n) + public Vector2 Reflect(Vector2 n) { - return 2.0f * n * dot(n) - this; + return 2.0f * n * Dot(n) - this; } - public Vector2 rotated(float phi) + public Vector2 Rotated(float phi) { - float rads = angle() + phi; - return new Vector2(Mathf.cos(rads), Mathf.sin(rads)) * length(); + float rads = Angle() + phi; + return new Vector2(Mathf.Cos(rads), Mathf.Sin(rads)) * Length(); } - public Vector2 slide(Vector2 n) + public Vector2 Slide(Vector2 n) { - return this - n * dot(n); + return this - n * Dot(n); } - public Vector2 snapped(Vector2 by) + public Vector2 Snapped(Vector2 by) { - return new Vector2(Mathf.stepify(x, by.x), Mathf.stepify(y, by.y)); + return new Vector2(Mathf.Stepify(x, by.x), Mathf.Stepify(y, by.y)); } - public Vector2 tangent() + public Vector2 Tangent() { return new Vector2(y, -x); } diff --git a/modules/mono/glue/cs_files/Vector3.cs b/modules/mono/glue/cs_files/Vector3.cs index c023cd83cf..190caa4b53 100644 --- a/modules/mono/glue/cs_files/Vector3.cs +++ b/modules/mono/glue/cs_files/Vector3.cs @@ -59,9 +59,9 @@ namespace Godot } } - internal void normalize() + internal void Normalize() { - float length = this.length(); + float length = this.Length(); if (length == 0f) { @@ -75,27 +75,27 @@ namespace Godot } } - public Vector3 abs() + public Vector3 Abs() { - return new Vector3(Mathf.abs(x), Mathf.abs(y), Mathf.abs(z)); + return new Vector3(Mathf.Abs(x), Mathf.Abs(y), Mathf.Abs(z)); } - public float angle_to(Vector3 to) + public float AngleTo(Vector3 to) { - return Mathf.atan2(cross(to).length(), dot(to)); + return Mathf.Atan2(Cross(to).Length(), Dot(to)); } - public Vector3 bounce(Vector3 n) + public Vector3 Bounce(Vector3 n) { - return -reflect(n); + return -Reflect(n); } - public Vector3 ceil() + public Vector3 Ceil() { - return new Vector3(Mathf.ceil(x), Mathf.ceil(y), Mathf.ceil(z)); + return new Vector3(Mathf.Ceil(x), Mathf.Ceil(y), Mathf.Ceil(z)); } - public Vector3 cross(Vector3 b) + public Vector3 Cross(Vector3 b) { return new Vector3 ( @@ -105,7 +105,7 @@ namespace Godot ); } - public Vector3 cubic_interpolate(Vector3 b, Vector3 preA, Vector3 postB, float t) + public Vector3 CubicInterpolate(Vector3 b, Vector3 preA, Vector3 postB, float t) { Vector3 p0 = preA; Vector3 p1 = this; @@ -122,46 +122,46 @@ namespace Godot ); } - public float distance_squared_to(Vector3 b) + public float DistanceSquaredTo(Vector3 b) { - return (b - this).length_squared(); + return (b - this).LengthSquared(); } - public float distance_to(Vector3 b) + public float DistanceTo(Vector3 b) { - return (b - this).length(); + return (b - this).Length(); } - public float dot(Vector3 b) + public float Dot(Vector3 b) { return x * b.x + y * b.y + z * b.z; } - public Vector3 floor() + public Vector3 Floor() { - return new Vector3(Mathf.floor(x), Mathf.floor(y), Mathf.floor(z)); + return new Vector3(Mathf.Floor(x), Mathf.Floor(y), Mathf.Floor(z)); } - public Vector3 inverse() + public Vector3 Inverse() { return new Vector3(1.0f / x, 1.0f / y, 1.0f / z); } - public bool is_normalized() + public bool IsNormalized() { - return Mathf.abs(length_squared() - 1.0f) < Mathf.Epsilon; + return Mathf.Abs(LengthSquared() - 1.0f) < Mathf.Epsilon; } - public float length() + public float Length() { float x2 = x * x; float y2 = y * y; float z2 = z * z; - return Mathf.sqrt(x2 + y2 + z2); + return Mathf.Sqrt(x2 + y2 + z2); } - public float length_squared() + public float LengthSquared() { float x2 = x * x; float y2 = y * y; @@ -170,7 +170,7 @@ namespace Godot return x2 + y2 + z2; } - public Vector3 linear_interpolate(Vector3 b, float t) + public Vector3 LinearInterpolate(Vector3 b, float t) { return new Vector3 ( @@ -180,24 +180,24 @@ namespace Godot ); } - public Axis max_axis() + public Axis MaxAxis() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); } - public Axis min_axis() + public Axis MinAxis() { return x < y ? (x < z ? Axis.X : Axis.Z) : (y < z ? Axis.Y : Axis.Z); } - public Vector3 normalized() + public Vector3 Normalized() { Vector3 v = this; - v.normalize(); + v.Normalize(); return v; } - public Basis outer(Vector3 b) + public Basis Outer(Vector3 b) { return new Basis( new Vector3(x * b.x, x * b.y, x * b.z), @@ -206,36 +206,36 @@ namespace Godot ); } - public Vector3 reflect(Vector3 n) + public Vector3 Reflect(Vector3 n) { #if DEBUG - if (!n.is_normalized()) + if (!n.IsNormalized()) throw new ArgumentException(String.Format("{0} is not normalized", n), nameof(n)); #endif - return 2.0f * n * dot(n) - this; + return 2.0f * n * Dot(n) - this; } - public Vector3 rotated(Vector3 axis, float phi) + public Vector3 Rotated(Vector3 axis, float phi) { - return new Basis(axis, phi).xform(this); + return new Basis(axis, phi).Xform(this); } - public Vector3 slide(Vector3 n) + public Vector3 Slide(Vector3 n) { - return this - n * dot(n); + return this - n * Dot(n); } - public Vector3 snapped(Vector3 by) + public Vector3 Snapped(Vector3 by) { return new Vector3 ( - Mathf.stepify(x, by.x), - Mathf.stepify(y, by.y), - Mathf.stepify(z, by.z) + Mathf.Stepify(x, by.x), + Mathf.Stepify(y, by.y), + Mathf.Stepify(z, by.z) ); } - public Basis to_diagonal_matrix() + public Basis ToDiagonalMatrix() { return new Basis( x, 0f, 0f, diff --git a/modules/mono/godotsharp_dirs.cpp b/modules/mono/godotsharp_dirs.cpp index 7cc2168b70..a0c2508b0d 100644 --- a/modules/mono/godotsharp_dirs.cpp +++ b/modules/mono/godotsharp_dirs.cpp @@ -57,7 +57,7 @@ String _get_expected_build_config() { String _get_mono_user_dir() { #ifdef TOOLS_ENABLED if (EditorSettings::get_singleton()) { - return EditorSettings::get_singleton()->get_settings_path().plus_file("mono"); + return EditorSettings::get_singleton()->get_data_dir().plus_file("mono"); } else { String settings_path; @@ -68,19 +68,13 @@ String _get_mono_user_dir() { // contain yourself settings_path = exe_dir.plus_file("editor_data"); } else { - if (OS::get_singleton()->has_environment("APPDATA")) { - String app_data = OS::get_singleton()->get_environment("APPDATA").replace("\\", "/"); - settings_path = app_data.plus_file(String(_MKSTR(VERSION_SHORT_NAME)).capitalize()); - } else if (OS::get_singleton()->has_environment("HOME")) { - String home = OS::get_singleton()->get_environment("HOME"); - settings_path = home.plus_file("." + String(_MKSTR(VERSION_SHORT_NAME)).to_lower()); - } + settings_path = OS::get_singleton()->get_data_path().plus_file(OS::get_singleton()->get_godot_dir_name()); } return settings_path.plus_file("mono"); } #else - return OS::get_singleton()->get_data_dir().plus_file("mono"); + return OS::get_singleton()->get_user_data_dir().plus_file("mono"); #endif } diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp index 1643f8cfc5..eb34f9dd3f 100644 --- a/modules/mono/mono_gd/gd_mono_field.cpp +++ b/modules/mono/mono_gd/gd_mono_field.cpp @@ -41,7 +41,7 @@ void GDMonoField::set_value_raw(MonoObject *p_object, void *p_ptr) { void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) { #define SET_FROM_STRUCT_AND_BREAK(m_type) \ { \ - const m_type &val = p_value.operator m_type(); \ + const m_type &val = p_value.operator ::m_type(); \ MARSHALLED_OUT(m_type, val, raw); \ mono_field_set_value(p_object, mono_field, raw); \ break; \ @@ -129,8 +129,8 @@ void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) { if (tclass == CACHED_CLASS(Transform)) SET_FROM_STRUCT_AND_BREAK(Transform); - if (tclass == CACHED_CLASS(Rect3)) - SET_FROM_STRUCT_AND_BREAK(Rect3); + if (tclass == CACHED_CLASS(AABB)) + SET_FROM_STRUCT_AND_BREAK(AABB); if (tclass == CACHED_CLASS(Color)) SET_FROM_STRUCT_AND_BREAK(Color); @@ -229,7 +229,7 @@ void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) { case Variant::TRANSFORM2D: SET_FROM_STRUCT_AND_BREAK(Transform2D); case Variant::PLANE: SET_FROM_STRUCT_AND_BREAK(Plane); case Variant::QUAT: SET_FROM_STRUCT_AND_BREAK(Quat); - case Variant::RECT3: SET_FROM_STRUCT_AND_BREAK(Rect3); + case Variant::AABB: SET_FROM_STRUCT_AND_BREAK(AABB); case Variant::BASIS: SET_FROM_STRUCT_AND_BREAK(Basis); case Variant::TRANSFORM: SET_FROM_STRUCT_AND_BREAK(Transform); case Variant::COLOR: SET_FROM_STRUCT_AND_BREAK(Color); diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 01392447f3..8bc2bb5096 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -36,7 +36,7 @@ namespace GDMonoMarshal { #define RETURN_BOXED_STRUCT(m_t, m_var_in) \ { \ - const m_t &m_in = m_var_in->operator m_t(); \ + const m_t &m_in = m_var_in->operator ::m_t(); \ MARSHALLED_OUT(m_t, m_in, raw); \ return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(m_t), raw); \ } @@ -104,8 +104,8 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type) { if (tclass == CACHED_CLASS(Transform)) return Variant::TRANSFORM; - if (tclass == CACHED_CLASS(Rect3)) - return Variant::RECT3; + if (tclass == CACHED_CLASS(AABB)) + return Variant::AABB; if (tclass == CACHED_CLASS(Color)) return Variant::COLOR; @@ -297,8 +297,8 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty if (tclass == CACHED_CLASS(Transform)) RETURN_BOXED_STRUCT(Transform, p_var); - if (tclass == CACHED_CLASS(Rect3)) - RETURN_BOXED_STRUCT(Rect3, p_var); + if (tclass == CACHED_CLASS(AABB)) + RETURN_BOXED_STRUCT(AABB, p_var); if (tclass == CACHED_CLASS(Color)) RETURN_BOXED_STRUCT(Color, p_var); @@ -394,8 +394,8 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty RETURN_BOXED_STRUCT(Plane, p_var); case Variant::QUAT: RETURN_BOXED_STRUCT(Quat, p_var); - case Variant::RECT3: - RETURN_BOXED_STRUCT(Rect3, p_var); + case Variant::AABB: + RETURN_BOXED_STRUCT(AABB, p_var); case Variant::BASIS: RETURN_BOXED_STRUCT(Basis, p_var); case Variant::TRANSFORM: @@ -518,8 +518,8 @@ Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) { if (tclass == CACHED_CLASS(Transform)) RETURN_UNBOXED_STRUCT(Transform, p_obj); - if (tclass == CACHED_CLASS(Rect3)) - RETURN_UNBOXED_STRUCT(Rect3, p_obj); + if (tclass == CACHED_CLASS(AABB)) + RETURN_UNBOXED_STRUCT(AABB, p_obj); if (tclass == CACHED_CLASS(Color)) RETURN_UNBOXED_STRUCT(Color, p_obj); diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h index 9f403b787f..443e947fb5 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.h +++ b/modules/mono/mono_gd/gd_mono_marshal.h @@ -197,10 +197,10 @@ Dictionary mono_object_to_Dictionary(MonoObject *p_dict); Basis(m_in[0], m_in[1], m_in[2], m_in[3], m_in[4], m_in[5], m_in[6], m_in[7], m_in[8]), \ Vector3(m_in[9], m_in[10], m_in[11])); -// Rect3 +// AABB -#define MARSHALLED_OUT_Rect3(m_in, m_out) real_t m_out[6] = { m_in.position.x, m_in.position.y, m_in.position.z, m_in.size.x, m_in.size.y, m_in.size.z }; -#define MARSHALLED_IN_Rect3(m_in, m_out) Rect3 m_out(Vector3(m_in[0], m_in[1], m_in[2]), Vector3(m_in[3], m_in[4], m_in[5])); +#define MARSHALLED_OUT_AABB(m_in, m_out) real_t m_out[6] = { m_in.position.x, m_in.position.y, m_in.position.z, m_in.size.x, m_in.size.y, m_in.size.z }; +#define MARSHALLED_IN_AABB(m_in, m_out) AABB m_out(Vector3(m_in[0], m_in[1], m_in[2]), Vector3(m_in[3], m_in[4], m_in[5])); // Color @@ -214,6 +214,6 @@ Dictionary mono_object_to_Dictionary(MonoObject *p_dict); #endif -} // GDMonoMarshal +} // namespace GDMonoMarshal #endif // GDMONOMARSHAL_H diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index 53e45002c4..1cccd0ad9d 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -80,7 +80,7 @@ void MonoCache::clear_members() { class_Basis = NULL; class_Quat = NULL; class_Transform = NULL; - class_Rect3 = NULL; + class_AABB = NULL; class_Color = NULL; class_Plane = NULL; class_NodePath = NULL; @@ -147,7 +147,7 @@ void update_godot_api_cache() { CACHE_CLASS_AND_CHECK(Basis, GODOT_API_CLASS(Basis)); CACHE_CLASS_AND_CHECK(Quat, GODOT_API_CLASS(Quat)); CACHE_CLASS_AND_CHECK(Transform, GODOT_API_CLASS(Transform)); - CACHE_CLASS_AND_CHECK(Rect3, GODOT_API_CLASS(Rect3)); + CACHE_CLASS_AND_CHECK(AABB, GODOT_API_CLASS(AABB)); CACHE_CLASS_AND_CHECK(Color, GODOT_API_CLASS(Color)); CACHE_CLASS_AND_CHECK(Plane, GODOT_API_CLASS(Plane)); CACHE_CLASS_AND_CHECK(NodePath, GODOT_API_CLASS(NodePath)); @@ -364,4 +364,4 @@ String get_exception_name_and_message(MonoObject *p_ex) { return res; } -} +} // namespace GDMonoUtils diff --git a/modules/mono/mono_gd/gd_mono_utils.h b/modules/mono/mono_gd/gd_mono_utils.h index ebb5d28e4d..c38f8c5af5 100644 --- a/modules/mono/mono_gd/gd_mono_utils.h +++ b/modules/mono/mono_gd/gd_mono_utils.h @@ -82,7 +82,7 @@ struct MonoCache { GDMonoClass *class_Basis; GDMonoClass *class_Quat; GDMonoClass *class_Transform; - GDMonoClass *class_Rect3; + GDMonoClass *class_AABB; GDMonoClass *class_Color; GDMonoClass *class_Plane; GDMonoClass *class_NodePath; @@ -166,7 +166,7 @@ MonoDomain *create_domain(const String &p_friendly_name); String get_exception_name_and_message(MonoObject *p_ex); -} // GDMonoUtils +} // namespace GDMonoUtils #define NATIVE_GDMONOCLASS_NAME(m_class) (GDMonoMarshal::mono_string_to_godot((MonoString *)m_class->get_field(BINDINGS_NATIVE_NAME_FIELD)->get_value(NULL))) diff --git a/modules/regex/doc_classes/RegExMatch.xml b/modules/regex/doc_classes/RegExMatch.xml index 354febf89a..8c6951fea2 100644 --- a/modules/regex/doc_classes/RegExMatch.xml +++ b/modules/regex/doc_classes/RegExMatch.xml @@ -4,7 +4,7 @@ Contains the results of a regex search. </brief_description> <description> - Contains the results of a single regex match returned by [method RegEx.search] and [method.RegEx.search_all]. It can be used to find the position and range of the match and its capturing groups, and it can extract its sub-string for you. + Contains the results of a single regex match returned by [method RegEx.search] and [method RegEx.search_all]. It can be used to find the position and range of the match and its capturing groups, and it can extract its sub-string for you. </description> <tutorials> </tutorials> diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml index 27231574d7..c45c8d2b64 100644 --- a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml +++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml @@ -151,68 +151,74 @@ <constant name="MATH_DB2LINEAR" value="39"> Convert the input from decibel volume to linear volume. </constant> - <constant name="MATH_WRAP" value="40"> + <constant name="MATH_POLAR2CARTESIAN" value="40"> + Converts a 2D point expressed in the polar coordinate system (a distance from the origin [code]r[/code] and an angle [code]th[/code]) to the cartesian coordinate system (x and y axis). </constant> - <constant name="MATH_WRAPF" value="41"> + <constant name="MATH_CARTESIAN2POLAR" value="41"> + Converts a 2D point expressed in the cartesian coordinate system (x and y axis) to the polar coordinate system (a distance from the origin and an angle). </constant> - <constant name="LOGIC_MAX" value="42"> + <constant name="MATH_WRAP" value="42"> + </constant> + <constant name="MATH_WRAPF" value="43"> + </constant> + <constant name="LOGIC_MAX" value="44"> Return the greater of the two numbers, also known as their maximum. </constant> - <constant name="LOGIC_MIN" value="43"> + <constant name="LOGIC_MIN" value="45"> Return the lesser of the two numbers, also known as their minimum. </constant> - <constant name="LOGIC_CLAMP" value="44"> + <constant name="LOGIC_CLAMP" value="46"> Return the input clamped inside the given range, ensuring the result is never outside it. Equivalent to `min(max(input, range_low), range_high)` </constant> - <constant name="LOGIC_NEAREST_PO2" value="45"> + <constant name="LOGIC_NEAREST_PO2" value="46"> Return the nearest power of 2 to the input. </constant> - <constant name="OBJ_WEAKREF" value="46"> + <constant name="OBJ_WEAKREF" value="47"> Create a [WeakRef] from the input. </constant> - <constant name="FUNC_FUNCREF" value="47"> + <constant name="FUNC_FUNCREF" value="48"> Create a [FuncRef] from the input. </constant> - <constant name="TYPE_CONVERT" value="48"> + <constant name="TYPE_CONVERT" value="49"> Convert between types. </constant> - <constant name="TYPE_OF" value="49"> + <constant name="TYPE_OF" value="50"> Return the type of the input as an integer. Check [enum Variant.Type] for the integers that might be returned. </constant> - <constant name="TYPE_EXISTS" value="50"> + <constant name="TYPE_EXISTS" value="51"> Checks if a type is registered in the [ClassDB]. </constant> - <constant name="TEXT_CHAR" value="51"> + <constant name="TEXT_CHAR" value="52"> Return a character with the given ascii value. </constant> - <constant name="TEXT_STR" value="52"> + <constant name="TEXT_STR" value="53"> Convert the input to a string. </constant> - <constant name="TEXT_PRINT" value="53"> + <constant name="TEXT_PRINT" value="54"> Print the given string to the output window. </constant> - <constant name="TEXT_PRINTERR" value="54"> + <constant name="TEXT_PRINTERR" value="55"> Print the given string to the standard error output. </constant> - <constant name="TEXT_PRINTRAW" value="55"> + <constant name="TEXT_PRINTRAW" value="56"> Print the given string to the standard output, without adding a newline. </constant> - <constant name="VAR_TO_STR" value="56"> + <constant name="VAR_TO_STR" value="57"> Serialize a [Variant] to a string. </constant> - <constant name="STR_TO_VAR" value="57"> + <constant name="STR_TO_VAR" value="58"> Deserialize a [Variant] from a string serialized using [VAR_TO_STR]. </constant> - <constant name="VAR_TO_BYTES" value="58"> + <constant name="VAR_TO_BYTES" value="59"> Serialize a [Variant] to a [PoolByteArray]. </constant> - <constant name="BYTES_TO_VAR" value="59"> + <constant name="BYTES_TO_VAR" value="60"> Deserialize a [Variant] from a [PoolByteArray] serialized using [VAR_TO_BYTES]. </constant> - <constant name="COLORN" value="60"> + <constant name="COLORN" value="61"> Return the [Color] with the given name and alpha ranging from 0 to 1. Note: names are defined in color_names.inc. </constant> - <constant name="FUNC_MAX" value="61"> + <constant name="FUNC_MAX" value="62"> The maximum value the [member function] property can have. </constant> </constants> diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp index 7c9d306831..32f7519125 100644 --- a/modules/visual_script/visual_script_builtin_funcs.cpp +++ b/modules/visual_script/visual_script_builtin_funcs.cpp @@ -78,6 +78,8 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX "rad2deg", "linear2db", "db2linear", + "polar2cartesian", + "cartesian2polar", "wrapi", "wrapf", "max", @@ -191,6 +193,8 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) { case MATH_EASE: case MATH_STEPIFY: case MATH_RANDOM: + case MATH_POLAR2CARTESIAN: + case MATH_CARTESIAN2POLAR: case LOGIC_MAX: case LOGIC_MIN: case FUNC_FUNCREF: @@ -368,6 +372,18 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const case MATH_DB2LINEAR: { return PropertyInfo(Variant::REAL, "db"); } break; + case MATH_POLAR2CARTESIAN: { + if (p_idx == 0) + return PropertyInfo(Variant::REAL, "r"); + else + return PropertyInfo(Variant::REAL, "th"); + } break; + case MATH_CARTESIAN2POLAR: { + if (p_idx == 0) + return PropertyInfo(Variant::REAL, "x"); + else + return PropertyInfo(Variant::REAL, "y"); + } break; case MATH_WRAP: { if (p_idx == 0) return PropertyInfo(Variant::INT, "value"); @@ -573,6 +589,10 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons case MATH_DB2LINEAR: { t = Variant::REAL; } break; + case MATH_POLAR2CARTESIAN: + case MATH_CARTESIAN2POLAR: { + t = Variant::VECTOR2; + } break; case MATH_WRAP: { t = Variant::INT; } break; @@ -922,6 +942,20 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in VALIDATE_ARG_NUM(0); *r_return = Math::db2linear((double)*p_inputs[0]); } break; + case VisualScriptBuiltinFunc::MATH_POLAR2CARTESIAN: { + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double r = *p_inputs[0]; + double th = *p_inputs[1]; + *r_return = Vector2(r * Math::cos(th), r * Math::sin(th)); + } break; + case VisualScriptBuiltinFunc::MATH_CARTESIAN2POLAR: { + VALIDATE_ARG_NUM(0); + VALIDATE_ARG_NUM(1); + double x = *p_inputs[0]; + double y = *p_inputs[1]; + *r_return = Vector2(Math::sqrt(x * x + y * y), Math::atan2(y, x)); + } break; case VisualScriptBuiltinFunc::MATH_WRAP: { VALIDATE_ARG_NUM(0); VALIDATE_ARG_NUM(1); @@ -1109,7 +1143,7 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in String str = *p_inputs[0]; //str+="\n"; - OS::get_singleton()->printerr("%s\n", str.utf8().get_data()); + print_error(str); } break; case VisualScriptBuiltinFunc::TEXT_PRINTRAW: { @@ -1294,6 +1328,8 @@ void VisualScriptBuiltinFunc::_bind_methods() { BIND_ENUM_CONSTANT(MATH_RAD2DEG); BIND_ENUM_CONSTANT(MATH_LINEAR2DB); BIND_ENUM_CONSTANT(MATH_DB2LINEAR); + BIND_ENUM_CONSTANT(MATH_POLAR2CARTESIAN); + BIND_ENUM_CONSTANT(MATH_CARTESIAN2POLAR); BIND_ENUM_CONSTANT(MATH_WRAP); BIND_ENUM_CONSTANT(MATH_WRAPF); BIND_ENUM_CONSTANT(LOGIC_MAX); @@ -1381,6 +1417,8 @@ void register_visual_script_builtin_func_node() { VisualScriptLanguage::singleton->add_register_func("functions/built_in/rad2deg", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_RAD2DEG>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/linear2db", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_LINEAR2DB>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/db2linear", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_DB2LINEAR>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/polar2cartesian", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_POLAR2CARTESIAN>); + VisualScriptLanguage::singleton->add_register_func("functions/built_in/cartesian2polar", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_CARTESIAN2POLAR>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapi", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAP>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/wrapf", create_builtin_func_node<VisualScriptBuiltinFunc::MATH_WRAPF>); diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 34a2825938..54dc997b38 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -77,6 +77,8 @@ public: MATH_RAD2DEG, MATH_LINEAR2DB, MATH_DB2LINEAR, + MATH_POLAR2CARTESIAN, + MATH_CARTESIAN2POLAR, MATH_WRAP, MATH_WRAPF, LOGIC_MAX, diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 86cf5b27e6..2318149ca5 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -349,7 +349,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { case Variant::TRANSFORM2D: color = Color::html("#c4ec69"); break; case Variant::PLANE: color = Color::html("#f77070"); break; case Variant::QUAT: color = Color::html("#ec69a3"); break; - case Variant::RECT3: color = Color::html("#ee7991"); break; + case Variant::AABB: color = Color::html("#ee7991"); break; case Variant::BASIS: color = Color::html("#e3ec69"); break; case Variant::TRANSFORM: color = Color::html("#f6a86e"); break; @@ -386,7 +386,7 @@ static Color _color_from_type(Variant::Type p_type, bool dark_theme = true) { case Variant::TRANSFORM2D: color = Color::html("#96ce1a"); break; case Variant::PLANE: color = Color::html("#f77070"); break; case Variant::QUAT: color = Color::html("#ec69a3"); break; - case Variant::RECT3: color = Color::html("#ee7991"); break; + case Variant::AABB: color = Color::html("#ee7991"); break; case Variant::BASIS: color = Color::html("#b2bb19"); break; case Variant::TRANSFORM: color = Color::html("#f49047"); break; @@ -1389,7 +1389,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "obj_property") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Getter. Hold Shift to drop a generic signature.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Getter. Hold Shift to drop a generic signature."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Getter. Hold Shift to drop a generic signature.")); #endif @@ -1398,7 +1398,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "nodes") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a simple reference to the node.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a simple reference to the node."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a simple reference to the node.")); #endif @@ -1407,7 +1407,7 @@ bool VisualScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant & if (String(d["type"]) == "visual_script_variable_drag") { #ifdef OSX_ENABLED - const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Meta to drop a Variable Setter.")); + const_cast<VisualScriptEditor *>(this)->_show_hint(vformat(TTR("Hold %s to drop a Variable Setter."), find_keycode_name(KEY_META))); #else const_cast<VisualScriptEditor *>(this)->_show_hint(TTR("Hold Ctrl to drop a Variable Setter.")); #endif diff --git a/modules/webm/config.py b/modules/webm/config.py index 0374bb36f7..dcae4447d5 100644 --- a/modules/webm/config.py +++ b/modules/webm/config.py @@ -1,5 +1,5 @@ def can_build(platform): - return True + return platform != 'iphone' def configure(env): pass |