diff options
Diffstat (limited to 'modules')
216 files changed, 7909 insertions, 2984 deletions
diff --git a/modules/SCsub b/modules/SCsub index d1c0cdc05c..c1cf5a6c1a 100644 --- a/modules/SCsub +++ b/modules/SCsub @@ -9,7 +9,6 @@ Export('env_modules') env.modules_sources = [ "register_module_types.gen.cpp", ] -# env.add_source_files(env.modules_sources,"*.cpp") Export('env') for x in env.module_list: diff --git a/modules/bullet/config.py b/modules/bullet/config.py index b00ea18328..0a31c2e503 100644 --- a/modules/bullet/config.py +++ b/modules/bullet/config.py @@ -3,4 +3,12 @@ def can_build(platform): def configure(env): pass - + +def get_doc_classes(): + return [ + "BulletPhysicsDirectBodyState", + "BulletPhysicsServer", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/bullet/doc_classes/BulletPhysicsDirectBodyState.xml b/modules/bullet/doc_classes/BulletPhysicsDirectBodyState.xml new file mode 100644 index 0000000000..831b346942 --- /dev/null +++ b/modules/bullet/doc_classes/BulletPhysicsDirectBodyState.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="BulletPhysicsDirectBodyState" inherits="PhysicsDirectBodyState" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/bullet/doc_classes/BulletPhysicsServer.xml b/modules/bullet/doc_classes/BulletPhysicsServer.xml new file mode 100644 index 0000000000..4b5c2e6d83 --- /dev/null +++ b/modules/bullet/doc_classes/BulletPhysicsServer.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="BulletPhysicsServer" inherits="PhysicsServer" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> 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..853906063b 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -115,12 +115,13 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra 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); @@ -147,12 +148,13 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra 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) { 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); @@ -174,16 +176,18 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf 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); @@ -197,12 +201,13 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & 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); @@ -231,12 +236,13 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh 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); @@ -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..9acac9a7d6 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -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/dds/config.py b/modules/dds/config.py index fb920482f5..5f133eba90 100644 --- a/modules/dds/config.py +++ b/modules/dds/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/enet/config.py b/modules/enet/config.py index fb920482f5..8031fbb4b6 100644 --- a/modules/enet/config.py +++ b/modules/enet/config.py @@ -1,7 +1,13 @@ - def can_build(platform): return True - def configure(env): pass + +def get_doc_classes(): + return [ + "NetworkedMultiplayerENet", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml new file mode 100644 index 0000000000..70ef6aef20 --- /dev/null +++ b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="NetworkedMultiplayerENet" inherits="NetworkedMultiplayerPeer" category="Core" version="3.0-alpha"> + <brief_description> + PacketPeer implementation using the ENet library. + </brief_description> + <description> + A connection (or a listening server) that should be passed to [method SceneTree.set_network_peer]. Socket events can be handled by connecting to [SceneTree] signals. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="close_connection"> + <return type="void"> + </return> + <description> + </description> + </method> + <method name="create_client"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="ip" type="String"> + </argument> + <argument index="1" name="port" type="int"> + </argument> + <argument index="2" name="in_bandwidth" type="int" default="0"> + </argument> + <argument index="3" name="out_bandwidth" type="int" default="0"> + </argument> + <description> + Create client that connects to a server at address [code]ip[/code] using specified [code]port[/code]. + </description> + </method> + <method name="create_server"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="port" type="int"> + </argument> + <argument index="1" name="max_clients" type="int" default="32"> + </argument> + <argument index="2" name="in_bandwidth" type="int" default="0"> + </argument> + <argument index="3" name="out_bandwidth" type="int" default="0"> + </argument> + <description> + Create server that listens to connections via [code]port[/code]. + </description> + </method> + <method name="get_compression_mode" qualifiers="const"> + <return type="int" enum="NetworkedMultiplayerENet.CompressionMode"> + </return> + <description> + </description> + </method> + <method name="set_bind_ip"> + <return type="void"> + </return> + <argument index="0" name="ip" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_compression_mode"> + <return type="void"> + </return> + <argument index="0" name="mode" type="int" enum="NetworkedMultiplayerENet.CompressionMode"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + <constant name="COMPRESS_NONE" value="0"> + </constant> + <constant name="COMPRESS_RANGE_CODER" value="1"> + </constant> + <constant name="COMPRESS_FASTLZ" value="2"> + </constant> + <constant name="COMPRESS_ZLIB" value="3"> + </constant> + <constant name="COMPRESS_ZSTD" value="4"> + </constant> + </constants> +</class> 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/config.py b/modules/etc/config.py index 7dc2cb59c1..395fc1bb02 100644 --- a/modules/etc/config.py +++ b/modules/etc/config.py @@ -1,8 +1,6 @@ - def can_build(platform): return True - def configure(env): # Tools only, disabled for non-tools # TODO: Find a cleaner way to achieve that 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/freetype/config.py b/modules/freetype/config.py index fb920482f5..5f133eba90 100644 --- a/modules/freetype/config.py +++ b/modules/freetype/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/gdnative/SCsub b/modules/gdnative/SCsub index 88588417d1..54d0672a5b 100644 --- a/modules/gdnative/SCsub +++ b/modules/gdnative/SCsub @@ -19,6 +19,28 @@ def _spaced(e): return e if e[-1] == '*' else e + ' ' def _build_gdnative_api_struct_header(api): + gdnative_api_init_macro = [ + '\textern const godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct;' + ] + + for name in api['extensions']: + gdnative_api_init_macro.append( + '\textern const godot_gdnative_ext_{0}_api_struct *_gdnative_wrapper_{0}_api_struct;'.format(name)) + + 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']: + 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 */', '#ifndef GODOT_GDNATIVE_API_STRUCT_H', @@ -29,23 +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; _gdnative_wrapper_api_struct = options->api_struct; } 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 {', - '\tunsigned int type;', - '\tgodot_gdnative_api_version version;', - '\tconst godot_gdnative_api_struct *next;', - '} godot_gdnative_api_struct;', - '', 'enum GDNATIVE_API_TYPES {', '\tGDNATIVE_' + api['core']['type'] + ',' ] @@ -164,18 +175,23 @@ def _build_gdnative_wrapper_code(api): '#include <gdnative/gdnative.h>', '#include <nativescript/godot_nativescript.h>', '#include <pluginscript/godot_pluginscript.h>', + '#include <arvr/godot_arvr.h>', '', '#include <gdnative_api_struct.gen.h>', '', - 'godot_gdnative_api_struct *_gdnative_wrapper_api_struct = 0;', - '', '#ifdef __cplusplus', 'extern "C" {', '#endif', - '' + '', + 'godot_gdnative_core_api_struct *_gdnative_wrapper_api_struct = 0;', ] - for funcdef in api['api']: + for name in api['extensions']: + out.append('godot_gdnative_ext_' + name + '_api_struct *_gdnative_wrapper_' + name + '_api_struct = 0;') + + out += [''] + + for funcdef in api['core']['api']: args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']]) out.append('%s%s(%s) {' % (_spaced(funcdef['return_type']), funcdef['name'], args)) @@ -188,6 +204,20 @@ def _build_gdnative_wrapper_code(api): out.append('}') out.append('') + for name in api['extensions']: + for funcdef in api['extensions'][name]['api']: + args = ', '.join(['%s%s' % (_spaced(t), n) for t, n in funcdef['arguments']]) + out.append('%s%s(%s) {' % (_spaced(funcdef['return_type']), funcdef['name'], args)) + + args = ', '.join(['%s' % n for t, n in funcdef['arguments']]) + + return_line = '\treturn ' if funcdef['return_type'] != 'void' else '\t' + return_line += '_gdnative_wrapper_' + name + '_api_struct->' + funcdef['name'] + '(' + args + ');' + + out.append(return_line) + out.append('}') + out.append('') + out += [ '#ifdef __cplusplus', '}', diff --git a/modules/gdnative/arvr/arvr_interface_gdnative.cpp b/modules/gdnative/arvr/arvr_interface_gdnative.cpp index e2a7019fa4..02f2ee7424 100644 --- a/modules/gdnative/arvr/arvr_interface_gdnative.cpp +++ b/modules/gdnative/arvr/arvr_interface_gdnative.cpp @@ -166,11 +166,11 @@ void ARVRInterfaceGDNative::uninitialize() { interface->uninitialize(data); } -Size2 ARVRInterfaceGDNative::get_recommended_render_targetsize() { +Size2 ARVRInterfaceGDNative::get_render_targetsize() { ERR_FAIL_COND_V(interface == NULL, Size2()); - godot_vector2 result = interface->get_recommended_render_targetsize(data); + godot_vector2 result = interface->get_render_targetsize(data); Vector2 *vec = (Vector2 *)&result; return *vec; diff --git a/modules/gdnative/arvr/arvr_interface_gdnative.h b/modules/gdnative/arvr/arvr_interface_gdnative.h index e45b51e070..96f7b580d5 100644 --- a/modules/gdnative/arvr/arvr_interface_gdnative.h +++ b/modules/gdnative/arvr/arvr_interface_gdnative.h @@ -68,7 +68,7 @@ public: virtual void set_anchor_detection_is_enabled(bool p_enable); /** rendering and internal **/ - virtual Size2 get_recommended_render_targetsize(); + virtual Size2 get_render_targetsize(); virtual bool is_stereo(); virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform); diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py index df3556249d..68148c4d87 100644 --- a/modules/gdnative/config.py +++ b/modules/gdnative/config.py @@ -1,4 +1,3 @@ - def can_build(platform): return True @@ -6,7 +5,13 @@ def configure(env): env.use_ptrcall = True def get_doc_classes(): - return ["GDNative", "GDNativeLibrary", "NativeScript", "ARVRInterfaceGDNative"] + return [ + "ARVRInterfaceGDNative", + "GDNative", + "GDNativeLibrary", + "NativeScript", + "PluginScript", + ] def get_doc_path(): - return "doc_classes" + return "doc_classes" diff --git a/modules/gdnative/doc_classes/ARVRInterfaceGDNative.xml b/modules/gdnative/doc_classes/ARVRInterfaceGDNative.xml index 308a7d5946..10957a3394 100644 --- a/modules/gdnative/doc_classes/ARVRInterfaceGDNative.xml +++ b/modules/gdnative/doc_classes/ARVRInterfaceGDNative.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="ARVRInterfaceGDNative" inherits="ARVRInterface" category="Core" version="3.0.alpha.custom_build"> +<class name="ARVRInterfaceGDNative" inherits="ARVRInterface" category="Core" version="3.0-alpha"> <brief_description> GDNative wrapper for an ARVR interface </brief_description> diff --git a/modules/gdnative/doc_classes/GDNative.xml b/modules/gdnative/doc_classes/GDNative.xml index 83a1cf06f0..7a36d09aec 100644 --- a/modules/gdnative/doc_classes/GDNative.xml +++ b/modules/gdnative/doc_classes/GDNative.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="GDNative" inherits="Reference" category="Core" version="3.0.alpha.custom_build"> +<class name="GDNative" inherits="Reference" category="Core" version="3.0-alpha"> <brief_description> </brief_description> <description> diff --git a/modules/gdnative/doc_classes/GDNativeLibrary.xml b/modules/gdnative/doc_classes/GDNativeLibrary.xml index 361c89e6b3..e271665fd4 100644 --- a/modules/gdnative/doc_classes/GDNativeLibrary.xml +++ b/modules/gdnative/doc_classes/GDNativeLibrary.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="GDNativeLibrary" inherits="Resource" category="Core" version="3.0.alpha.custom_build"> +<class name="GDNativeLibrary" inherits="Resource" category="Core" version="3.0-alpha"> <brief_description> </brief_description> <description> @@ -9,37 +9,51 @@ <demos> </demos> <methods> - <method name="get_active_library_path" qualifiers="const"> + <method name="get_config_file"> + <return type="ConfigFile"> + </return> + <description> + </description> + </method> + <method name="get_current_dependencies" qualifiers="const"> + <return type="PoolStringArray"> + </return> + <description> + </description> + </method> + <method name="get_current_library_path" qualifiers="const"> <return type="String"> </return> <description> </description> </method> - <method name="get_library_path" qualifiers="const"> + <method name="get_symbol_prefix" qualifiers="const"> <return type="String"> </return> - <argument index="0" name="platform" type="String"> - </argument> <description> </description> </method> - <method name="is_singleton_gdnative" qualifiers="const"> + <method name="is_current_library_statically_linked" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="is_singleton" qualifiers="const"> <return type="bool"> </return> <description> </description> </method> - <method name="set_library_path"> + <method name="set_load_once"> <return type="void"> </return> - <argument index="0" name="platform" type="String"> - </argument> - <argument index="1" name="path" type="String"> + <argument index="0" name="load_once" type="bool"> </argument> <description> </description> </method> - <method name="set_singleton_gdnative"> + <method name="set_singleton"> <return type="void"> </return> <argument index="0" name="singleton" type="bool"> @@ -47,9 +61,27 @@ <description> </description> </method> + <method name="set_symbol_prefix"> + <return type="void"> + </return> + <argument index="0" name="symbol_prefix" type="String"> + </argument> + <description> + </description> + </method> + <method name="should_load_once" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> </methods> <members> - <member name="singleton_gdnative" type="bool" setter="set_singleton_gdnative" getter="is_singleton_gdnative"> + <member name="load_once" type="bool" setter="set_load_once" getter="should_load_once"> + </member> + <member name="singleton" type="bool" setter="set_singleton" getter="is_singleton"> + </member> + <member name="symbol_prefix" type="String" setter="set_symbol_prefix" getter="get_symbol_prefix"> </member> </members> <constants> diff --git a/modules/gdnative/doc_classes/NativeScript.xml b/modules/gdnative/doc_classes/NativeScript.xml index b040cfd966..eb4e13f748 100644 --- a/modules/gdnative/doc_classes/NativeScript.xml +++ b/modules/gdnative/doc_classes/NativeScript.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="NativeScript" inherits="Script" category="Core" version="3.0.alpha.custom_build"> +<class name="NativeScript" inherits="Script" category="Core" version="3.0-alpha"> <brief_description> </brief_description> <description> diff --git a/modules/gdnative/doc_classes/PluginScript.xml b/modules/gdnative/doc_classes/PluginScript.xml new file mode 100644 index 0000000000..a5ab422d3c --- /dev/null +++ b/modules/gdnative/doc_classes/PluginScript.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="PluginScript" inherits="Script" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/gdnative/gd_native_library_editor.cpp b/modules/gdnative/gd_native_library_editor.cpp index c37b7f473d..fda5dcdcad 100644 --- a/modules/gdnative/gd_native_library_editor.cpp +++ b/modules/gdnative/gd_native_library_editor.cpp @@ -44,7 +44,7 @@ void GDNativeLibraryEditor::_find_gdnative_singletons(EditorFileSystemDirectory } Ref<GDNativeLibrary> lib = ResourceLoader::load(p_dir->get_file_path(i)); - if (lib.is_valid() && lib->is_singleton_gdnative()) { + if (lib.is_valid() && lib->is_singleton()) { String path = p_dir->get_file_path(i); TreeItem *ti = libraries->create_item(libraries->get_root()); ti->set_text(0, path.get_file()); diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 832a0cb859..0132ef3c5d 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -37,161 +37,55 @@ #include "scene/main/scene_tree.h" -const String init_symbol = "godot_gdnative_init"; -const String terminate_symbol = "godot_gdnative_terminate"; +const String init_symbol = "gdnative_init"; +const String terminate_symbol = "gdnative_terminate"; +const String default_symbol_prefix = "godot_"; // Defined in gdnative_api_struct.gen.cpp extern const godot_gdnative_core_api_struct api_struct; -String GDNativeLibrary::platform_names[NUM_PLATFORMS + 1] = { - "X11_32bit", - "X11_64bit", - "Windows_32bit", - "Windows_64bit", - "OSX", +Map<String, Vector<Ref<GDNative> > > *GDNativeLibrary::loaded_libraries = NULL; - "Android", +GDNativeLibrary::GDNativeLibrary() { + config_file.instance(); - "iOS_32bit", - "iOS_64bit", + symbol_prefix = default_symbol_prefix; - "WebAssembly", - - "" -}; -String GDNativeLibrary::platform_lib_ext[NUM_PLATFORMS + 1] = { - "so", - "so", - "dll", - "dll", - "dylib", - - "so", - - "dylib", - "dylib", - - "wasm", - - "" -}; - -GDNativeLibrary::Platform GDNativeLibrary::current_platform = -#if defined(X11_ENABLED) - (sizeof(void *) == 8 ? X11_64BIT : X11_32BIT); -#elif defined(WINDOWS_ENABLED) - (sizeof(void *) == 8 ? WINDOWS_64BIT : WINDOWS_32BIT); -#elif defined(OSX_ENABLED) - OSX; -#elif defined(IPHONE_ENABLED) - (sizeof(void *) == 8 ? IOS_64BIT : IOS_32BIT); -#elif defined(ANDROID_ENABLED) - ANDROID; -#elif defined(JAVASCRIPT_ENABLED) - WASM; -#else - NUM_PLATFORMS; -#endif - -GDNativeLibrary::GDNativeLibrary() - : library_paths(), singleton_gdnative(false) { + if (GDNativeLibrary::loaded_libraries == NULL) { + GDNativeLibrary::loaded_libraries = memnew((Map<String, Vector<Ref<GDNative> > >)); + } } GDNativeLibrary::~GDNativeLibrary() { } void GDNativeLibrary::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_library_path", "platform", "path"), &GDNativeLibrary::set_library_path); - ClassDB::bind_method(D_METHOD("get_library_path", "platform"), &GDNativeLibrary::get_library_path); - ClassDB::bind_method(D_METHOD("get_active_library_path"), &GDNativeLibrary::get_active_library_path); - - ClassDB::bind_method(D_METHOD("is_singleton_gdnative"), &GDNativeLibrary::is_singleton_gdnative); - ClassDB::bind_method(D_METHOD("set_singleton_gdnative", "singleton"), &GDNativeLibrary::set_singleton_gdnative); - - ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "singleton_gdnative"), "set_singleton_gdnative", "is_singleton_gdnative"); -} + ClassDB::bind_method(D_METHOD("get_config_file"), &GDNativeLibrary::get_config_file); -bool GDNativeLibrary::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; - if (name.begins_with("platform/")) { - set_library_path(name.get_slice("/", 1), p_value); - return true; - } - return false; -} - -bool GDNativeLibrary::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; - if (name.begins_with("platform/")) { - r_ret = get_library_path(name.get_slice("/", 1)); - return true; - } - return false; -} + 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); -void GDNativeLibrary::_get_property_list(List<PropertyInfo> *p_list) const { - for (int i = 0; i < NUM_PLATFORMS; i++) { - p_list->push_back(PropertyInfo(Variant::STRING, - "platform/" + platform_names[i], - PROPERTY_HINT_FILE, - "*." + platform_lib_ext[i])); - } -} + ClassDB::bind_method(D_METHOD("should_load_once"), &GDNativeLibrary::should_load_once); + ClassDB::bind_method(D_METHOD("is_singleton"), &GDNativeLibrary::is_singleton); + ClassDB::bind_method(D_METHOD("get_symbol_prefix"), &GDNativeLibrary::get_symbol_prefix); -void GDNativeLibrary::set_library_path(StringName p_platform, String p_path) { - int i; - for (i = 0; i <= NUM_PLATFORMS; i++) { - if (i == NUM_PLATFORMS) break; - if (platform_names[i] == p_platform) { - break; - } - } - - if (i == NUM_PLATFORMS) { - ERR_EXPLAIN(String("No such platform: ") + p_platform); - ERR_FAIL(); - } + ClassDB::bind_method(D_METHOD("set_load_once", "load_once"), &GDNativeLibrary::set_load_once); + ClassDB::bind_method(D_METHOD("set_singleton", "singleton"), &GDNativeLibrary::set_singleton); + ClassDB::bind_method(D_METHOD("set_symbol_prefix", "symbol_prefix"), &GDNativeLibrary::set_symbol_prefix); - library_paths[i] = p_path; -} - -String GDNativeLibrary::get_library_path(StringName p_platform) const { - int i; - for (i = 0; i <= NUM_PLATFORMS; i++) { - if (i == NUM_PLATFORMS) break; - if (platform_names[i] == p_platform) { - break; - } - } - - if (i == NUM_PLATFORMS) { - ERR_EXPLAIN(String("No such platform: ") + p_platform); - ERR_FAIL_V(""); - } - - return library_paths[i]; -} - -String GDNativeLibrary::get_active_library_path() const { - if (GDNativeLibrary::current_platform != NUM_PLATFORMS) { - return library_paths[GDNativeLibrary::current_platform]; - } - return ""; + ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "load_once"), "set_load_once", "should_load_once"); + ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "singleton"), "set_singleton", "is_singleton"); + ADD_PROPERTYNZ(PropertyInfo(Variant::STRING, "symbol_prefix"), "set_symbol_prefix", "get_symbol_prefix"); } GDNative::GDNative() { native_handle = NULL; + initialized = false; } GDNative::~GDNative() { } -extern "C" void _api_anchor(); - -void GDNative::_compile_dummy_for_api() { - _api_anchor(); -} - void GDNative::_bind_methods() { ClassDB::bind_method(D_METHOD("set_library", "library"), &GDNative::set_library); ClassDB::bind_method(D_METHOD("get_library"), &GDNative::get_library); @@ -214,29 +108,55 @@ 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"); return false; } - String lib_path = library->get_active_library_path(); + String lib_path = library->get_current_library_path(); 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 + + if (library->should_load_once()) { + if (GDNativeLibrary::loaded_libraries->has(lib_path)) { + // already loaded. Don't load again. + // copy some of the stuff instead + this->native_handle = (*GDNativeLibrary::loaded_libraries)[lib_path][0]->native_handle; + initialized = true; + return true; + } + } + Error err = OS::get_singleton()->open_dynamic_library(path, native_handle); if (err != OK) { return false; } void *library_init; - err = get_symbol(init_symbol, library_init); + + // we cheat here a little bit. you saw nothing + initialized = true; + + err = get_symbol(library->get_symbol_prefix() + init_symbol, library_init, false); + + initialized = false; if (err || !library_init) { OS::get_singleton()->close_dynamic_library(native_handle); @@ -255,23 +175,49 @@ 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; library_init_fpointer(&options); + initialized = true; + + if (library->should_load_once() && !GDNativeLibrary::loaded_libraries->has(lib_path)) { + Vector<Ref<GDNative> > gdnatives; + gdnatives.resize(1); + gdnatives[0] = Ref<GDNative>(this); + GDNativeLibrary::loaded_libraries->insert(lib_path, gdnatives); + } + return true; } bool GDNative::terminate() { - if (native_handle == NULL) { + if (!initialized) { ERR_PRINT("No valid library handle, can't terminate GDNative object"); return false; } + if (library->should_load_once()) { + Vector<Ref<GDNative> > *gdnatives = &(*GDNativeLibrary::loaded_libraries)[library->get_current_library_path()]; + if (gdnatives->size() > 1) { + // there are other GDNative's still using this library, so we actually don't terminte + gdnatives->erase(Ref<GDNative>(this)); + initialized = false; + return true; + } else if (gdnatives->size() == 1) { + // we're the last one, terminate! + gdnatives->clear(); + // wew this looks scary, but all it does is remove the entry completely + GDNativeLibrary::loaded_libraries->erase(GDNativeLibrary::loaded_libraries->find(library->get_current_library_path())); + } + } + void *library_terminate; - Error error = get_symbol(terminate_symbol, library_terminate); + Error error = get_symbol(library->get_symbol_prefix() + terminate_symbol, library_terminate); if (error || !library_terminate) { OS::get_singleton()->close_dynamic_library(native_handle); native_handle = NULL; @@ -281,13 +227,13 @@ bool GDNative::terminate() { godot_gdnative_terminate_fn library_terminate_pointer; library_terminate_pointer = (godot_gdnative_terminate_fn)library_terminate; - // TODO(karroffel): remove this? Should be part of NativeScript, not - // GDNative IMO godot_gdnative_terminate_options options; options.in_editor = Engine::get_singleton()->is_editor_hint(); library_terminate_pointer(&options); + initialized = false; + // GDNativeScriptLanguage::get_singleton()->initialized_libraries.erase(p_native_lib->path); OS::get_singleton()->close_dynamic_library(native_handle); @@ -297,7 +243,7 @@ bool GDNative::terminate() { } bool GDNative::is_initialized() { - return (native_handle != NULL); + return initialized; } void GDNativeCallRegistry::register_native_call_type(StringName p_call_type, native_call_cb p_callback) { @@ -340,9 +286,9 @@ 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 (native_handle == NULL) { + if (!initialized) { ERR_PRINT("No valid library handle, can't get symbol from GDNative object"); return ERR_CANT_OPEN; } @@ -351,7 +297,131 @@ Error GDNative::get_symbol(StringName p_procedure_name, void *&r_handle) { native_handle, p_procedure_name, r_handle, - true); + p_optional); return result; } + +RES GDNativeLibraryResourceLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { + Ref<GDNativeLibrary> lib; + lib.instance(); + + Ref<ConfigFile> config = lib->get_config_file(); + + Error err = config->load(p_path); + + if (r_error) { + *r_error = err; + } + + lib->set_singleton(config->get_value("general", "singleton", false)); + lib->set_load_once(config->get_value("general", "load_once", true)); + lib->set_symbol_prefix(config->get_value("general", "symbol_prefix", default_symbol_prefix)); + + String entry_lib_path; + { + + List<String> entry_keys; + config->get_section_keys("entry", &entry_keys); + + for (List<String>::Element *E = entry_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; + } + + entry_lib_path = config->get_value("entry", key); + break; + } + } + + Vector<String> dependency_paths; + { + + List<String> dependency_keys; + config->get_section_keys("dependencies", &dependency_keys); + + for (List<String>::Element *E = dependency_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; + } + + dependency_paths = config->get_value("dependencies", key); + break; + } + } + + lib->current_library_path = entry_lib_path; + lib->current_dependencies = dependency_paths; + + return lib; +} + +void GDNativeLibraryResourceLoader::get_recognized_extensions(List<String> *p_extensions) const { + p_extensions->push_back("gdnlib"); +} + +bool GDNativeLibraryResourceLoader::handles_type(const String &p_type) const { + return p_type == "GDNativeLibrary"; +} + +String GDNativeLibraryResourceLoader::get_resource_type(const String &p_path) const { + String el = p_path.get_extension().to_lower(); + if (el == "gdnlib") + return "GDNativeLibrary"; + return ""; +} + +Error GDNativeLibraryResourceSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { + + Ref<GDNativeLibrary> lib = p_resource; + + if (lib.is_null()) { + return ERR_INVALID_DATA; + } + + Ref<ConfigFile> config = lib->get_config_file(); + + config->set_value("general", "singleton", lib->is_singleton()); + config->set_value("general", "load_once", lib->should_load_once()); + config->set_value("general", "symbol_prefix", lib->get_symbol_prefix()); + + return config->save(p_path); +} + +bool GDNativeLibraryResourceSaver::recognize(const RES &p_resource) const { + return Object::cast_to<GDNativeLibrary>(*p_resource) != NULL; +} + +void GDNativeLibraryResourceSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { + if (Object::cast_to<GDNativeLibrary>(*p_resource) != NULL) { + p_extensions->push_back("gdnlib"); + } +} diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index e44cc55a79..bb260bdd1b 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -38,74 +38,71 @@ #include "gdnative/gdnative.h" #include "gdnative_api_struct.gen.h" -class GDNativeLibrary : public Resource { - GDCLASS(GDNativeLibrary, Resource) - - enum Platform { - X11_32BIT, - X11_64BIT, - WINDOWS_32BIT, - WINDOWS_64BIT, - // NOTE(karroffel): I heard OSX 32 bit is dead, so 64 only - OSX, - - // Android .so files must be located in directories corresponding to Android ABI names: - // https://developer.android.com/ndk/guides/abis.html - // Android runtime will select the matching library depending on the device. - // The value here must simply point to the .so name, for example: - // "res://libmy_gdnative.so" or "libmy_gdnative.so", - // while in the project the actual paths can be "lib/android/armeabi-v7a/libmy_gdnative.so", - // "lib/android/arm64-v8a/libmy_gdnative.so". - ANDROID, - - IOS_32BIT, - IOS_64BIT, - - // TODO(karroffel): figure out how to deal with web stuff at all... - WASM, - - // TODO(karroffel): does UWP have different libs?? - // UWP, +#include "io/config_file.h" - NUM_PLATFORMS +class GDNativeLibraryResourceLoader; +class GDNative; - }; +class GDNativeLibrary : public Resource { + GDCLASS(GDNativeLibrary, Resource) - static String platform_names[NUM_PLATFORMS + 1]; - static String platform_lib_ext[NUM_PLATFORMS + 1]; + static Map<String, Vector<Ref<GDNative> > > *loaded_libraries; - static Platform current_platform; + friend class GDNativeLibraryResourceLoader; + friend class GDNative; - String library_paths[NUM_PLATFORMS]; + Ref<ConfigFile> config_file; - bool singleton_gdnative; + String current_library_path; + Vector<String> current_dependencies; -protected: - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List<PropertyInfo> *p_list) const; + bool singleton; + bool load_once; + String symbol_prefix; public: GDNativeLibrary(); ~GDNativeLibrary(); - static void _bind_methods(); + _FORCE_INLINE_ Ref<ConfigFile> get_config_file() { return config_file; } - void set_library_path(StringName p_platform, String p_path); - String get_library_path(StringName p_platform) const; + // things that change per-platform + // so there are no setters for this + _FORCE_INLINE_ String get_current_library_path() const { + return current_library_path; + } + _FORCE_INLINE_ Vector<String> get_current_dependencies() const { + return current_dependencies; + } + + // things that are a property of the library itself, not platform specific + _FORCE_INLINE_ bool should_load_once() const { + return load_once; + } + _FORCE_INLINE_ bool is_singleton() const { + return singleton; + } + _FORCE_INLINE_ String get_symbol_prefix() const { + return symbol_prefix; + } - String get_active_library_path() const; + _FORCE_INLINE_ void set_load_once(bool p_load_once) { + load_once = p_load_once; + } + _FORCE_INLINE_ void set_singleton(bool p_singleton) { + singleton = p_singleton; + } + _FORCE_INLINE_ void set_symbol_prefix(String p_symbol_prefix) { + symbol_prefix = p_symbol_prefix; + } - _FORCE_INLINE_ bool is_singleton_gdnative() const { return singleton_gdnative; } - _FORCE_INLINE_ void set_singleton_gdnative(bool p_singleton) { singleton_gdnative = p_singleton; } + 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; } @@ -124,10 +121,9 @@ class GDNative : public Reference { Ref<GDNativeLibrary> library; - // TODO(karroffel): different platforms? WASM???? void *native_handle; - void _compile_dummy_for_api(); + bool initialized; public: GDNative(); @@ -145,7 +141,22 @@ 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 { +public: + virtual RES load(const String &p_path, const String &p_original_path, Error *r_error); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual bool handles_type(const String &p_type) const; + virtual String get_resource_type(const String &p_path) const; +}; + +class GDNativeLibraryResourceSaver : public ResourceFormatSaver { +public: + virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags); + virtual bool recognize(const RES &p_resource) const; + virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const; }; #endif // GDNATIVE_H 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 90bc4dc031..8351c43574 100644 --- a/modules/gdnative/gdnative/array.cpp +++ b/modules/gdnative/gdnative/array.cpp @@ -41,9 +41,6 @@ extern "C" { #endif -void _array_api_anchor() { -} - void GDAPI godot_array_new(godot_array *r_dest) { Array *dest = (Array *)r_dest; memnew_placement(dest, Array); @@ -305,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/basis.cpp b/modules/gdnative/gdnative/basis.cpp index 28af93f942..39ca754dc7 100644 --- a/modules/gdnative/gdnative/basis.cpp +++ b/modules/gdnative/gdnative/basis.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _basis_api_anchor() {} - void GDAPI godot_basis_new_with_rows(godot_basis *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis) { const Vector3 *x_axis = (const Vector3 *)p_x_axis; const Vector3 *y_axis = (const Vector3 *)p_y_axis; diff --git a/modules/gdnative/gdnative/color.cpp b/modules/gdnative/gdnative/color.cpp index 2a5c0887a1..281a4c416f 100644 --- a/modules/gdnative/gdnative/color.cpp +++ b/modules/gdnative/gdnative/color.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _color_api_anchor() {} - void GDAPI godot_color_new_rgba(godot_color *r_dest, const godot_real p_r, const godot_real p_g, const godot_real p_b, const godot_real p_a) { Color *dest = (Color *)r_dest; diff --git a/modules/gdnative/gdnative/dictionary.cpp b/modules/gdnative/gdnative/dictionary.cpp index 7f8320622d..8363416946 100644 --- a/modules/gdnative/gdnative/dictionary.cpp +++ b/modules/gdnative/gdnative/dictionary.cpp @@ -38,8 +38,6 @@ extern "C" { #endif -void _dictionary_api_anchor() {} - void GDAPI godot_dictionary_new(godot_dictionary *r_dest) { Dictionary *dest = (Dictionary *)r_dest; memnew_placement(dest, Dictionary); diff --git a/modules/gdnative/gdnative/gdnative.cpp b/modules/gdnative/gdnative/gdnative.cpp index 64a7c33cf8..92a88e354b 100644 --- a/modules/gdnative/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative/gdnative.cpp @@ -30,57 +30,18 @@ #include "gdnative/gdnative.h" #include "class_db.h" +#include "engine.h" #include "error_macros.h" #include "global_constants.h" #include "os/os.h" -#include "project_settings.h" #include "variant.h" +#include "modules/gdnative/gdnative.h" + #ifdef __cplusplus extern "C" { #endif -extern "C" void _string_api_anchor(); -extern "C" void _string_name_api_anchor(); -extern "C" void _vector2_api_anchor(); -extern "C" void _rect2_api_anchor(); -extern "C" void _vector3_api_anchor(); -extern "C" void _transform2d_api_anchor(); -extern "C" void _plane_api_anchor(); -extern "C" void _quat_api_anchor(); -extern "C" void _basis_api_anchor(); -extern "C" void _rect3_api_anchor(); -extern "C" void _transform_api_anchor(); -extern "C" void _color_api_anchor(); -extern "C" void _node_path_api_anchor(); -extern "C" void _rid_api_anchor(); -extern "C" void _dictionary_api_anchor(); -extern "C" void _array_api_anchor(); -extern "C" void _pool_arrays_api_anchor(); -extern "C" void _variant_api_anchor(); - -void _api_anchor() { - - _string_api_anchor(); - _string_name_api_anchor(); - _vector2_api_anchor(); - _rect2_api_anchor(); - _vector3_api_anchor(); - _transform2d_api_anchor(); - _plane_api_anchor(); - _quat_api_anchor(); - _rect3_api_anchor(); - _basis_api_anchor(); - _transform_api_anchor(); - _color_api_anchor(); - _node_path_api_anchor(); - _rid_api_anchor(); - _dictionary_api_anchor(); - _array_api_anchor(); - _pool_arrays_api_anchor(); - _variant_api_anchor(); -} - void GDAPI godot_object_destroy(godot_object *p_o) { memdelete((Object *)p_o); } @@ -88,7 +49,7 @@ void GDAPI godot_object_destroy(godot_object *p_o) { // Singleton API godot_object GDAPI *godot_global_get_singleton(char *p_name) { - return (godot_object *)ProjectSettings::get_singleton()->get_singleton_object(String(p_name)); + return (godot_object *)Engine::get_singleton()->get_singleton_object(String(p_name)); } // result shouldn't be freed void GDAPI *godot_get_stack_bottom() { @@ -133,14 +94,6 @@ godot_variant GDAPI godot_method_bind_call(godot_method_bind *p_method_bind, god return ret; } -// @Todo -/* -void GDAPI godot_method_bind_varcall(godot_method_bind *p_method_bind) -{ - -} -*/ - godot_class_constructor GDAPI godot_get_class_constructor(const char *p_classname) { ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(StringName(p_classname)); if (class_info) @@ -162,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); } @@ -186,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 0124efe4ba..8dfe151f91 100644 --- a/modules/gdnative/gdnative/node_path.cpp +++ b/modules/gdnative/gdnative/node_path.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _node_path_api_anchor() {} - void GDAPI godot_node_path_new(godot_node_path *r_dest, const godot_string *p_from) { NodePath *dest = (NodePath *)r_dest; const String *from = (const String *)p_from; diff --git a/modules/gdnative/gdnative/plane.cpp b/modules/gdnative/gdnative/plane.cpp index a5e05ffa6b..c92efb8d99 100644 --- a/modules/gdnative/gdnative/plane.cpp +++ b/modules/gdnative/gdnative/plane.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _plane_api_anchor() {} - void GDAPI godot_plane_new_with_reals(godot_plane *r_dest, const godot_real p_a, const godot_real p_b, const godot_real p_c, const godot_real p_d) { Plane *dest = (Plane *)r_dest; diff --git a/modules/gdnative/gdnative/pool_arrays.cpp b/modules/gdnative/gdnative/pool_arrays.cpp index 731e930908..562cc344a9 100644 --- a/modules/gdnative/gdnative/pool_arrays.cpp +++ b/modules/gdnative/gdnative/pool_arrays.cpp @@ -41,9 +41,6 @@ extern "C" { #endif -void _pool_arrays_api_anchor() { -} - #define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) // byte diff --git a/modules/gdnative/gdnative/quat.cpp b/modules/gdnative/gdnative/quat.cpp index 7db7847da1..2d012c069f 100644 --- a/modules/gdnative/gdnative/quat.cpp +++ b/modules/gdnative/gdnative/quat.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _quat_api_anchor() {} - void GDAPI godot_quat_new(godot_quat *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z, const godot_real p_w) { Quat *dest = (Quat *)r_dest; diff --git a/modules/gdnative/gdnative/rect2.cpp b/modules/gdnative/gdnative/rect2.cpp index ecd8cce9ca..b0b0e28138 100644 --- a/modules/gdnative/gdnative/rect2.cpp +++ b/modules/gdnative/gdnative/rect2.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _rect2_api_anchor() {} - void GDAPI godot_rect2_new_with_position_and_size(godot_rect2 *r_dest, const godot_vector2 *p_pos, const godot_vector2 *p_size) { const Vector2 *position = (const Vector2 *)p_pos; const Vector2 *size = (const Vector2 *)p_size; diff --git a/modules/gdnative/gdnative/rect3.cpp b/modules/gdnative/gdnative/rect3.cpp deleted file mode 100644 index d34d964db9..0000000000 --- a/modules/gdnative/gdnative/rect3.cpp +++ /dev/null @@ -1,219 +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 _rect3_api_anchor() {} - -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/rid.cpp b/modules/gdnative/gdnative/rid.cpp index f05c39906c..c6e8d82494 100644 --- a/modules/gdnative/gdnative/rid.cpp +++ b/modules/gdnative/gdnative/rid.cpp @@ -37,8 +37,6 @@ extern "C" { #endif -void _rid_api_anchor() {} - void GDAPI godot_rid_new(godot_rid *r_dest) { RID *dest = (RID *)r_dest; memnew_placement(dest, RID); diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index 619003083d..67a037736c 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -39,9 +39,6 @@ extern "C" { #endif -void _string_api_anchor() { -} - void GDAPI godot_string_new(godot_string *r_dest) { String *dest = (String *)r_dest; memnew_placement(dest, String); @@ -92,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/string_name.cpp b/modules/gdnative/gdnative/string_name.cpp index 5c00fdfc2f..5c79e0acbd 100644 --- a/modules/gdnative/gdnative/string_name.cpp +++ b/modules/gdnative/gdnative/string_name.cpp @@ -38,9 +38,6 @@ extern "C" { #endif -void _string_name_api_anchor() { -} - void GDAPI godot_string_name_new(godot_string_name *r_dest, const godot_string *p_name) { StringName *dest = (StringName *)r_dest; const String *name = (const String *)p_name; diff --git a/modules/gdnative/gdnative/transform.cpp b/modules/gdnative/gdnative/transform.cpp index d7a3e78d3f..b07fcffcb6 100644 --- a/modules/gdnative/gdnative/transform.cpp +++ b/modules/gdnative/gdnative/transform.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _transform_api_anchor() {} - void GDAPI godot_transform_new_with_axis_origin(godot_transform *r_dest, const godot_vector3 *p_x_axis, const godot_vector3 *p_y_axis, const godot_vector3 *p_z_axis, const godot_vector3 *p_origin) { const Vector3 *x_axis = (const Vector3 *)p_x_axis; const Vector3 *y_axis = (const Vector3 *)p_y_axis; @@ -200,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/transform2d.cpp b/modules/gdnative/gdnative/transform2d.cpp index dcb54f7a53..0a6334516b 100644 --- a/modules/gdnative/gdnative/transform2d.cpp +++ b/modules/gdnative/gdnative/transform2d.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _transform2d_api_anchor() {} - void GDAPI godot_transform2d_new(godot_transform2d *r_dest, const godot_real p_rot, const godot_vector2 *p_pos) { const Vector2 *pos = (const Vector2 *)p_pos; Transform2D *dest = (Transform2D *)r_dest; diff --git a/modules/gdnative/gdnative/variant.cpp b/modules/gdnative/gdnative/variant.cpp index 9ba4166c1d..6483d19d74 100644 --- a/modules/gdnative/gdnative/variant.cpp +++ b/modules/gdnative/gdnative/variant.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _variant_api_anchor() {} - #define memnew_placement_custom(m_placement, m_class, m_constr) _post_initialize(new (m_placement, sizeof(m_class), "") m_constr) // Constructors @@ -120,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) { @@ -306,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/vector2.cpp b/modules/gdnative/gdnative/vector2.cpp index 67f858997f..7a5b29e0c4 100644 --- a/modules/gdnative/gdnative/vector2.cpp +++ b/modules/gdnative/gdnative/vector2.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _vector2_api_anchor() {} - void GDAPI godot_vector2_new(godot_vector2 *r_dest, const godot_real p_x, const godot_real p_y) { Vector2 *dest = (Vector2 *)r_dest; diff --git a/modules/gdnative/gdnative/vector3.cpp b/modules/gdnative/gdnative/vector3.cpp index c85a3f1c08..11ffb3320b 100644 --- a/modules/gdnative/gdnative/vector3.cpp +++ b/modules/gdnative/gdnative/vector3.cpp @@ -36,8 +36,6 @@ extern "C" { #endif -void _vector3_api_anchor() {} - void GDAPI godot_vector3_new(godot_vector3 *r_dest, const godot_real p_x, const godot_real p_y, const godot_real p_z) { Vector3 *dest = (Vector3 *)r_dest; diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index 6555bc83b7..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": [ @@ -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/arvr/godot_arvr.h b/modules/gdnative/include/arvr/godot_arvr.h index c12251439d..be13ac954b 100644 --- a/modules/gdnative/include/arvr/godot_arvr.h +++ b/modules/gdnative/include/arvr/godot_arvr.h @@ -47,7 +47,7 @@ typedef struct { godot_bool (*is_initialized)(const void *); godot_bool (*initialize)(void *); void (*uninitialize)(void *); - godot_vector2 (*get_recommended_render_targetsize)(const void *); + godot_vector2 (*get_render_targetsize)(const void *); godot_transform (*get_transform_for_eye)(void *, godot_int, godot_transform *); void (*fill_projection_for_eye)(void *, godot_real *, godot_int, godot_real, godot_real, godot_real); void (*commit_for_eye)(void *, godot_int, godot_rid *, godot_rect2 *); 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 8fa96fd3af..6e69d43469 100644 --- a/modules/gdnative/include/gdnative/gdnative.h +++ b/modules/gdnative/include/gdnative/gdnative.h @@ -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/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/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index 63fb71feb6..f9d699fb59 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -32,9 +32,9 @@ #ifdef TOOLS_ENABLED #include "core/class_db.h" +#include "core/engine.h" #include "core/global_constants.h" #include "core/pair.h" -#include "core/project_settings.h" #include "os/file_access.h" // helper stuff @@ -177,7 +177,7 @@ List<ClassAPI> generate_c_api_classes() { if (name.begins_with("_")) { name.remove(0); } - class_api.is_singleton = ProjectSettings::get_singleton()->has_singleton(name); + class_api.is_singleton = Engine::get_singleton()->has_singleton(name); } class_api.is_instanciable = !class_api.is_singleton && ClassDB::can_instance(class_name); diff --git a/modules/gdnative/nativescript/nativescript.cpp b/modules/gdnative/nativescript/nativescript.cpp index c1df7def2e..c2c7c27f25 100644 --- a/modules/gdnative/nativescript/nativescript.cpp +++ b/modules/gdnative/nativescript/nativescript.cpp @@ -40,6 +40,8 @@ #include "scene/main/scene_tree.h" #include "scene/resources/scene_format_text.h" +#include <stdlib.h> + #ifndef NO_THREADS #include "os/thread.h" #endif @@ -52,7 +54,11 @@ #include "editor/editor_node.h" #endif -////// Script stuff +// +// +// Script stuff +// +// void NativeScript::_bind_methods() { ClassDB::bind_method(D_METHOD("set_class_name", "class_name"), &NativeScript::set_class_name); @@ -108,7 +114,7 @@ void NativeScript::set_library(Ref<GDNativeLibrary> p_library) { return; } library = p_library; - lib_path = library->get_active_library_path(); + lib_path = library->get_current_library_path(); #ifndef NO_THREADS if (Thread::get_caller_id() != Thread::get_main_id()) { @@ -414,7 +420,6 @@ Variant NativeScript::_new(const Variant **p_args, int p_argcount, Variant::Call } } -// TODO(karroffel): implement this NativeScript::NativeScript() { library = Ref<GDNative>(); lib_path = ""; @@ -424,7 +429,6 @@ NativeScript::NativeScript() { #endif } -// TODO(karroffel): implement this NativeScript::~NativeScript() { NSL->unregister_script(this); @@ -433,7 +437,11 @@ NativeScript::~NativeScript() { #endif } -////// ScriptInstance stuff +// +// +// ScriptInstance stuff +// +// #define GET_SCRIPT_DESC() script->get_script_desc() @@ -691,7 +699,6 @@ NativeScriptInstance::RPCMode NativeScriptInstance::get_rpc_mode(const StringNam return RPC_MODE_DISABLED; } -// TODO(karroffel): implement this NativeScriptInstance::RPCMode NativeScriptInstance::get_rset_mode(const StringName &p_variable) const { NativeScriptDesc *script_data = GET_SCRIPT_DESC(); @@ -774,15 +781,14 @@ NativeScriptInstance::~NativeScriptInstance() { } } -////// ScriptingLanguage stuff +// +// +// ScriptingLanguage stuff +// +// NativeScriptLanguage *NativeScriptLanguage::singleton; -extern "C" void _native_script_hook(); -void NativeScriptLanguage::_hacky_api_anchor() { - _native_script_hook(); -} - void NativeScriptLanguage::_unload_stuff() { for (Map<String, Map<StringName, NativeScriptDesc> >::Element *L = library_classes.front(); L; L = L->next()) { for (Map<StringName, NativeScriptDesc>::Element *C = L->get().front(); C; C = C->next()) { @@ -819,9 +825,7 @@ NativeScriptLanguage::NativeScriptLanguage() { #endif } -// TODO(karroffel): implement this NativeScriptLanguage::~NativeScriptLanguage() { - // _unload_stuff(); // NOTE(karroffel): This gets called in ::finish() for (Map<String, Ref<GDNative> >::Element *L = NSL->library_gdnatives.front(); L; L = L->next()) { @@ -847,7 +851,6 @@ void _add_reload_node() { #endif } -// TODO(karroffel): implement this void NativeScriptLanguage::init() { #if defined(TOOLS_ENABLED) && defined(DEBUG_METHODS_ENABLED) @@ -860,6 +863,7 @@ void NativeScriptLanguage::init() { if (generate_c_api(E->next()->get()) != OK) { ERR_PRINT("Failed to generate C API\n"); } + exit(0); } #endif @@ -886,11 +890,9 @@ void NativeScriptLanguage::get_comment_delimiters(List<String> *p_delimiters) co void NativeScriptLanguage::get_string_delimiters(List<String> *p_delimiters) const { } -// TODO(karroffel): implement this Ref<Script> NativeScriptLanguage::get_template(const String &p_class_name, const String &p_base_class_name) const { NativeScript *s = memnew(NativeScript); s->set_class_name(p_class_name); - // TODO(karroffel): use p_base_class_name return Ref<NativeScript>(s); } bool NativeScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const { @@ -988,7 +990,7 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { MutexLock lock(mutex); #endif // See if this library was "registered" already. - const String &lib_path = lib->get_active_library_path(); + const String &lib_path = lib->get_current_library_path(); ERR_EXPLAIN(lib->get_name() + " does not have a library for the current platform"); ERR_FAIL_COND(lib_path.length() == 0); Map<String, Ref<GDNative> >::Element *E = library_gdnatives.find(lib_path); @@ -998,7 +1000,7 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { gdn.instance(); gdn->set_library(lib); - // TODO(karroffel): check the return value? + // TODO check the return value? gdn->initialize(); library_gdnatives.insert(lib_path, gdn); @@ -1010,7 +1012,7 @@ void NativeScriptLanguage::init_library(const Ref<GDNativeLibrary> &lib) { void *proc_ptr; - Error err = gdn->get_symbol(_init_call_name, proc_ptr); + Error err = gdn->get_symbol(lib->get_symbol_prefix() + _init_call_name, proc_ptr); if (err != OK) { ERR_PRINT(String("No " + _init_call_name + " in \"" + lib_path + "\" found").utf8().get_data()); @@ -1051,7 +1053,7 @@ void NativeScriptLanguage::call_libraries_cb(const StringName &name) { if (L->get()->is_initialized()) { void *proc_ptr; - Error err = L->get()->get_symbol(name, proc_ptr); + Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + name, proc_ptr); if (!err) { ((void (*)())proc_ptr)(); @@ -1140,7 +1142,7 @@ void NativeReloadNode::_notification(int p_what) { // here the library registers all the classes and stuff. void *proc_ptr; - Error err = L->get()->get_symbol("godot_nativescript_init", proc_ptr); + Error err = L->get()->get_symbol(L->get()->get_library()->get_symbol_prefix() + "nativescript_init", proc_ptr); if (err != OK) { ERR_PRINT(String("No godot_nativescript_init in \"" + L->key() + "\" found").utf8().get_data()); } else { diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index e8fc9e6880..f0f14e2f30 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -229,15 +229,15 @@ public: Map<String, Set<NativeScript *> > library_script_users; const StringName _init_call_type = "nativescript_init"; - const StringName _init_call_name = "godot_nativescript_init"; + const StringName _init_call_name = "nativescript_init"; const StringName _noarg_call_type = "nativescript_no_arg"; - const StringName _frame_call_name = "godot_nativescript_frame"; + const StringName _frame_call_name = "nativescript_frame"; #ifndef NO_THREADS - const StringName _thread_enter_call_name = "godot_nativescript_thread_enter"; - const StringName _thread_exit_call_name = "godot_nativescript_thread_exit"; + const StringName _thread_enter_call_name = "nativescript_thread_enter"; + const StringName _thread_exit_call_name = "nativescript_thread_exit"; #endif NativeScriptLanguage(); diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index 19a62b9c4f..34099bf528 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -48,7 +48,7 @@ #include "gd_native_library_editor.h" // Class used to discover singleton gdnative files -void actual_discoverer_handler(); +static void actual_discoverer_handler(); class GDNativeSingletonDiscover : public Object { // GDCLASS(GDNativeSingletonDiscover, Object) @@ -66,7 +66,7 @@ class GDNativeSingletonDiscover : public Object { } }; -Set<String> get_gdnative_singletons(EditorFileSystemDirectory *p_dir) { +static Set<String> get_gdnative_singletons(EditorFileSystemDirectory *p_dir) { Set<String> file_paths; @@ -81,7 +81,7 @@ Set<String> get_gdnative_singletons(EditorFileSystemDirectory *p_dir) { } Ref<GDNativeLibrary> lib = ResourceLoader::load(p_dir->get_file_path(i)); - if (lib.is_valid() && lib->is_singleton_gdnative()) { + if (lib.is_valid() && lib->is_singleton()) { file_paths.insert(p_dir->get_file_path(i)); } } @@ -98,7 +98,7 @@ Set<String> get_gdnative_singletons(EditorFileSystemDirectory *p_dir) { return file_paths; } -void actual_discoverer_handler() { +static void actual_discoverer_handler() { EditorFileSystemDirectory *dir = EditorFileSystem::get_singleton()->get_filesystem(); Set<String> file_paths = get_gdnative_singletons(dir); @@ -115,7 +115,134 @@ void actual_discoverer_handler() { ProjectSettings::get_singleton()->save(); } -GDNativeSingletonDiscover *discoverer = NULL; +static GDNativeSingletonDiscover *discoverer = NULL; + +class GDNativeExportPlugin : public EditorExportPlugin { + +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; + } + + Ref<GDNativeLibrary> lib = ResourceLoader::load(p_path); + + if (lib.is_null()) { + return; + } + + Ref<ConfigFile> config = lib->get_config_file(); + + { + + List<String> entry_keys; + config->get_section_keys("entry", &entry_keys); + + for (List<String>::Element *E = entry_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 (skip) { + continue; + } + + String entry_lib_path = config->get_value("entry", key); + add_shared_object(entry_lib_path, tags); + } + } + + { + List<String> dependency_keys; + config->get_section_keys("dependencies", &dependency_keys); + + for (List<String>::Element *E = dependency_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 (skip) { + continue; + } + + 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); + } + } + } + + 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; + } + } + + 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()); + + add_ios_cpp_code(additional_code); + add_ios_linker_flags(linker_flags); + } +} static void editor_init_callback() { @@ -125,11 +252,16 @@ static void editor_init_callback() { discoverer = memnew(GDNativeSingletonDiscover); EditorFileSystem::get_singleton()->connect("filesystem_changed", discoverer, "get_class"); + + Ref<GDNativeExportPlugin> export_plugin; + export_plugin.instance(); + + EditorExport::get_singleton()->add_export_plugin(export_plugin); } #endif -godot_variant cb_standard_varcall(void *p_procedure_handle, godot_array *p_args) { +static godot_variant cb_standard_varcall(void *p_procedure_handle, godot_array *p_args) { godot_gdnative_procedure_fn proc; proc = (godot_gdnative_procedure_fn)p_procedure_handle; @@ -141,18 +273,25 @@ GDNativeCallRegistry *GDNativeCallRegistry::singleton; Vector<Ref<GDNative> > singleton_gdnatives; +GDNativeLibraryResourceLoader *resource_loader_gdnlib = NULL; +GDNativeLibraryResourceSaver *resource_saver_gdnlib = NULL; + 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>(); ClassDB::register_class<GDNative>(); + resource_loader_gdnlib = memnew(GDNativeLibraryResourceLoader); + resource_saver_gdnlib = memnew(GDNativeLibraryResourceSaver); + + ResourceLoader::add_resource_format_loader(resource_loader_gdnlib); + ResourceSaver::add_resource_format_saver(resource_saver_gdnlib); + GDNativeCallRegistry::singleton = memnew(GDNativeCallRegistry); GDNativeCallRegistry::singleton->register_native_call_type("standard_varcall", cb_standard_varcall); @@ -185,11 +324,11 @@ void register_gdnative_types() { void *proc_ptr; Error err = singleton_gdnatives[i]->get_symbol( - "godot_gdnative_singleton", + lib->get_symbol_prefix() + "gdnative_singleton", proc_ptr); if (err != OK) { - ERR_PRINT((String("No godot_gdnative_singleton in \"" + singleton_gdnatives[i]->get_library()->get_active_library_path()) + "\" found").utf8().get_data()); + ERR_PRINT((String("No godot_gdnative_singleton in \"" + singleton_gdnatives[i]->get_library()->get_current_library_path()) + "\" found").utf8().get_data()); } else { ((void (*)())proc_ptr)(); } @@ -224,6 +363,9 @@ void unregister_gdnative_types() { } #endif + memdelete(resource_loader_gdnlib); + memdelete(resource_saver_gdnlib); + // This is for printing out the sizes of the core types /* @@ -236,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/config.py b/modules/gdscript/config.py index 5698a37295..6496b59d75 100644 --- a/modules/gdscript/config.py +++ b/modules/gdscript/config.py @@ -1,8 +1,15 @@ - - def can_build(platform): return True - def configure(env): pass + +def get_doc_classes(): + return [ + "GDScript", + "GDScriptFunctionState", + "GDScriptNativeClass", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/gdscript/doc_classes/GDScript.xml b/modules/gdscript/doc_classes/GDScript.xml new file mode 100644 index 0000000000..13d45aa520 --- /dev/null +++ b/modules/gdscript/doc_classes/GDScript.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="GDScript" inherits="Script" category="Core" version="3.0-alpha"> + <brief_description> + A script implemented in the GDScript programming language. + </brief_description> + <description> + A script implemented in the GDScript programming language. The script exends the functionality of all objects that instance it. + [method new] creates a new instance of the script. [method Object.set_script] extends an existing object, if that object's class matches one of the script's base classes. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_as_byte_code" qualifiers="const"> + <return type="PoolByteArray"> + </return> + <description> + Returns byte code for the script source code. + </description> + </method> + <method name="new" qualifiers="vararg"> + <return type="Object"> + </return> + <description> + Returns a new instance of the script. + For example: + [codeblock] + var MyClass = load("myclass.gd") + var instance = MyClass.new() + assert(instance.get_script() == MyClass) + [/codeblock] + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/modules/gdscript/doc_classes/GDScriptFunctionState.xml b/modules/gdscript/doc_classes/GDScriptFunctionState.xml new file mode 100644 index 0000000000..2df4e7c217 --- /dev/null +++ b/modules/gdscript/doc_classes/GDScriptFunctionState.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="GDScriptFunctionState" inherits="Reference" category="Core" version="3.0-alpha"> + <brief_description> + State of a function call after yielding. + </brief_description> + <description> + Calling [method @GDScript.yield] within a function will cause that function to yield and return its current state as an object of this type. The yielded function call can then be resumed later by calling [method resume] on this state object. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="is_valid" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="extended_check" type="bool" default="false"> + </argument> + <description> + Check whether the function call may be resumed. This is not the case if the function state was already resumed. + If [code]extended_check[/code] is enabled, it also checks if the associated script and object still exist. The extended check is done in debug mode as part of [method GDScriptFunctionState.resume], but you can use this if you know you may be trying to resume without knowing for sure the object and/or script have survived up to that point. + </description> + </method> + <method name="resume"> + <return type="Variant"> + </return> + <argument index="0" name="arg" type="Variant" default="null"> + </argument> + <description> + Resume execution of the yielded function call. + If handed an argument, return the argument from the [method @GDScript.yield] call in the yielded function call. You can pass e.g. an [Array] to hand multiple arguments. + This function returns what the resumed function call returns, possibly another function state if yielded again. + </description> + </method> + </methods> + <signals> + <signal name="completed"> + <argument index="0" name="result" type="Nil"> + </argument> + <description> + </description> + </signal> + </signals> + <constants> + </constants> +</class> diff --git a/modules/gdscript/doc_classes/GDScriptNativeClass.xml b/modules/gdscript/doc_classes/GDScriptNativeClass.xml new file mode 100644 index 0000000000..4514a78469 --- /dev/null +++ b/modules/gdscript/doc_classes/GDScriptNativeClass.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="GDScriptNativeClass" inherits="Reference" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="new"> + <return type="Variant"> + </return> + <description> + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/modules/gdscript/gd_script.cpp b/modules/gdscript/gdscript.cpp index e5016c59bd..41a810ff00 100644 --- a/modules/gdscript/gd_script.cpp +++ b/modules/gdscript/gdscript.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_script.cpp */ +/* gdscript.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,9 +27,10 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_script.h" +#include "gdscript.h" -#include "gd_compiler.h" +#include "engine.h" +#include "gdscript_compiler.h" #include "global_constants.h" #include "io/file_access_encrypted.h" #include "os/file_access.h" @@ -38,12 +39,12 @@ /////////////////////////// -GDNativeClass::GDNativeClass(const StringName &p_name) { +GDScriptNativeClass::GDScriptNativeClass(const StringName &p_name) { name = p_name; } -bool GDNativeClass::_get(const StringName &p_name, Variant &r_ret) const { +bool GDScriptNativeClass::_get(const StringName &p_name, Variant &r_ret) const { bool ok; int v = ClassDB::get_integer_constant(name, p_name, &ok); @@ -56,12 +57,12 @@ bool GDNativeClass::_get(const StringName &p_name, Variant &r_ret) const { } } -void GDNativeClass::_bind_methods() { +void GDScriptNativeClass::_bind_methods() { - ClassDB::bind_method(D_METHOD("new"), &GDNativeClass::_new); + ClassDB::bind_method(D_METHOD("new"), &GDScriptNativeClass::_new); } -Variant GDNativeClass::_new() { +Variant GDScriptNativeClass::_new() { Object *o = instance(); if (!o) { @@ -77,16 +78,16 @@ Variant GDNativeClass::_new() { } } -Object *GDNativeClass::instance() { +Object *GDScriptNativeClass::instance() { return ClassDB::instance(name); } -GDInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error) { +GDScriptInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error) { /* STEP 1, CREATE */ - GDInstance *instance = memnew(GDInstance); + GDScriptInstance *instance = memnew(GDScriptInstance); instance->base_ref = p_isref; instance->members.resize(member_indices.size()); instance->script = Ref<GDScript>(this); @@ -99,7 +100,7 @@ GDInstance *GDScript::_create_instance(const Variant **p_args, int p_argcount, O #endif instance->owner->set_script_instance(instance); -/* STEP 2, INITIALIZE AND CONSRTUCT */ + /* STEP 2, INITIALIZE AND CONSRTUCT */ #ifndef NO_THREADS GDScriptLanguage::singleton->lock->lock(); @@ -162,7 +163,7 @@ Variant GDScript::_new(const Variant **p_args, int p_argcount, Variant::CallErro ref = REF(r); } - GDInstance *instance = _create_instance(p_args, p_argcount, owner, r != NULL, r_error); + GDScriptInstance *instance = _create_instance(p_args, p_argcount, owner, r != NULL, r_error); if (!instance) { if (ref.is_null()) { memdelete(owner); //no owner, sorry @@ -217,7 +218,7 @@ void GDScript::_placeholder_erased(PlaceHolderScriptInstance *p_placeholder) { void GDScript::get_script_method_list(List<MethodInfo> *p_list) const { - for (const Map<StringName, GDFunction *>::Element *E = member_functions.front(); E; E = E->next()) { + for (const Map<StringName, GDScriptFunction *>::Element *E = member_functions.front(); E; E = E->next()) { MethodInfo mi; mi.name = E->key(); for (int i = 0; i < E->get()->get_argument_count(); i++) { @@ -271,7 +272,7 @@ bool GDScript::has_method(const StringName &p_method) const { MethodInfo GDScript::get_method_info(const StringName &p_method) const { - const Map<StringName, GDFunction *>::Element *E = member_functions.find(p_method); + const Map<StringName, GDScriptFunction *>::Element *E = member_functions.find(p_method); if (!E) return MethodInfo(); @@ -419,15 +420,15 @@ bool GDScript::_update_exports() { if (basedir != "") basedir = basedir.get_base_dir(); - GDParser parser; + GDScriptParser parser; Error err = parser.parse(source, basedir, true, path); if (err == OK) { - const GDParser::Node *root = parser.get_parse_tree(); - ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, false); + const GDScriptParser::Node *root = parser.get_parse_tree(); + ERR_FAIL_COND_V(root->type != GDScriptParser::Node::TYPE_CLASS, false); - const GDParser::ClassNode *c = static_cast<const GDParser::ClassNode *>(root); + const GDScriptParser::ClassNode *c = static_cast<const GDScriptParser::ClassNode *>(root); if (base_cache.is_valid()) { base_cache->inheriters_cache.erase(get_instance_id()); @@ -571,7 +572,7 @@ Error GDScript::reload(bool p_keep_state) { } valid = false; - GDParser parser; + GDScriptParser parser; Error err = parser.parse(source, basedir, false, path); if (err) { if (ScriptDebugger::get_singleton()) { @@ -583,7 +584,7 @@ Error GDScript::reload(bool p_keep_state) { bool can_run = ScriptServer::is_scripting_enabled() || parser.is_tool_script(); - GDCompiler compiler; + GDScriptCompiler compiler; err = compiler.compile(&parser, this, p_keep_state); if (err) { @@ -614,12 +615,29 @@ 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; while (top) { - Map<StringName, GDFunction *>::Element *E = top->member_functions.find(p_method); + Map<StringName, GDScriptFunction *>::Element *E = top->member_functions.find(p_method); if (E) { if (!E->get()->is_static()) { @@ -698,7 +716,7 @@ void GDScript::_bind_methods() { Vector<uint8_t> GDScript::get_as_byte_code() const { - GDTokenizerBuffer tokenizer; + GDScriptTokenizerBuffer tokenizer; return tokenizer.parse_code_string(source); }; @@ -738,14 +756,14 @@ Error GDScript::load_byte_code(const String &p_path) { basedir = basedir.get_base_dir(); valid = false; - GDParser parser; + GDScriptParser parser; Error err = parser.parse_bytecode(bytecode, basedir, get_path()); if (err) { _err_print_error("GDScript::load_byte_code", path.empty() ? "built-in" : (const char *)path.utf8().get_data(), parser.get_error_line(), ("Parse Error: " + parser.get_error()).utf8().get_data(), ERR_HANDLER_SCRIPT); ERR_FAIL_V(ERR_PARSE_ERROR); } - GDCompiler compiler; + GDScriptCompiler compiler; err = compiler.compile(&parser, this); if (err) { @@ -798,7 +816,7 @@ Error GDScript::load_source_code(const String &p_path) { return OK; } -const Map<StringName, GDFunction *> &GDScript::debug_get_member_functions() const { +const Map<StringName, GDScriptFunction *> &GDScript::debug_get_member_functions() const { return member_functions; } @@ -885,7 +903,7 @@ GDScript::GDScript() } GDScript::~GDScript() { - for (Map<StringName, GDFunction *>::Element *E = member_functions.front(); E; E = E->next()) { + for (Map<StringName, GDScriptFunction *>::Element *E = member_functions.front(); E; E = E->next()) { memdelete(E->get()); } @@ -909,7 +927,7 @@ GDScript::~GDScript() { // INSTANCE // ////////////////////////////// -bool GDInstance::set(const StringName &p_name, const Variant &p_value) { +bool GDScriptInstance::set(const StringName &p_name, const Variant &p_value) { //member { @@ -931,7 +949,7 @@ bool GDInstance::set(const StringName &p_name, const Variant &p_value) { GDScript *sptr = script.ptr(); while (sptr) { - Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set); + Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._set); if (E) { Variant name = p_name; @@ -948,7 +966,7 @@ bool GDInstance::set(const StringName &p_name, const Variant &p_value) { return false; } -bool GDInstance::get(const StringName &p_name, Variant &r_ret) const { +bool GDScriptInstance::get(const StringName &p_name, Variant &r_ret) const { const GDScript *sptr = script.ptr(); while (sptr) { @@ -958,7 +976,7 @@ bool GDInstance::get(const StringName &p_name, Variant &r_ret) const { if (E) { if (E->get().getter) { Variant::CallError err; - r_ret = const_cast<GDInstance *>(this)->call(E->get().getter, NULL, 0, err); + r_ret = const_cast<GDScriptInstance *>(this)->call(E->get().getter, NULL, 0, err); if (err.error == Variant::CallError::CALL_OK) { return true; } @@ -982,14 +1000,14 @@ bool GDInstance::get(const StringName &p_name, Variant &r_ret) const { } { - const Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get); + const Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get); if (E) { Variant name = p_name; const Variant *args[1] = { &name }; Variant::CallError err; - Variant ret = const_cast<GDFunction *>(E->get())->call(const_cast<GDInstance *>(this), (const Variant **)args, 1, err); + Variant ret = const_cast<GDScriptFunction *>(E->get())->call(const_cast<GDScriptInstance *>(this), (const Variant **)args, 1, err); if (err.error == Variant::CallError::CALL_OK && ret.get_type() != Variant::NIL) { r_ret = ret; return true; @@ -1002,7 +1020,7 @@ bool GDInstance::get(const StringName &p_name, Variant &r_ret) const { return false; } -Variant::Type GDInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { +Variant::Type GDScriptInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { const GDScript *sptr = script.ptr(); while (sptr) { @@ -1020,7 +1038,7 @@ Variant::Type GDInstance::get_property_type(const StringName &p_name, bool *r_is return Variant::NIL; } -void GDInstance::get_property_list(List<PropertyInfo> *p_properties) const { +void GDScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const { // exported members, not doen yet! const GDScript *sptr = script.ptr(); @@ -1028,11 +1046,11 @@ void GDInstance::get_property_list(List<PropertyInfo> *p_properties) const { while (sptr) { - const Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list); + const Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._get_property_list); if (E) { Variant::CallError err; - Variant ret = const_cast<GDFunction *>(E->get())->call(const_cast<GDInstance *>(this), NULL, 0, err); + Variant ret = const_cast<GDScriptFunction *>(E->get())->call(const_cast<GDScriptInstance *>(this), NULL, 0, err); if (err.error == Variant::CallError::CALL_OK) { if (ret.get_type() != Variant::ARRAY) { @@ -1091,12 +1109,12 @@ void GDInstance::get_property_list(List<PropertyInfo> *p_properties) const { } } -void GDInstance::get_method_list(List<MethodInfo> *p_list) const { +void GDScriptInstance::get_method_list(List<MethodInfo> *p_list) const { const GDScript *sptr = script.ptr(); while (sptr) { - for (Map<StringName, GDFunction *>::Element *E = sptr->member_functions.front(); E; E = E->next()) { + for (Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.front(); E; E = E->next()) { MethodInfo mi; mi.name = E->key(); @@ -1109,11 +1127,11 @@ void GDInstance::get_method_list(List<MethodInfo> *p_list) const { } } -bool GDInstance::has_method(const StringName &p_method) const { +bool GDScriptInstance::has_method(const StringName &p_method) const { const GDScript *sptr = script.ptr(); while (sptr) { - const Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(p_method); + const Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(p_method); if (E) return true; sptr = sptr->_base; @@ -1121,13 +1139,13 @@ bool GDInstance::has_method(const StringName &p_method) const { return false; } -Variant GDInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { +Variant GDScriptInstance::call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { //printf("calling %ls:%i method %ls\n", script->get_path().c_str(), -1, String(p_method).c_str()); GDScript *sptr = script.ptr(); while (sptr) { - Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(p_method); + Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(p_method); if (E) { return E->get()->call(this, p_args, p_argcount, r_error); } @@ -1137,13 +1155,13 @@ Variant GDInstance::call(const StringName &p_method, const Variant **p_args, int return Variant(); } -void GDInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { +void GDScriptInstance::call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) { GDScript *sptr = script.ptr(); Variant::CallError ce; while (sptr) { - Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(p_method); + Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(p_method); if (E) { E->get()->call(this, p_args, p_argcount, ce); } @@ -1151,27 +1169,27 @@ void GDInstance::call_multilevel(const StringName &p_method, const Variant **p_a } } -void GDInstance::_ml_call_reversed(GDScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount) { +void GDScriptInstance::_ml_call_reversed(GDScript *sptr, const StringName &p_method, const Variant **p_args, int p_argcount) { if (sptr->_base) _ml_call_reversed(sptr->_base, p_method, p_args, p_argcount); Variant::CallError ce; - Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(p_method); + Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(p_method); if (E) { E->get()->call(this, p_args, p_argcount, ce); } } -void GDInstance::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { +void GDScriptInstance::call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) { if (script.ptr()) { _ml_call_reversed(script.ptr(), p_method, p_args, p_argcount); } } -void GDInstance::notification(int p_notification) { +void GDScriptInstance::notification(int p_notification) { //notification is not virtual, it gets called at ALL levels just like in C. Variant value = p_notification; @@ -1179,7 +1197,7 @@ void GDInstance::notification(int p_notification) { GDScript *sptr = script.ptr(); while (sptr) { - Map<StringName, GDFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification); + Map<StringName, GDScriptFunction *>::Element *E = sptr->member_functions.find(GDScriptLanguage::get_singleton()->strings._notification); if (E) { Variant::CallError err; E->get()->call(this, args, 1, err); @@ -1191,22 +1209,22 @@ void GDInstance::notification(int p_notification) { } } -Ref<Script> GDInstance::get_script() const { +Ref<Script> GDScriptInstance::get_script() const { return script; } -ScriptLanguage *GDInstance::get_language() { +ScriptLanguage *GDScriptInstance::get_language() { return GDScriptLanguage::get_singleton(); } -GDInstance::RPCMode GDInstance::get_rpc_mode(const StringName &p_method) const { +GDScriptInstance::RPCMode GDScriptInstance::get_rpc_mode(const StringName &p_method) const { const GDScript *cscript = script.ptr(); while (cscript) { - const Map<StringName, GDFunction *>::Element *E = cscript->member_functions.find(p_method); + const Map<StringName, GDScriptFunction *>::Element *E = cscript->member_functions.find(p_method); if (E) { if (E->get()->get_rpc_mode() != RPC_MODE_DISABLED) { @@ -1219,7 +1237,7 @@ GDInstance::RPCMode GDInstance::get_rpc_mode(const StringName &p_method) const { return RPC_MODE_DISABLED; } -GDInstance::RPCMode GDInstance::get_rset_mode(const StringName &p_variable) const { +GDScriptInstance::RPCMode GDScriptInstance::get_rset_mode(const StringName &p_variable) const { const GDScript *cscript = script.ptr(); @@ -1237,7 +1255,7 @@ GDInstance::RPCMode GDInstance::get_rset_mode(const StringName &p_variable) cons return RPC_MODE_DISABLED; } -void GDInstance::reload_members() { +void GDScriptInstance::reload_members() { #ifdef DEBUG_ENABLED @@ -1268,12 +1286,12 @@ void GDInstance::reload_members() { #endif } -GDInstance::GDInstance() { +GDScriptInstance::GDScriptInstance() { owner = NULL; base_ref = false; } -GDInstance::~GDInstance() { +GDScriptInstance::~GDScriptInstance() { if (script.is_valid() && owner) { #ifndef NO_THREADS GDScriptLanguage::singleton->lock->lock(); @@ -1341,15 +1359,15 @@ void GDScriptLanguage::init() { if (globals.has(n)) continue; - Ref<GDNativeClass> nc = memnew(GDNativeClass(E->get())); + Ref<GDScriptNativeClass> nc = memnew(GDScriptNativeClass(E->get())); _add_global(n, nc); } //populate singletons - List<ProjectSettings::Singleton> singletons; - ProjectSettings::get_singleton()->get_singletons(&singletons); - for (List<ProjectSettings::Singleton>::Element *E = singletons.front(); E; E = E->next()) { + List<Engine::Singleton> singletons; + Engine::get_singleton()->get_singletons(&singletons); + for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { _add_global(E->get().name, E->get().ptr); } @@ -1378,7 +1396,7 @@ void GDScriptLanguage::profiling_start() { lock->lock(); } - SelfList<GDFunction> *elem = function_list.first(); + SelfList<GDScriptFunction> *elem = function_list.first(); while (elem) { elem->self()->profile.call_count = 0; elem->self()->profile.self_time = 0; @@ -1423,7 +1441,7 @@ int GDScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, lock->lock(); } - SelfList<GDFunction> *elem = function_list.first(); + SelfList<GDScriptFunction> *elem = function_list.first(); while (elem) { if (current >= p_info_max) break; @@ -1453,7 +1471,7 @@ int GDScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_ lock->lock(); } - SelfList<GDFunction> *elem = function_list.first(); + SelfList<GDScriptFunction> *elem = function_list.first(); while (elem) { if (current >= p_info_max) break; @@ -1598,17 +1616,18 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so Object *obj = E->get()->placeholders.front()->get()->get_owner(); //save instance info - List<Pair<StringName, Variant> > state; if (obj->get_script_instance()) { + map.insert(obj->get_instance_id(), List<Pair<StringName, Variant> >()); + List<Pair<StringName, Variant> > &state = map[obj->get_instance_id()]; obj->get_script_instance()->get_property_state(state); - map[obj->get_instance_id()] = state; obj->set_script(RefPtr()); } else { // no instance found. Let's remove it so we don't loop forever E->get()->placeholders.erase(E->get()->placeholders.front()->get()); } } + #endif for (Map<ObjectID, List<Pair<StringName, Variant> > >::Element *F = E->get()->pending_reload_state.front(); F; F = F->next()) { @@ -1666,7 +1685,7 @@ void GDScriptLanguage::frame() { lock->lock(); } - SelfList<GDFunction> *elem = function_list.first(); + SelfList<GDScriptFunction> *elem = function_list.first(); while (elem) { elem->self()->profile.last_frame_call_count = elem->self()->profile.frame_call_count; elem->self()->profile.last_frame_self_time = elem->self()->profile.frame_self_time; @@ -1751,8 +1770,8 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const { w++; } - for (int i = 0; i < GDFunctions::FUNC_MAX; i++) { - p_words->push_back(GDFunctions::get_func_name(GDFunctions::Function(i))); + for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) { + p_words->push_back(GDScriptFunctions::get_func_name(GDScriptFunctions::Function(i))); } } diff --git a/modules/gdscript/gd_script.h b/modules/gdscript/gdscript.h index e0d142014a..6e5d59ad0e 100644 --- a/modules/gdscript/gd_script.h +++ b/modules/gdscript/gdscript.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_script.h */ +/* gdscript.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,16 +27,17 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GD_SCRIPT_H -#define GD_SCRIPT_H +#ifndef GDSCRIPT_H +#define GDSCRIPT_H -#include "gd_function.h" +#include "gdscript_function.h" #include "io/resource_loader.h" #include "io/resource_saver.h" #include "script_language.h" -class GDNativeClass : public Reference { - GDCLASS(GDNativeClass, Reference); +class GDScriptNativeClass : public Reference { + + GDCLASS(GDScriptNativeClass, Reference); StringName name; @@ -48,7 +49,7 @@ public: _FORCE_INLINE_ const StringName &get_name() const { return name; } Variant _new(); Object *instance(); - GDNativeClass(const StringName &p_name); + GDScriptNativeClass(const StringName &p_name); }; class GDScript : public Script { @@ -64,21 +65,21 @@ class GDScript : public Script { ScriptInstance::RPCMode rpc_mode; }; - friend class GDInstance; - friend class GDFunction; - friend class GDCompiler; - friend class GDFunctions; + friend class GDScriptInstance; + friend class GDScriptFunction; + friend class GDScriptCompiler; + friend class GDScriptFunctions; friend class GDScriptLanguage; Variant _static_ref; //used for static call - Ref<GDNativeClass> native; + Ref<GDScriptNativeClass> native; Ref<GDScript> base; GDScript *_base; //fast pointer access GDScript *_owner; //for subclasses Set<StringName> members; //members are just indices to the instanced script. Map<StringName, Variant> constants; - Map<StringName, GDFunction *> member_functions; + Map<StringName, GDScriptFunction *> member_functions; Map<StringName, MemberInfo> member_indices; //members are just indices to the instanced script. Map<StringName, Ref<GDScript> > subclasses; Map<StringName, Vector<StringName> > _signals; @@ -99,7 +100,7 @@ class GDScript : public Script { #endif Map<StringName, PropertyInfo> member_info; - GDFunction *initializer; //direct pointer to _init , faster to locate + GDScriptFunction *initializer; //direct pointer to _init , faster to locate int subclass_count; Set<Object *> instances; @@ -109,7 +110,7 @@ class GDScript : public Script { String name; SelfList<GDScript> script_list; - GDInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error); + GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error); void _set_subclass_path(Ref<GDScript> &p_sc, const String &p_path); @@ -143,8 +144,8 @@ public: const Map<StringName, Ref<GDScript> > &get_subclasses() const { return subclasses; } const Map<StringName, Variant> &get_constants() const { return constants; } const Set<StringName> &get_members() const { return members; } - const Map<StringName, GDFunction *> &get_member_functions() const { return member_functions; } - const Ref<GDNativeClass> &get_native() const { return native; } + const Map<StringName, GDScriptFunction *> &get_member_functions() const { return member_functions; } + const Ref<GDScriptNativeClass> &get_native() const { return native; } virtual bool has_script_signal(const StringName &p_signal) const; virtual void get_script_signal_list(List<MethodInfo> *r_signals) const; @@ -153,7 +154,7 @@ public: Ref<GDScript> get_base() const; const Map<StringName, MemberInfo> &debug_get_member_indices() const { return member_indices; } - const Map<StringName, GDFunction *> &debug_get_member_functions() const; //this is debug only + const Map<StringName, GDScriptFunction *> &debug_get_member_functions() const; //this is debug only StringName debug_get_member_by_index(int p_idx) const; Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error); @@ -197,15 +198,18 @@ public: return -1; } + virtual void get_constants(Map<StringName, Variant> *p_constants); + virtual void get_members(Set<StringName> *p_members); + GDScript(); ~GDScript(); }; -class GDInstance : public ScriptInstance { +class GDScriptInstance : public ScriptInstance { friend class GDScript; - friend class GDFunction; - friend class GDFunctions; - friend class GDCompiler; + friend class GDScriptFunction; + friend class GDScriptFunctions; + friend class GDScriptCompiler; Object *owner; Ref<GDScript> script; @@ -218,7 +222,7 @@ class GDInstance : 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; @@ -246,8 +250,8 @@ public: virtual RPCMode get_rpc_mode(const StringName &p_method) const; virtual RPCMode get_rset_mode(const StringName &p_variable) const; - GDInstance(); - ~GDInstance(); + GDScriptInstance(); + ~GDScriptInstance(); }; class GDScriptLanguage : public ScriptLanguage { @@ -261,8 +265,8 @@ class GDScriptLanguage : public ScriptLanguage { struct CallLevel { Variant *stack; - GDFunction *function; - GDInstance *instance; + GDScriptFunction *function; + GDScriptInstance *instance; int *ip; int *line; }; @@ -276,16 +280,16 @@ class GDScriptLanguage : public ScriptLanguage { void _add_global(const StringName &p_name, const Variant &p_value); - friend class GDInstance; + friend class GDScriptInstance; Mutex *lock; friend class GDScript; SelfList<GDScript>::List script_list; - friend class GDFunction; + friend class GDScriptFunction; - SelfList<GDFunction>::List function_list; + SelfList<GDScriptFunction>::List function_list; bool profiling; uint64_t script_frame_time; @@ -295,7 +299,7 @@ public: bool debug_break(const String &p_error, bool p_allow_continue = true); bool debug_break_parse(const String &p_file, int p_line, const String &p_error); - _FORCE_INLINE_ void enter_function(GDInstance *p_instance, GDFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) { + _FORCE_INLINE_ void enter_function(GDScriptInstance *p_instance, GDScriptFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) { if (Thread::get_main_id() != Thread::get_caller_id()) return; //no support for other threads than main for now @@ -406,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(); @@ -446,4 +451,4 @@ public: virtual bool recognize(const RES &p_resource) const; }; -#endif // GD_SCRIPT_H +#endif // GDSCRIPT_H diff --git a/modules/gdscript/gd_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 7036a708e5..4cd6472b7f 100644 --- a/modules/gdscript/gd_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_compiler.cpp */ +/* gdscript_compiler.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,10 +27,11 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_compiler.h" -#include "gd_script.h" +#include "gdscript_compiler.h" -bool GDCompiler::_is_class_member_property(CodeGen &codegen, const StringName &p_name) { +#include "gdscript.h" + +bool GDScriptCompiler::_is_class_member_property(CodeGen &codegen, const StringName &p_name) { if (!codegen.function_node || codegen.function_node->_static) return false; @@ -38,10 +39,10 @@ bool GDCompiler::_is_class_member_property(CodeGen &codegen, const StringName &p return _is_class_member_property(codegen.script, p_name); } -bool GDCompiler::_is_class_member_property(GDScript *owner, const StringName &p_name) { +bool GDScriptCompiler::_is_class_member_property(GDScript *owner, const StringName &p_name) { GDScript *scr = owner; - GDNativeClass *nc = NULL; + GDScriptNativeClass *nc = NULL; while (scr) { if (scr->native.is_valid()) @@ -54,7 +55,7 @@ bool GDCompiler::_is_class_member_property(GDScript *owner, const StringName &p_ return ClassDB::has_property(nc->get_name(), p_name); } -void GDCompiler::_set_error(const String &p_error, const GDParser::Node *p_node) { +void GDScriptCompiler::_set_error(const String &p_error, const GDScriptParser::Node *p_node) { if (error != "") return; @@ -69,7 +70,7 @@ void GDCompiler::_set_error(const String &p_error, const GDParser::Node *p_node) } } -bool GDCompiler::_create_unary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level) { +bool GDScriptCompiler::_create_unary_operator(CodeGen &codegen, const GDScriptParser::OperatorNode *on, Variant::Operator op, int p_stack_level) { ERR_FAIL_COND_V(on->arguments.size() != 1, false); @@ -77,29 +78,29 @@ bool GDCompiler::_create_unary_operator(CodeGen &codegen, const GDParser::Operat if (src_address_a < 0) return false; - codegen.opcodes.push_back(GDFunction::OPCODE_OPERATOR); // perform operator + codegen.opcodes.push_back(GDScriptFunction::OPCODE_OPERATOR); // perform operator codegen.opcodes.push_back(op); //which operator codegen.opcodes.push_back(src_address_a); // argument 1 codegen.opcodes.push_back(src_address_a); // argument 2 (repeated) - //codegen.opcodes.push_back(GDFunction::ADDR_TYPE_NIL); // argument 2 (unary only takes one parameter) + //codegen.opcodes.push_back(GDScriptFunction::ADDR_TYPE_NIL); // argument 2 (unary only takes one parameter) return true; } -bool GDCompiler::_create_binary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer) { +bool GDScriptCompiler::_create_binary_operator(CodeGen &codegen, const GDScriptParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer) { ERR_FAIL_COND_V(on->arguments.size() != 2, false); int src_address_a = _parse_expression(codegen, on->arguments[0], p_stack_level, false, p_initializer); if (src_address_a < 0) return false; - if (src_address_a & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) + if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) p_stack_level++; //uses stack for return, increase stack int src_address_b = _parse_expression(codegen, on->arguments[1], p_stack_level, false, p_initializer); if (src_address_b < 0) return false; - codegen.opcodes.push_back(GDFunction::OPCODE_OPERATOR); // perform operator + codegen.opcodes.push_back(GDScriptFunction::OPCODE_OPERATOR); // perform operator codegen.opcodes.push_back(op); //which operator codegen.opcodes.push_back(src_address_a); // argument 1 codegen.opcodes.push_back(src_address_b); // argument 2 (unary only takes one parameter) @@ -107,14 +108,14 @@ bool GDCompiler::_create_binary_operator(CodeGen &codegen, const GDParser::Opera } /* -int GDCompiler::_parse_subexpression(CodeGen& codegen,const GDParser::Node *p_expression) { +int GDScriptCompiler::_parse_subexpression(CodeGen& codegen,const GDScriptParser::Node *p_expression) { int ret = _parse_expression(codegen,p_expression); if (ret<0) return ret; - if (ret&(GDFunction::ADDR_TYPE_STACK<<GDFunction::ADDR_BITS)) { + if (ret&(GDScriptFunction::ADDR_TYPE_STACK<<GDScriptFunction::ADDR_BITS)) { codegen.stack_level++; codegen.check_max_stack_level(); //stack was used, keep value @@ -124,24 +125,24 @@ int GDCompiler::_parse_subexpression(CodeGen& codegen,const GDParser::Node *p_ex } */ -int GDCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDParser::OperatorNode *p_expression, int p_stack_level) { +int GDScriptCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDScriptParser::OperatorNode *p_expression, int p_stack_level) { Variant::Operator var_op = Variant::OP_MAX; switch (p_expression->op) { - case GDParser::OperatorNode::OP_ASSIGN_ADD: var_op = Variant::OP_ADD; break; - case GDParser::OperatorNode::OP_ASSIGN_SUB: var_op = Variant::OP_SUBTRACT; break; - case GDParser::OperatorNode::OP_ASSIGN_MUL: var_op = Variant::OP_MULTIPLY; break; - case GDParser::OperatorNode::OP_ASSIGN_DIV: var_op = Variant::OP_DIVIDE; break; - case GDParser::OperatorNode::OP_ASSIGN_MOD: var_op = Variant::OP_MODULE; break; - case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: var_op = Variant::OP_SHIFT_LEFT; break; - case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: var_op = Variant::OP_SHIFT_RIGHT; break; - case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: var_op = Variant::OP_BIT_AND; break; - case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: var_op = Variant::OP_BIT_OR; break; - case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: var_op = Variant::OP_BIT_XOR; break; - case GDParser::OperatorNode::OP_INIT_ASSIGN: - case GDParser::OperatorNode::OP_ASSIGN: { + case GDScriptParser::OperatorNode::OP_ASSIGN_ADD: var_op = Variant::OP_ADD; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_SUB: var_op = Variant::OP_SUBTRACT; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_MUL: var_op = Variant::OP_MULTIPLY; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_DIV: var_op = Variant::OP_DIVIDE; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_MOD: var_op = Variant::OP_MODULE; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: var_op = Variant::OP_SHIFT_LEFT; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: var_op = Variant::OP_SHIFT_RIGHT; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_BIT_AND: var_op = Variant::OP_BIT_AND; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_BIT_OR: var_op = Variant::OP_BIT_OR; break; + case GDScriptParser::OperatorNode::OP_ASSIGN_BIT_XOR: var_op = Variant::OP_BIT_XOR; break; + case GDScriptParser::OperatorNode::OP_INIT_ASSIGN: + case GDScriptParser::OperatorNode::OP_ASSIGN: { //none } break; @@ -151,7 +152,7 @@ int GDCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDParser: } } - bool initializer = p_expression->op == GDParser::OperatorNode::OP_INIT_ASSIGN; + bool initializer = p_expression->op == GDScriptParser::OperatorNode::OP_INIT_ASSIGN; if (var_op == Variant::OP_MAX) { @@ -161,32 +162,32 @@ int GDCompiler::_parse_assign_right_expression(CodeGen &codegen, const GDParser: if (!_create_binary_operator(codegen, p_expression, var_op, p_stack_level, initializer)) return -1; - int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); + int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode codegen.alloc_stack(p_stack_level); return dst_addr; } -int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expression, int p_stack_level, bool p_root, bool p_initializer) { +int GDScriptCompiler::_parse_expression(CodeGen &codegen, const GDScriptParser::Node *p_expression, int p_stack_level, bool p_root, bool p_initializer) { switch (p_expression->type) { //should parse variable declaration and adjust stack accordingly... - case GDParser::Node::TYPE_IDENTIFIER: { + case GDScriptParser::Node::TYPE_IDENTIFIER: { //return identifier //wait, identifier could be a local variable or something else... careful here, must reference properly //as stack may be more interesting to work with //This could be made much simpler by just indexing "self", but done this way (with custom self-addressing modes) increases peformance a lot. - const GDParser::IdentifierNode *in = static_cast<const GDParser::IdentifierNode *>(p_expression); + const GDScriptParser::IdentifierNode *in = static_cast<const GDScriptParser::IdentifierNode *>(p_expression); StringName identifier = in->name; if (_is_class_member_property(codegen, identifier)) { //get property - codegen.opcodes.push_back(GDFunction::OPCODE_GET_MEMBER); // perform operator + codegen.opcodes.push_back(GDScriptFunction::OPCODE_GET_MEMBER); // perform operator codegen.opcodes.push_back(codegen.get_name_map_pos(identifier)); // argument 2 (unary only takes one parameter) - int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); + int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode codegen.alloc_stack(p_stack_level); return dst_addr; @@ -196,7 +197,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (!p_initializer && codegen.stack_identifiers.has(identifier)) { int pos = codegen.stack_identifiers[identifier]; - return pos | (GDFunction::ADDR_TYPE_STACK_VARIABLE << GDFunction::ADDR_BITS); + return pos | (GDScriptFunction::ADDR_TYPE_STACK_VARIABLE << GDScriptFunction::ADDR_BITS); } //TRY MEMBERS! if (!codegen.function_node || !codegen.function_node->_static) { @@ -206,7 +207,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (codegen.script->member_indices.has(identifier)) { int idx = codegen.script->member_indices[identifier].index; - return idx | (GDFunction::ADDR_TYPE_MEMBER << GDFunction::ADDR_BITS); //argument (stack root) + return idx | (GDScriptFunction::ADDR_TYPE_MEMBER << GDScriptFunction::ADDR_BITS); //argument (stack root) } } @@ -216,14 +217,14 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr while (owner) { GDScript *scr = owner; - GDNativeClass *nc = NULL; + GDScriptNativeClass *nc = NULL; while (scr) { if (scr->constants.has(identifier)) { //int idx=scr->constants[identifier]; int idx = codegen.get_name_map_pos(identifier); - return idx | (GDFunction::ADDR_TYPE_CLASS_CONSTANT << GDFunction::ADDR_BITS); //argument (stack root) + return idx | (GDScriptFunction::ADDR_TYPE_CLASS_CONSTANT << GDScriptFunction::ADDR_BITS); //argument (stack root) } if (scr->native.is_valid()) nc = scr->native.ptr(); @@ -249,7 +250,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr idx = codegen.constant_map[key]; } - return idx | (GDFunction::ADDR_TYPE_LOCAL_CONSTANT << GDFunction::ADDR_BITS); //make it a local constant (faster access) + return idx | (GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT << GDScriptFunction::ADDR_BITS); //make it a local constant (faster access) } } @@ -261,14 +262,14 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (codegen.script->subclasses.has(identifier)) { //same with a subclass, make it a local constant. int idx = codegen.get_constant_pos(codegen.script->subclasses[identifier]); - return idx|(GDFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDFunction::ADDR_BITS); //make it a local constant (faster access) + return idx|(GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT<<GDScriptFunction::ADDR_BITS); //make it a local constant (faster access) }*/ if (GDScriptLanguage::get_singleton()->get_global_map().has(identifier)) { int idx = GDScriptLanguage::get_singleton()->get_global_map()[identifier]; - return idx | (GDFunction::ADDR_TYPE_GLOBAL << GDFunction::ADDR_BITS); //argument (stack root) + return idx | (GDScriptFunction::ADDR_TYPE_GLOBAL << GDScriptFunction::ADDR_BITS); //argument (stack root) } //not found, error @@ -278,9 +279,9 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr return -1; } break; - case GDParser::Node::TYPE_CONSTANT: { + case GDScriptParser::Node::TYPE_CONSTANT: { //return constant - const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode *>(p_expression); + const GDScriptParser::ConstantNode *cn = static_cast<const GDScriptParser::ConstantNode *>(p_expression); int idx; @@ -293,20 +294,20 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr idx = codegen.constant_map[cn->value]; } - return idx | (GDFunction::ADDR_TYPE_LOCAL_CONSTANT << GDFunction::ADDR_BITS); //argument (stack root) + return idx | (GDScriptFunction::ADDR_TYPE_LOCAL_CONSTANT << GDScriptFunction::ADDR_BITS); //argument (stack root) } break; - case GDParser::Node::TYPE_SELF: { + case GDScriptParser::Node::TYPE_SELF: { //return constant if (codegen.function_node && codegen.function_node->_static) { _set_error("'self' not present in static function!", p_expression); return -1; } - return (GDFunction::ADDR_TYPE_SELF << GDFunction::ADDR_BITS); + return (GDScriptFunction::ADDR_TYPE_SELF << GDScriptFunction::ADDR_BITS); } break; - case GDParser::Node::TYPE_ARRAY: { + case GDScriptParser::Node::TYPE_ARRAY: { - const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode *>(p_expression); + const GDScriptParser::ArrayNode *an = static_cast<const GDScriptParser::ArrayNode *>(p_expression); Vector<int> values; int slevel = p_stack_level; @@ -316,7 +317,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int ret = _parse_expression(codegen, an->elements[i], slevel); if (ret < 0) return ret; - if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (ret & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -324,20 +325,20 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr values.push_back(ret); } - codegen.opcodes.push_back(GDFunction::OPCODE_CONSTRUCT_ARRAY); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_CONSTRUCT_ARRAY); codegen.opcodes.push_back(values.size()); for (int i = 0; i < values.size(); i++) codegen.opcodes.push_back(values[i]); - int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); + int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode codegen.alloc_stack(p_stack_level); return dst_addr; } break; - case GDParser::Node::TYPE_DICTIONARY: { + case GDScriptParser::Node::TYPE_DICTIONARY: { - const GDParser::DictionaryNode *dn = static_cast<const GDParser::DictionaryNode *>(p_expression); + const GDScriptParser::DictionaryNode *dn = static_cast<const GDScriptParser::DictionaryNode *>(p_expression); Vector<int> values; int slevel = p_stack_level; @@ -347,7 +348,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int ret = _parse_expression(codegen, dn->elements[i].key, slevel); if (ret < 0) return ret; - if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (ret & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -357,7 +358,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr ret = _parse_expression(codegen, dn->elements[i].value, slevel); if (ret < 0) return ret; - if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (ret & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -365,29 +366,29 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr values.push_back(ret); } - codegen.opcodes.push_back(GDFunction::OPCODE_CONSTRUCT_DICTIONARY); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_CONSTRUCT_DICTIONARY); codegen.opcodes.push_back(dn->elements.size()); for (int i = 0; i < values.size(); i++) codegen.opcodes.push_back(values[i]); - int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); + int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode codegen.alloc_stack(p_stack_level); return dst_addr; } break; - case GDParser::Node::TYPE_OPERATOR: { + case GDScriptParser::Node::TYPE_OPERATOR: { //hell breaks loose - const GDParser::OperatorNode *on = static_cast<const GDParser::OperatorNode *>(p_expression); + const GDScriptParser::OperatorNode *on = static_cast<const GDScriptParser::OperatorNode *>(p_expression); switch (on->op) { //call/constructor operator - case GDParser::OperatorNode::OP_PARENT_CALL: { + case GDScriptParser::OperatorNode::OP_PARENT_CALL: { ERR_FAIL_COND_V(on->arguments.size() < 1, -1); - const GDParser::IdentifierNode *in = (const GDParser::IdentifierNode *)on->arguments[0]; + const GDScriptParser::IdentifierNode *in = (const GDScriptParser::IdentifierNode *)on->arguments[0]; Vector<int> arguments; int slevel = p_stack_level; @@ -396,7 +397,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; - if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (ret & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -404,7 +405,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr } //push call bytecode - codegen.opcodes.push_back(GDFunction::OPCODE_CALL_SELF_BASE); // basic type constructor + codegen.opcodes.push_back(GDScriptFunction::OPCODE_CALL_SELF_BASE); // basic type constructor codegen.opcodes.push_back(codegen.get_name_map_pos(in->name)); //instance codegen.opcodes.push_back(arguments.size()); //argument count @@ -413,13 +414,13 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr codegen.opcodes.push_back(arguments[i]); //arguments } break; - case GDParser::OperatorNode::OP_CALL: { + case GDScriptParser::OperatorNode::OP_CALL: { - if (on->arguments[0]->type == GDParser::Node::TYPE_TYPE) { + if (on->arguments[0]->type == GDScriptParser::Node::TYPE_TYPE) { //construct a basic type ERR_FAIL_COND_V(on->arguments.size() < 1, -1); - const GDParser::TypeNode *tn = (const GDParser::TypeNode *)on->arguments[0]; + const GDScriptParser::TypeNode *tn = (const GDScriptParser::TypeNode *)on->arguments[0]; int vtype = tn->vtype; Vector<int> arguments; @@ -429,7 +430,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; - if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (ret & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -437,14 +438,14 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr } //push call bytecode - codegen.opcodes.push_back(GDFunction::OPCODE_CONSTRUCT); // basic type constructor + codegen.opcodes.push_back(GDScriptFunction::OPCODE_CONSTRUCT); // basic type constructor codegen.opcodes.push_back(vtype); //instance codegen.opcodes.push_back(arguments.size()); //argument count codegen.alloc_call(arguments.size()); for (int i = 0; i < arguments.size(); i++) codegen.opcodes.push_back(arguments[i]); //arguments - } else if (on->arguments[0]->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) { + } else if (on->arguments[0]->type == GDScriptParser::Node::TYPE_BUILT_IN_FUNCTION) { //built in function ERR_FAIL_COND_V(on->arguments.size() < 1, -1); @@ -457,7 +458,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (ret < 0) return ret; - if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (ret & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -465,8 +466,8 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr arguments.push_back(ret); } - codegen.opcodes.push_back(GDFunction::OPCODE_CALL_BUILT_IN); - codegen.opcodes.push_back(static_cast<const GDParser::BuiltInFunctionNode *>(on->arguments[0])->function); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_CALL_BUILT_IN); + codegen.opcodes.push_back(static_cast<const GDScriptParser::BuiltInFunctionNode *>(on->arguments[0])->function); codegen.opcodes.push_back(on->arguments.size() - 1); codegen.alloc_call(on->arguments.size() - 1); for (int i = 0; i < arguments.size(); i++) @@ -476,9 +477,9 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr //regular function ERR_FAIL_COND_V(on->arguments.size() < 2, -1); - const GDParser::Node *instance = on->arguments[0]; + const GDScriptParser::Node *instance = on->arguments[0]; - if (instance->type == GDParser::Node::TYPE_SELF) { + if (instance->type == GDScriptParser::Node::TYPE_SELF) { //room for optimization } @@ -489,16 +490,16 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int ret; - if (i == 0 && on->arguments[i]->type == GDParser::Node::TYPE_SELF && codegen.function_node && codegen.function_node->_static) { + if (i == 0 && on->arguments[i]->type == GDScriptParser::Node::TYPE_SELF && codegen.function_node && codegen.function_node->_static) { //static call to self - ret = (GDFunction::ADDR_TYPE_CLASS << GDFunction::ADDR_BITS); + ret = (GDScriptFunction::ADDR_TYPE_CLASS << GDScriptFunction::ADDR_BITS); } else if (i == 1) { - if (on->arguments[i]->type != GDParser::Node::TYPE_IDENTIFIER) { + if (on->arguments[i]->type != GDScriptParser::Node::TYPE_IDENTIFIER) { _set_error("Attempt to call a non-identifier.", on); return -1; } - GDParser::IdentifierNode *id = static_cast<GDParser::IdentifierNode *>(on->arguments[i]); + GDScriptParser::IdentifierNode *id = static_cast<GDScriptParser::IdentifierNode *>(on->arguments[i]); ret = codegen.get_name_map_pos(id->name); } else { @@ -506,7 +507,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; - if (ret & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (ret & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -514,14 +515,14 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr arguments.push_back(ret); } - codegen.opcodes.push_back(p_root ? GDFunction::OPCODE_CALL : GDFunction::OPCODE_CALL_RETURN); // perform operator + codegen.opcodes.push_back(p_root ? GDScriptFunction::OPCODE_CALL : GDScriptFunction::OPCODE_CALL_RETURN); // perform operator codegen.opcodes.push_back(on->arguments.size() - 2); codegen.alloc_call(on->arguments.size() - 2); for (int i = 0; i < arguments.size(); i++) codegen.opcodes.push_back(arguments[i]); } } break; - case GDParser::OperatorNode::OP_YIELD: { + case GDScriptParser::OperatorNode::OP_YIELD: { ERR_FAIL_COND_V(on->arguments.size() && on->arguments.size() != 2, -1); @@ -532,7 +533,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int ret = _parse_expression(codegen, on->arguments[i], slevel); if (ret < 0) return ret; - if (ret & (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS)) { + if (ret & (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS)) { slevel++; codegen.alloc_stack(slevel); } @@ -540,22 +541,22 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr } //push call bytecode - codegen.opcodes.push_back(arguments.size() == 0 ? GDFunction::OPCODE_YIELD : GDFunction::OPCODE_YIELD_SIGNAL); // basic type constructor + codegen.opcodes.push_back(arguments.size() == 0 ? GDScriptFunction::OPCODE_YIELD : GDScriptFunction::OPCODE_YIELD_SIGNAL); // basic type constructor for (int i = 0; i < arguments.size(); i++) codegen.opcodes.push_back(arguments[i]); //arguments - codegen.opcodes.push_back(GDFunction::OPCODE_YIELD_RESUME); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_YIELD_RESUME); //next will be where to place the result :) } break; //indexing operator - case GDParser::OperatorNode::OP_INDEX: - case GDParser::OperatorNode::OP_INDEX_NAMED: { + case GDScriptParser::OperatorNode::OP_INDEX: + case GDScriptParser::OperatorNode::OP_INDEX_NAMED: { ERR_FAIL_COND_V(on->arguments.size() != 2, -1); int slevel = p_stack_level; - bool named = (on->op == GDParser::OperatorNode::OP_INDEX_NAMED); + bool named = (on->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED); int from = _parse_expression(codegen, on->arguments[0], slevel); if (from < 0) @@ -563,14 +564,14 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int index; if (named) { - if (on->arguments[0]->type == GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) { + if (on->arguments[0]->type == GDScriptParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) { - GDParser::IdentifierNode *identifier = static_cast<GDParser::IdentifierNode *>(on->arguments[1]); + GDScriptParser::IdentifierNode *identifier = static_cast<GDScriptParser::IdentifierNode *>(on->arguments[1]); const Map<StringName, GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(identifier->name); #ifdef DEBUG_ENABLED if (MI && MI->get().getter == codegen.function_node->name) { - String n = static_cast<GDParser::IdentifierNode *>(on->arguments[1])->name; + String n = static_cast<GDScriptParser::IdentifierNode *>(on->arguments[1])->name; _set_error("Must use '" + n + "' instead of 'self." + n + "' in getter.", on); return -1; } @@ -578,23 +579,23 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (MI && MI->get().getter == "") { // Faster than indexing self (as if no self. had been used) - return (MI->get().index) | (GDFunction::ADDR_TYPE_MEMBER << GDFunction::ADDR_BITS); + return (MI->get().index) | (GDScriptFunction::ADDR_TYPE_MEMBER << GDScriptFunction::ADDR_BITS); } } - index = codegen.get_name_map_pos(static_cast<GDParser::IdentifierNode *>(on->arguments[1])->name); + index = codegen.get_name_map_pos(static_cast<GDScriptParser::IdentifierNode *>(on->arguments[1])->name); } else { - if (on->arguments[1]->type == GDParser::Node::TYPE_CONSTANT && static_cast<const GDParser::ConstantNode *>(on->arguments[1])->value.get_type() == Variant::STRING) { + if (on->arguments[1]->type == GDScriptParser::Node::TYPE_CONSTANT && static_cast<const GDScriptParser::ConstantNode *>(on->arguments[1])->value.get_type() == Variant::STRING) { //also, somehow, named (speed up anyway) - StringName name = static_cast<const GDParser::ConstantNode *>(on->arguments[1])->value; + StringName name = static_cast<const GDScriptParser::ConstantNode *>(on->arguments[1])->value; index = codegen.get_name_map_pos(name); named = true; } else { //regular indexing - if (from & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (from & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -605,19 +606,19 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr } } - codegen.opcodes.push_back(named ? GDFunction::OPCODE_GET_NAMED : GDFunction::OPCODE_GET); // perform operator + codegen.opcodes.push_back(named ? GDScriptFunction::OPCODE_GET_NAMED : GDScriptFunction::OPCODE_GET); // perform operator codegen.opcodes.push_back(from); // argument 1 codegen.opcodes.push_back(index); // argument 2 (unary only takes one parameter) } break; - case GDParser::OperatorNode::OP_AND: { + case GDScriptParser::OperatorNode::OP_AND: { // AND operator with early out on failure int res = _parse_expression(codegen, on->arguments[0], p_stack_level); if (res < 0) return res; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(res); int jump_fail_pos = codegen.opcodes.size(); codegen.opcodes.push_back(0); @@ -626,31 +627,31 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (res < 0) return res; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(res); int jump_fail_pos2 = codegen.opcodes.size(); codegen.opcodes.push_back(0); codegen.alloc_stack(p_stack_level); //it will be used.. - codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN_TRUE); - codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN_TRUE); + codegen.opcodes.push_back(p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(codegen.opcodes.size() + 3); codegen.opcodes[jump_fail_pos] = codegen.opcodes.size(); codegen.opcodes[jump_fail_pos2] = codegen.opcodes.size(); - codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN_FALSE); - codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); - return p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS; + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN_FALSE); + codegen.opcodes.push_back(p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); + return p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS; } break; - case GDParser::OperatorNode::OP_OR: { + case GDScriptParser::OperatorNode::OP_OR: { // OR operator with early out on success int res = _parse_expression(codegen, on->arguments[0], p_stack_level); if (res < 0) return res; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF); codegen.opcodes.push_back(res); int jump_success_pos = codegen.opcodes.size(); codegen.opcodes.push_back(0); @@ -659,32 +660,32 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (res < 0) return res; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF); codegen.opcodes.push_back(res); int jump_success_pos2 = codegen.opcodes.size(); codegen.opcodes.push_back(0); codegen.alloc_stack(p_stack_level); //it will be used.. - codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN_FALSE); - codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN_FALSE); + codegen.opcodes.push_back(p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(codegen.opcodes.size() + 3); codegen.opcodes[jump_success_pos] = codegen.opcodes.size(); codegen.opcodes[jump_success_pos2] = codegen.opcodes.size(); - codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN_TRUE); - codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); - return p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS; + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN_TRUE); + codegen.opcodes.push_back(p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); + return p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS; } break; // ternary operators - case GDParser::OperatorNode::OP_TERNARY_IF: { + case GDScriptParser::OperatorNode::OP_TERNARY_IF: { // x IF a ELSE y operator with early out on failure int res = _parse_expression(codegen, on->arguments[0], p_stack_level); if (res < 0) return res; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(res); int jump_fail_pos = codegen.opcodes.size(); codegen.opcodes.push_back(0); @@ -694,10 +695,10 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr return res; codegen.alloc_stack(p_stack_level); //it will be used.. - codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN); - codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN); + codegen.opcodes.push_back(p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(res); - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); int jump_past_pos = codegen.opcodes.size(); codegen.opcodes.push_back(0); @@ -706,116 +707,116 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (res < 0) return res; - codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN); - codegen.opcodes.push_back(p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN); + codegen.opcodes.push_back(p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(res); codegen.opcodes[jump_past_pos] = codegen.opcodes.size(); - return p_stack_level | GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS; + return p_stack_level | GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS; } break; //unary operators - case GDParser::OperatorNode::OP_NEG: { + case GDScriptParser::OperatorNode::OP_NEG: { if (!_create_unary_operator(codegen, on, Variant::OP_NEGATE, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_NOT: { + case GDScriptParser::OperatorNode::OP_NOT: { if (!_create_unary_operator(codegen, on, Variant::OP_NOT, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_BIT_INVERT: { + case GDScriptParser::OperatorNode::OP_BIT_INVERT: { if (!_create_unary_operator(codegen, on, Variant::OP_BIT_NEGATE, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_PREINC: { + case GDScriptParser::OperatorNode::OP_PREINC: { } break; //? - case GDParser::OperatorNode::OP_PREDEC: { + case GDScriptParser::OperatorNode::OP_PREDEC: { } break; - case GDParser::OperatorNode::OP_INC: { + case GDScriptParser::OperatorNode::OP_INC: { } break; - case GDParser::OperatorNode::OP_DEC: { + case GDScriptParser::OperatorNode::OP_DEC: { } break; //binary operators (in precedence order) - case GDParser::OperatorNode::OP_IN: { + case GDScriptParser::OperatorNode::OP_IN: { if (!_create_binary_operator(codegen, on, Variant::OP_IN, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_EQUAL: { + case GDScriptParser::OperatorNode::OP_EQUAL: { if (!_create_binary_operator(codegen, on, Variant::OP_EQUAL, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_NOT_EQUAL: { + case GDScriptParser::OperatorNode::OP_NOT_EQUAL: { if (!_create_binary_operator(codegen, on, Variant::OP_NOT_EQUAL, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_LESS: { + case GDScriptParser::OperatorNode::OP_LESS: { if (!_create_binary_operator(codegen, on, Variant::OP_LESS, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_LESS_EQUAL: { + case GDScriptParser::OperatorNode::OP_LESS_EQUAL: { if (!_create_binary_operator(codegen, on, Variant::OP_LESS_EQUAL, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_GREATER: { + case GDScriptParser::OperatorNode::OP_GREATER: { if (!_create_binary_operator(codegen, on, Variant::OP_GREATER, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_GREATER_EQUAL: { + case GDScriptParser::OperatorNode::OP_GREATER_EQUAL: { if (!_create_binary_operator(codegen, on, Variant::OP_GREATER_EQUAL, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_ADD: { + case GDScriptParser::OperatorNode::OP_ADD: { if (!_create_binary_operator(codegen, on, Variant::OP_ADD, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_SUB: { + case GDScriptParser::OperatorNode::OP_SUB: { if (!_create_binary_operator(codegen, on, Variant::OP_SUBTRACT, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_MUL: { + case GDScriptParser::OperatorNode::OP_MUL: { if (!_create_binary_operator(codegen, on, Variant::OP_MULTIPLY, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_DIV: { + case GDScriptParser::OperatorNode::OP_DIV: { if (!_create_binary_operator(codegen, on, Variant::OP_DIVIDE, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_MOD: { + case GDScriptParser::OperatorNode::OP_MOD: { if (!_create_binary_operator(codegen, on, Variant::OP_MODULE, p_stack_level)) return -1; } break; - //case GDParser::OperatorNode::OP_SHIFT_LEFT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_LEFT,p_stack_level)) return -1;} break; - //case GDParser::OperatorNode::OP_SHIFT_RIGHT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_RIGHT,p_stack_level)) return -1;} break; - case GDParser::OperatorNode::OP_BIT_AND: { + //case GDScriptParser::OperatorNode::OP_SHIFT_LEFT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_LEFT,p_stack_level)) return -1;} break; + //case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT: { if (!_create_binary_operator(codegen,on,Variant::OP_SHIFT_RIGHT,p_stack_level)) return -1;} break; + case GDScriptParser::OperatorNode::OP_BIT_AND: { if (!_create_binary_operator(codegen, on, Variant::OP_BIT_AND, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_BIT_OR: { + case GDScriptParser::OperatorNode::OP_BIT_OR: { if (!_create_binary_operator(codegen, on, Variant::OP_BIT_OR, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_BIT_XOR: { + case GDScriptParser::OperatorNode::OP_BIT_XOR: { if (!_create_binary_operator(codegen, on, Variant::OP_BIT_XOR, p_stack_level)) return -1; } break; //shift - case GDParser::OperatorNode::OP_SHIFT_LEFT: { + case GDScriptParser::OperatorNode::OP_SHIFT_LEFT: { if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_LEFT, p_stack_level)) return -1; } break; - case GDParser::OperatorNode::OP_SHIFT_RIGHT: { + case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT: { if (!_create_binary_operator(codegen, on, Variant::OP_SHIFT_RIGHT, p_stack_level)) return -1; } break; //assignment operators - case GDParser::OperatorNode::OP_ASSIGN_ADD: - case GDParser::OperatorNode::OP_ASSIGN_SUB: - case GDParser::OperatorNode::OP_ASSIGN_MUL: - case GDParser::OperatorNode::OP_ASSIGN_DIV: - case GDParser::OperatorNode::OP_ASSIGN_MOD: - case GDParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: - case GDParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: - case GDParser::OperatorNode::OP_ASSIGN_BIT_AND: - case GDParser::OperatorNode::OP_ASSIGN_BIT_OR: - case GDParser::OperatorNode::OP_ASSIGN_BIT_XOR: - case GDParser::OperatorNode::OP_INIT_ASSIGN: - case GDParser::OperatorNode::OP_ASSIGN: { + case GDScriptParser::OperatorNode::OP_ASSIGN_ADD: + case GDScriptParser::OperatorNode::OP_ASSIGN_SUB: + case GDScriptParser::OperatorNode::OP_ASSIGN_MUL: + case GDScriptParser::OperatorNode::OP_ASSIGN_DIV: + case GDScriptParser::OperatorNode::OP_ASSIGN_MOD: + case GDScriptParser::OperatorNode::OP_ASSIGN_SHIFT_LEFT: + case GDScriptParser::OperatorNode::OP_ASSIGN_SHIFT_RIGHT: + case GDScriptParser::OperatorNode::OP_ASSIGN_BIT_AND: + case GDScriptParser::OperatorNode::OP_ASSIGN_BIT_OR: + case GDScriptParser::OperatorNode::OP_ASSIGN_BIT_XOR: + case GDScriptParser::OperatorNode::OP_INIT_ASSIGN: + case GDScriptParser::OperatorNode::OP_ASSIGN: { ERR_FAIL_COND_V(on->arguments.size() != 2, -1); - if (on->arguments[0]->type == GDParser::Node::TYPE_OPERATOR && (static_cast<GDParser::OperatorNode *>(on->arguments[0])->op == GDParser::OperatorNode::OP_INDEX || static_cast<GDParser::OperatorNode *>(on->arguments[0])->op == GDParser::OperatorNode::OP_INDEX_NAMED)) { + if (on->arguments[0]->type == GDScriptParser::Node::TYPE_OPERATOR && (static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX || static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED)) { //SET (chained) MODE!! #ifdef DEBUG_ENABLED - if (static_cast<GDParser::OperatorNode *>(on->arguments[0])->op == GDParser::OperatorNode::OP_INDEX_NAMED) { - const GDParser::OperatorNode *inon = static_cast<GDParser::OperatorNode *>(on->arguments[0]); + if (static_cast<GDScriptParser::OperatorNode *>(on->arguments[0])->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED) { + const GDScriptParser::OperatorNode *inon = static_cast<GDScriptParser::OperatorNode *>(on->arguments[0]); - if (inon->arguments[0]->type == GDParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) { + if (inon->arguments[0]->type == GDScriptParser::Node::TYPE_SELF && codegen.script && codegen.function_node && !codegen.function_node->_static) { - const Map<StringName, GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(static_cast<GDParser::IdentifierNode *>(inon->arguments[1])->name); + const Map<StringName, GDScript::MemberInfo>::Element *MI = codegen.script->member_indices.find(static_cast<GDScriptParser::IdentifierNode *>(inon->arguments[1])->name); if (MI && MI->get().setter == codegen.function_node->name) { - String n = static_cast<GDParser::IdentifierNode *>(inon->arguments[1])->name; + String n = static_cast<GDScriptParser::IdentifierNode *>(inon->arguments[1])->name; _set_error("Must use '" + n + "' instead of 'self." + n + "' in setter.", inon); return -1; } @@ -825,34 +826,34 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int slevel = p_stack_level; - GDParser::OperatorNode *op = static_cast<GDParser::OperatorNode *>(on->arguments[0]); + GDScriptParser::OperatorNode *op = static_cast<GDScriptParser::OperatorNode *>(on->arguments[0]); /* Find chain of sets */ StringName assign_property; - List<GDParser::OperatorNode *> chain; + List<GDScriptParser::OperatorNode *> chain; { //create get/set chain - GDParser::OperatorNode *n = op; + GDScriptParser::OperatorNode *n = op; while (true) { chain.push_back(n); - if (n->arguments[0]->type != GDParser::Node::TYPE_OPERATOR) { + if (n->arguments[0]->type != GDScriptParser::Node::TYPE_OPERATOR) { //check for a built-in property - if (n->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER) { + if (n->arguments[0]->type == GDScriptParser::Node::TYPE_IDENTIFIER) { - GDParser::IdentifierNode *identifier = static_cast<GDParser::IdentifierNode *>(n->arguments[0]); + GDScriptParser::IdentifierNode *identifier = static_cast<GDScriptParser::IdentifierNode *>(n->arguments[0]); if (_is_class_member_property(codegen, identifier->name)) { assign_property = identifier->name; } } break; } - n = static_cast<GDParser::OperatorNode *>(n->arguments[0]); - if (n->op != GDParser::OperatorNode::OP_INDEX && n->op != GDParser::OperatorNode::OP_INDEX_NAMED) + n = static_cast<GDScriptParser::OperatorNode *>(n->arguments[0]); + if (n->op != GDScriptParser::OperatorNode::OP_INDEX && n->op != GDScriptParser::OperatorNode::OP_INDEX_NAMED) break; } } @@ -867,7 +868,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr //print_line("retval: "+itos(retval)); - if (retval & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (retval & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -881,30 +882,30 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr // in Node2D setchain.push_back(prev_pos); setchain.push_back(codegen.get_name_map_pos(assign_property)); - setchain.push_back(GDFunction::OPCODE_SET_MEMBER); + setchain.push_back(GDScriptFunction::OPCODE_SET_MEMBER); } - for (List<GDParser::OperatorNode *>::Element *E = chain.back(); E; E = E->prev()) { + for (List<GDScriptParser::OperatorNode *>::Element *E = chain.back(); E; E = E->prev()) { if (E == chain.front()) //ignore first break; - bool named = E->get()->op == GDParser::OperatorNode::OP_INDEX_NAMED; + bool named = E->get()->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED; int key_idx; if (named) { - key_idx = codegen.get_name_map_pos(static_cast<const GDParser::IdentifierNode *>(E->get()->arguments[1])->name); + key_idx = codegen.get_name_map_pos(static_cast<const GDScriptParser::IdentifierNode *>(E->get()->arguments[1])->name); //printf("named key %x\n",key_idx); } else { - if (prev_pos & (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS)) { + if (prev_pos & (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS)) { slevel++; codegen.alloc_stack(slevel); } - GDParser::Node *key = E->get()->arguments[1]; + GDScriptParser::Node *key = E->get()->arguments[1]; key_idx = _parse_expression(codegen, key, slevel); //printf("expr key %x\n",key_idx); @@ -914,12 +915,12 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (key_idx < 0) //error return key_idx; - codegen.opcodes.push_back(named ? GDFunction::OPCODE_GET_NAMED : GDFunction::OPCODE_GET); + codegen.opcodes.push_back(named ? GDScriptFunction::OPCODE_GET_NAMED : GDScriptFunction::OPCODE_GET); codegen.opcodes.push_back(prev_pos); codegen.opcodes.push_back(key_idx); slevel++; codegen.alloc_stack(slevel); - int dst_pos = (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) | slevel; + int dst_pos = (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) | slevel; codegen.opcodes.push_back(dst_pos); @@ -928,7 +929,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr setchain.push_back(dst_pos); setchain.push_back(key_idx); setchain.push_back(prev_pos); - setchain.push_back(named ? GDFunction::OPCODE_SET_NAMED : GDFunction::OPCODE_SET); + setchain.push_back(named ? GDScriptFunction::OPCODE_SET_NAMED : GDScriptFunction::OPCODE_SET); prev_pos = dst_pos; } @@ -938,9 +939,9 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr int set_index; bool named = false; - if (static_cast<const GDParser::OperatorNode *>(op)->op == GDParser::OperatorNode::OP_INDEX_NAMED) { + if (static_cast<const GDScriptParser::OperatorNode *>(op)->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED) { - set_index = codegen.get_name_map_pos(static_cast<const GDParser::IdentifierNode *>(op->arguments[1])->name); + set_index = codegen.get_name_map_pos(static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[1])->name); named = true; } else { @@ -951,7 +952,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (set_index < 0) //error return set_index; - if (set_index & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (set_index & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -960,7 +961,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (set_value < 0) //error return set_value; - codegen.opcodes.push_back(named ? GDFunction::OPCODE_SET_NAMED : GDFunction::OPCODE_SET); + codegen.opcodes.push_back(named ? GDScriptFunction::OPCODE_SET_NAMED : GDScriptFunction::OPCODE_SET); codegen.opcodes.push_back(prev_pos); codegen.opcodes.push_back(set_index); codegen.opcodes.push_back(set_value); @@ -972,7 +973,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr return retval; - } else if (on->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER && _is_class_member_property(codegen, static_cast<GDParser::IdentifierNode *>(on->arguments[0])->name)) { + } else if (on->arguments[0]->type == GDScriptParser::Node::TYPE_IDENTIFIER && _is_class_member_property(codegen, static_cast<GDScriptParser::IdentifierNode *>(on->arguments[0])->name)) { //assignment to member property int slevel = p_stack_level; @@ -981,24 +982,24 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (src_address < 0) return -1; - StringName name = static_cast<GDParser::IdentifierNode *>(on->arguments[0])->name; + StringName name = static_cast<GDScriptParser::IdentifierNode *>(on->arguments[0])->name; - codegen.opcodes.push_back(GDFunction::OPCODE_SET_MEMBER); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_SET_MEMBER); codegen.opcodes.push_back(codegen.get_name_map_pos(name)); codegen.opcodes.push_back(src_address); - return GDFunction::ADDR_TYPE_NIL << GDFunction::ADDR_BITS; + return GDScriptFunction::ADDR_TYPE_NIL << GDScriptFunction::ADDR_BITS; } else { //REGULAR ASSIGNMENT MODE!! int slevel = p_stack_level; - int dst_address_a = _parse_expression(codegen, on->arguments[0], slevel, false, on->op == GDParser::OperatorNode::OP_INIT_ASSIGN); + int dst_address_a = _parse_expression(codegen, on->arguments[0], slevel, false, on->op == GDScriptParser::OperatorNode::OP_INIT_ASSIGN); if (dst_address_a < 0) return -1; - if (dst_address_a & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) { + if (dst_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) { slevel++; codegen.alloc_stack(slevel); } @@ -1007,14 +1008,14 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (src_address_b < 0) return -1; - codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN); // perform operator + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN); // perform operator codegen.opcodes.push_back(dst_address_a); // argument 1 codegen.opcodes.push_back(src_address_b); // argument 2 (unary only takes one parameter) return dst_address_a; //if anything, returns wathever was assigned or correct stack position } } break; - case GDParser::OperatorNode::OP_IS: { + case GDScriptParser::OperatorNode::OP_IS: { ERR_FAIL_COND_V(on->arguments.size() != 2, false); @@ -1024,14 +1025,14 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr if (src_address_a < 0) return -1; - if (src_address_a & GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) + if (src_address_a & GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) slevel++; //uses stack for return, increase stack int src_address_b = _parse_expression(codegen, on->arguments[1], slevel); if (src_address_b < 0) return -1; - codegen.opcodes.push_back(GDFunction::OPCODE_EXTENDS_TEST); // perform operator + codegen.opcodes.push_back(GDScriptFunction::OPCODE_EXTENDS_TEST); // perform operator codegen.opcodes.push_back(src_address_a); // argument 1 codegen.opcodes.push_back(src_address_b); // argument 2 (unary only takes one parameter) @@ -1044,7 +1045,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr } break; } - int dst_addr = (p_stack_level) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); + int dst_addr = (p_stack_level) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.opcodes.push_back(dst_addr); // append the stack level as destination address of the opcode codegen.alloc_stack(p_stack_level); return dst_addr; @@ -1060,7 +1061,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr ERR_FAIL_V(-1); //unreachable code } -Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_block, int p_stack_level, int p_break_addr, int p_continue_addr) { +Error GDScriptCompiler::_parse_block(CodeGen &codegen, const GDScriptParser::BlockNode *p_block, int p_stack_level, int p_break_addr, int p_continue_addr) { codegen.push_stack_identifiers(); int new_identifiers = 0; @@ -1068,28 +1069,28 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl for (int i = 0; i < p_block->statements.size(); i++) { - const GDParser::Node *s = p_block->statements[i]; + const GDScriptParser::Node *s = p_block->statements[i]; switch (s->type) { - case GDParser::Node::TYPE_NEWLINE: { + case GDScriptParser::Node::TYPE_NEWLINE: { #ifdef DEBUG_ENABLED - const GDParser::NewLineNode *nl = static_cast<const GDParser::NewLineNode *>(s); - codegen.opcodes.push_back(GDFunction::OPCODE_LINE); + const GDScriptParser::NewLineNode *nl = static_cast<const GDScriptParser::NewLineNode *>(s); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_LINE); codegen.opcodes.push_back(nl->line); codegen.current_line = nl->line; #endif } break; - case GDParser::Node::TYPE_CONTROL_FLOW: { + case GDScriptParser::Node::TYPE_CONTROL_FLOW: { // try subblocks - const GDParser::ControlFlowNode *cf = static_cast<const GDParser::ControlFlowNode *>(s); + const GDScriptParser::ControlFlowNode *cf = static_cast<const GDScriptParser::ControlFlowNode *>(s); switch (cf->cf_type) { - case GDParser::ControlFlowNode::CF_MATCH: { - GDParser::MatchNode *match = cf->match; + case GDScriptParser::ControlFlowNode::CF_MATCH: { + GDScriptParser::MatchNode *match = cf->match; - GDParser::IdentifierNode *id = memnew(GDParser::IdentifierNode); + GDScriptParser::IdentifierNode *id = memnew(GDScriptParser::IdentifierNode); id->name = "#match_value"; // var #match_value @@ -1098,8 +1099,8 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl codegen.alloc_stack(p_stack_level); new_identifiers++; - GDParser::OperatorNode *op = memnew(GDParser::OperatorNode); - op->op = GDParser::OperatorNode::OP_ASSIGN; + GDScriptParser::OperatorNode *op = memnew(GDScriptParser::OperatorNode); + op->op = GDScriptParser::OperatorNode::OP_ASSIGN; op->arguments.push_back(id); op->arguments.push_back(match->val_to_match); @@ -1109,14 +1110,14 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl } // break address - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(codegen.opcodes.size() + 3); int break_addr = codegen.opcodes.size(); - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(0); // break addr for (int j = 0; j < match->compiled_pattern_branches.size(); j++) { - GDParser::MatchNode::CompiledPatternBranch branch = match->compiled_pattern_branches[j]; + GDScriptParser::MatchNode::CompiledPatternBranch branch = match->compiled_pattern_branches[j]; // jump over continue // jump unconditionally @@ -1127,11 +1128,11 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl return ERR_PARSE_ERROR; } - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF); codegen.opcodes.push_back(ret); codegen.opcodes.push_back(codegen.opcodes.size() + 3); int continue_addr = codegen.opcodes.size(); - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(0); Error err = _parse_block(codegen, branch.body, p_stack_level, p_break_addr, continue_addr); @@ -1139,7 +1140,7 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl return ERR_PARSE_ERROR; } - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(break_addr); codegen.opcodes[continue_addr + 1] = codegen.opcodes.size(); @@ -1149,10 +1150,10 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl } break; - case GDParser::ControlFlowNode::CF_IF: { + case GDScriptParser::ControlFlowNode::CF_IF: { #ifdef DEBUG_ENABLED - codegen.opcodes.push_back(GDFunction::OPCODE_LINE); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_LINE); codegen.opcodes.push_back(cf->line); codegen.current_line = cf->line; #endif @@ -1160,7 +1161,7 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl if (ret < 0) return ERR_PARSE_ERROR; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(ret); int else_addr = codegen.opcodes.size(); codegen.opcodes.push_back(0); //temporary @@ -1171,7 +1172,7 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl if (cf->body_else) { - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); int end_addr = codegen.opcodes.size(); codegen.opcodes.push_back(0); codegen.opcodes[else_addr] = codegen.opcodes.size(); @@ -1187,42 +1188,42 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl } } break; - case GDParser::ControlFlowNode::CF_FOR: { + case GDScriptParser::ControlFlowNode::CF_FOR: { int slevel = p_stack_level; int iter_stack_pos = slevel; - int iterator_pos = (slevel++) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); - int counter_pos = (slevel++) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); - int container_pos = (slevel++) | (GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS); + int iterator_pos = (slevel++) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); + int counter_pos = (slevel++) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); + int container_pos = (slevel++) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS); codegen.alloc_stack(slevel); codegen.push_stack_identifiers(); - codegen.add_stack_identifier(static_cast<const GDParser::IdentifierNode *>(cf->arguments[0])->name, iter_stack_pos); + codegen.add_stack_identifier(static_cast<const GDScriptParser::IdentifierNode *>(cf->arguments[0])->name, iter_stack_pos); int ret = _parse_expression(codegen, cf->arguments[1], slevel, false); if (ret < 0) return ERR_COMPILATION_FAILED; //assign container - codegen.opcodes.push_back(GDFunction::OPCODE_ASSIGN); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSIGN); codegen.opcodes.push_back(container_pos); codegen.opcodes.push_back(ret); //begin loop - codegen.opcodes.push_back(GDFunction::OPCODE_ITERATE_BEGIN); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ITERATE_BEGIN); codegen.opcodes.push_back(counter_pos); codegen.opcodes.push_back(container_pos); codegen.opcodes.push_back(codegen.opcodes.size() + 4); codegen.opcodes.push_back(iterator_pos); - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); //skip code for next + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); //skip code for next codegen.opcodes.push_back(codegen.opcodes.size() + 8); //break loop int break_pos = codegen.opcodes.size(); - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); //skip code for next + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); //skip code for next codegen.opcodes.push_back(0); //skip code for next //next loop int continue_pos = codegen.opcodes.size(); - codegen.opcodes.push_back(GDFunction::OPCODE_ITERATE); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ITERATE); codegen.opcodes.push_back(counter_pos); codegen.opcodes.push_back(container_pos); codegen.opcodes.push_back(break_pos); @@ -1232,52 +1233,52 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl if (err) return err; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(continue_pos); codegen.opcodes[break_pos + 1] = codegen.opcodes.size(); codegen.pop_stack_identifiers(); } break; - case GDParser::ControlFlowNode::CF_WHILE: { + case GDScriptParser::ControlFlowNode::CF_WHILE: { - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(codegen.opcodes.size() + 3); int break_addr = codegen.opcodes.size(); - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(0); int continue_addr = codegen.opcodes.size(); int ret = _parse_expression(codegen, cf->arguments[0], p_stack_level, false); if (ret < 0) return ERR_PARSE_ERROR; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_IF_NOT); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_IF_NOT); codegen.opcodes.push_back(ret); codegen.opcodes.push_back(break_addr); Error err = _parse_block(codegen, cf->body, p_stack_level, break_addr, continue_addr); if (err) return err; - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(continue_addr); codegen.opcodes[break_addr + 1] = codegen.opcodes.size(); } break; - case GDParser::ControlFlowNode::CF_SWITCH: { + case GDScriptParser::ControlFlowNode::CF_SWITCH: { } break; - case GDParser::ControlFlowNode::CF_BREAK: { + case GDScriptParser::ControlFlowNode::CF_BREAK: { if (p_break_addr < 0) { _set_error("'break'' not within loop", cf); return ERR_COMPILATION_FAILED; } - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(p_break_addr); } break; - case GDParser::ControlFlowNode::CF_CONTINUE: { + case GDScriptParser::ControlFlowNode::CF_CONTINUE: { if (p_continue_addr < 0) { @@ -1285,11 +1286,11 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl return ERR_COMPILATION_FAILED; } - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP); codegen.opcodes.push_back(p_continue_addr); } break; - case GDParser::ControlFlowNode::CF_RETURN: { + case GDScriptParser::ControlFlowNode::CF_RETURN: { int ret; @@ -1301,38 +1302,38 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl } else { - ret = GDFunction::ADDR_TYPE_NIL << GDFunction::ADDR_BITS; + ret = GDScriptFunction::ADDR_TYPE_NIL << GDScriptFunction::ADDR_BITS; } - codegen.opcodes.push_back(GDFunction::OPCODE_RETURN); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_RETURN); codegen.opcodes.push_back(ret); } break; } } break; - case GDParser::Node::TYPE_ASSERT: { + case GDScriptParser::Node::TYPE_ASSERT: { #ifdef DEBUG_ENABLED // try subblocks - const GDParser::AssertNode *as = static_cast<const GDParser::AssertNode *>(s); + const GDScriptParser::AssertNode *as = static_cast<const GDScriptParser::AssertNode *>(s); int ret = _parse_expression(codegen, as->condition, p_stack_level, false); if (ret < 0) return ERR_PARSE_ERROR; - codegen.opcodes.push_back(GDFunction::OPCODE_ASSERT); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_ASSERT); codegen.opcodes.push_back(ret); #endif } break; - case GDParser::Node::TYPE_BREAKPOINT: { + case GDScriptParser::Node::TYPE_BREAKPOINT: { #ifdef DEBUG_ENABLED // try subblocks - codegen.opcodes.push_back(GDFunction::OPCODE_BREAKPOINT); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_BREAKPOINT); #endif } break; - case GDParser::Node::TYPE_LOCAL_VAR: { + case GDScriptParser::Node::TYPE_LOCAL_VAR: { - const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode *>(s); + const GDScriptParser::LocalVarNode *lv = static_cast<const GDScriptParser::LocalVarNode *>(s); if (_is_class_member_property(codegen, lv->name)) { _set_error("Name for local variable '" + String(lv->name) + "' can't shadow class property of the same name.", lv); @@ -1356,7 +1357,7 @@ Error GDCompiler::_parse_block(CodeGen &codegen, const GDParser::BlockNode *p_bl return OK; } -Error GDCompiler::_parse_function(GDScript *p_script, const GDParser::ClassNode *p_class, const GDParser::FunctionNode *p_func, bool p_for_ready) { +Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser::ClassNode *p_class, const GDScriptParser::FunctionNode *p_func, bool p_for_ready) { Vector<int> bytecode; CodeGen codegen; @@ -1397,10 +1398,10 @@ Error GDCompiler::_parse_function(GDScript *p_script, const GDParser::ClassNode if (!p_func && p_class->extends_used && p_script->native.is_null()) { //call implicit parent constructor - codegen.opcodes.push_back(GDFunction::OPCODE_CALL_SELF_BASE); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_CALL_SELF_BASE); codegen.opcodes.push_back(codegen.get_name_map_pos("_init")); codegen.opcodes.push_back(0); - codegen.opcodes.push_back((GDFunction::ADDR_TYPE_STACK << GDFunction::ADDR_BITS) | 0); + codegen.opcodes.push_back((GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS) | 0); } Error err = _parse_block(codegen, p_class->initializer, stack_level); if (err) @@ -1426,7 +1427,7 @@ Error GDCompiler::_parse_function(GDScript *p_script, const GDParser::ClassNode if (p_func->default_values.size()) { - codegen.opcodes.push_back(GDFunction::OPCODE_JUMP_TO_DEF_ARGUMENT); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_JUMP_TO_DEF_ARGUMENT); defarg_addr.push_back(codegen.opcodes.size()); for (int i = 0; i < p_func->default_values.size(); i++) { @@ -1449,15 +1450,15 @@ Error GDCompiler::_parse_function(GDScript *p_script, const GDParser::ClassNode func_name = "_init"; } - codegen.opcodes.push_back(GDFunction::OPCODE_END); + codegen.opcodes.push_back(GDScriptFunction::OPCODE_END); /* if (String(p_func->name)=="") { //initializer func gdfunc = &p_script->initializer; */ //} else { //regular func - p_script->member_functions[func_name] = memnew(GDFunction); - GDFunction *gdfunc = p_script->member_functions[func_name]; + p_script->member_functions[func_name] = memnew(GDScriptFunction); + GDScriptFunction *gdfunc = p_script->member_functions[func_name]; //} if (p_func) { @@ -1579,7 +1580,7 @@ Error GDCompiler::_parse_function(GDScript *p_script, const GDParser::ClassNode return OK; } -Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDParser::ClassNode *p_class, bool p_keep_state) { +Error GDScriptCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDScriptParser::ClassNode *p_class, bool p_keep_state) { Map<StringName, Ref<GDScript> > old_subclasses; @@ -1587,12 +1588,12 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa old_subclasses = p_script->subclasses; } - p_script->native = Ref<GDNativeClass>(); + p_script->native = Ref<GDScriptNativeClass>(); p_script->base = Ref<GDScript>(); p_script->_base = NULL; p_script->members.clear(); p_script->constants.clear(); - for (Map<StringName, GDFunction *>::Element *E = p_script->member_functions.front(); E; E = E->next()) { + for (Map<StringName, GDScriptFunction *>::Element *E = p_script->member_functions.front(); E; E = E->next()) { memdelete(E->get()); } p_script->member_functions.clear(); @@ -1606,7 +1607,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa p_script->tool = p_class->tool; p_script->name = p_class->name; - Ref<GDNativeClass> native; + Ref<GDScriptNativeClass> native; if (p_class->extends_used) { //do inheritance @@ -1685,21 +1686,44 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa 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; } } @@ -1801,14 +1825,14 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa for (int i = 0; i < p_class->constant_expressions.size(); i++) { StringName name = p_class->constant_expressions[i].identifier; - ERR_CONTINUE(p_class->constant_expressions[i].expression->type != GDParser::Node::TYPE_CONSTANT); + ERR_CONTINUE(p_class->constant_expressions[i].expression->type != GDScriptParser::Node::TYPE_CONSTANT); if (_is_class_member_property(p_script, name)) { _set_error("Member '" + name + "' already exists as a class property.", p_class); return ERR_ALREADY_EXISTS; } - GDParser::ConstantNode *constant = static_cast<GDParser::ConstantNode *>(p_class->constant_expressions[i].expression); + GDScriptParser::ConstantNode *constant = static_cast<GDScriptParser::ConstantNode *>(p_class->constant_expressions[i].expression); p_script->constants.insert(name, constant->value); //p_script->constants[constant->value].make_const(); @@ -1917,7 +1941,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa for (int i = 0; i < p_class->variables.size(); i++) { if (p_class->variables[i].setter) { - const Map<StringName, GDFunction *>::Element *E = p_script->get_member_functions().find(p_class->variables[i].setter); + const Map<StringName, GDScriptFunction *>::Element *E = p_script->get_member_functions().find(p_class->variables[i].setter); if (!E) { _set_error("Setter function '" + String(p_class->variables[i].setter) + "' not found in class.", NULL); err_line = p_class->variables[i].line; @@ -1934,7 +1958,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa } } if (p_class->variables[i].getter) { - const Map<StringName, GDFunction *>::Element *E = p_script->get_member_functions().find(p_class->variables[i].getter); + const Map<StringName, GDScriptFunction *>::Element *E = p_script->get_member_functions().find(p_class->variables[i].getter); if (!E) { _set_error("Getter function '" + String(p_class->variables[i].getter) + "' not found in class.", NULL); err_line = p_class->variables[i].line; @@ -1970,7 +1994,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa //re-create as an instance p_script->placeholders.erase(psi); //remove placeholder - GDInstance *instance = memnew(GDInstance); + GDScriptInstance *instance = memnew(GDScriptInstance); instance->base_ref = Object::cast_to<Reference>(E->get()); instance->members.resize(p_script->member_indices.size()); instance->script = Ref<GDScript>(p_script); @@ -1994,7 +2018,7 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa #endif } else { - GDInstance *gi = static_cast<GDInstance *>(si); + GDScriptInstance *gi = static_cast<GDScriptInstance *>(si); gi->reload_members(); } @@ -2007,18 +2031,18 @@ Error GDCompiler::_parse_class(GDScript *p_script, GDScript *p_owner, const GDPa return OK; } -Error GDCompiler::compile(const GDParser *p_parser, GDScript *p_script, bool p_keep_state) { +Error GDScriptCompiler::compile(const GDScriptParser *p_parser, GDScript *p_script, bool p_keep_state) { err_line = -1; err_column = -1; error = ""; parser = p_parser; - const GDParser::Node *root = parser->get_parse_tree(); - ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, ERR_INVALID_DATA); + const GDScriptParser::Node *root = parser->get_parse_tree(); + ERR_FAIL_COND_V(root->type != GDScriptParser::Node::TYPE_CLASS, ERR_INVALID_DATA); source = p_script->get_path(); - Error err = _parse_class(p_script, NULL, static_cast<const GDParser::ClassNode *>(root), p_keep_state); + Error err = _parse_class(p_script, NULL, static_cast<const GDScriptParser::ClassNode *>(root), p_keep_state); if (err) return err; @@ -2026,18 +2050,18 @@ Error GDCompiler::compile(const GDParser *p_parser, GDScript *p_script, bool p_k return OK; } -String GDCompiler::get_error() const { +String GDScriptCompiler::get_error() const { return error; } -int GDCompiler::get_error_line() const { +int GDScriptCompiler::get_error_line() const { return err_line; } -int GDCompiler::get_error_column() const { +int GDScriptCompiler::get_error_column() const { return err_column; } -GDCompiler::GDCompiler() { +GDScriptCompiler::GDScriptCompiler() { } diff --git a/modules/gdscript/gd_compiler.h b/modules/gdscript/gdscript_compiler.h index ac713ae75b..6e0457ba30 100644 --- a/modules/gdscript/gd_compiler.h +++ b/modules/gdscript/gdscript_compiler.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_compiler.h */ +/* gdscript_compiler.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,26 +27,26 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GD_COMPILER_H -#define GD_COMPILER_H +#ifndef GDSCRIPT_COMPILER_H +#define GDSCRIPT_COMPILER_H -#include "gd_parser.h" -#include "gd_script.h" +#include "gdscript.h" +#include "gdscript_parser.h" -class GDCompiler { +class GDScriptCompiler { - const GDParser *parser; + const GDScriptParser *parser; struct CodeGen { GDScript *script; - const GDParser::ClassNode *class_node; - const GDParser::FunctionNode *function_node; + const GDScriptParser::ClassNode *class_node; + const GDScriptParser::FunctionNode *function_node; bool debug_stack; List<Map<StringName, int> > stack_id_stack; Map<StringName, int> stack_identifiers; - List<GDFunction::StackDebug> stack_debug; + List<GDScriptFunction::StackDebug> stack_debug; List<Map<StringName, int> > block_identifier_stack; Map<StringName, int> block_identifiers; @@ -54,7 +54,7 @@ class GDCompiler { stack_identifiers[p_id] = p_stackpos; if (debug_stack) { block_identifiers[p_id] = p_stackpos; - GDFunction::StackDebug sd; + GDScriptFunction::StackDebug sd; sd.added = true; sd.line = current_line; sd.identifier = p_id; @@ -79,7 +79,7 @@ class GDCompiler { if (debug_stack) { for (Map<StringName, int>::Element *E = block_identifiers.front(); E; E = E->next()) { - GDFunction::StackDebug sd; + GDScriptFunction::StackDebug sd; sd.added = false; sd.identifier = E->key(); sd.line = current_line; @@ -129,29 +129,29 @@ class GDCompiler { bool _is_class_member_property(CodeGen &codegen, const StringName &p_name); bool _is_class_member_property(GDScript *owner, const StringName &p_name); - void _set_error(const String &p_error, const GDParser::Node *p_node); + void _set_error(const String &p_error, const GDScriptParser::Node *p_node); - bool _create_unary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level); - bool _create_binary_operator(CodeGen &codegen, const GDParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer = false); + bool _create_unary_operator(CodeGen &codegen, const GDScriptParser::OperatorNode *on, Variant::Operator op, int p_stack_level); + bool _create_binary_operator(CodeGen &codegen, const GDScriptParser::OperatorNode *on, Variant::Operator op, int p_stack_level, bool p_initializer = false); - int _parse_assign_right_expression(CodeGen &codegen, const GDParser::OperatorNode *p_expression, int p_stack_level); - int _parse_expression(CodeGen &codegen, const GDParser::Node *p_expression, int p_stack_level, bool p_root = false, bool p_initializer = false); - Error _parse_block(CodeGen &codegen, const GDParser::BlockNode *p_block, int p_stack_level = 0, int p_break_addr = -1, int p_continue_addr = -1); - Error _parse_function(GDScript *p_script, const GDParser::ClassNode *p_class, const GDParser::FunctionNode *p_func, bool p_for_ready = false); - Error _parse_class(GDScript *p_script, GDScript *p_owner, const GDParser::ClassNode *p_class, bool p_keep_state); + int _parse_assign_right_expression(CodeGen &codegen, const GDScriptParser::OperatorNode *p_expression, int p_stack_level); + int _parse_expression(CodeGen &codegen, const GDScriptParser::Node *p_expression, int p_stack_level, bool p_root = false, bool p_initializer = false); + Error _parse_block(CodeGen &codegen, const GDScriptParser::BlockNode *p_block, int p_stack_level = 0, int p_break_addr = -1, int p_continue_addr = -1); + Error _parse_function(GDScript *p_script, const GDScriptParser::ClassNode *p_class, const GDScriptParser::FunctionNode *p_func, bool p_for_ready = false); + Error _parse_class(GDScript *p_script, GDScript *p_owner, const GDScriptParser::ClassNode *p_class, bool p_keep_state); int err_line; int err_column; StringName source; String error; public: - Error compile(const GDParser *p_parser, GDScript *p_script, bool p_keep_state = false); + Error compile(const GDScriptParser *p_parser, GDScript *p_script, bool p_keep_state = false); String get_error() const; int get_error_line() const; int get_error_column() const; - GDCompiler(); + GDScriptCompiler(); }; -#endif // COMPILER_H +#endif // GDSCRIPT_COMPILER_H diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gdscript_editor.cpp index 346b7d326a..5a76acea6e 100644 --- a/modules/gdscript/gd_editor.cpp +++ b/modules/gdscript/gdscript_editor.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_editor.cpp */ +/* gdscript_editor.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,13 +27,13 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_script.h" +#include "gdscript.h" #include "editor/editor_settings.h" -#include "gd_compiler.h" +#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" @@ -92,7 +92,7 @@ void GDScriptLanguage::make_template(const String &p_class_name, const String &p bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions) const { - GDParser parser; + GDScriptParser parser; Error err = parser.parse(p_script, p_path.get_base_dir(), true, p_path); if (err) { @@ -102,10 +102,10 @@ bool GDScriptLanguage::validate(const String &p_script, int &r_line_error, int & return false; } else { - const GDParser::Node *root = parser.get_parse_tree(); - ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, false); + const GDScriptParser::Node *root = parser.get_parse_tree(); + ERR_FAIL_COND_V(root->type != GDScriptParser::Node::TYPE_CLASS, false); - const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode *>(root); + const GDScriptParser::ClassNode *cl = static_cast<const GDScriptParser::ClassNode *>(root); Map<int, String> funcs; for (int i = 0; i < cl->functions.size(); i++) { @@ -138,16 +138,16 @@ bool GDScriptLanguage::supports_builtin_mode() const { int GDScriptLanguage::find_function(const String &p_function, const String &p_code) const { - GDTokenizerText tokenizer; + GDScriptTokenizerText tokenizer; tokenizer.set_code(p_code); int indent = 0; - while (tokenizer.get_token() != GDTokenizer::TK_EOF && tokenizer.get_token() != GDTokenizer::TK_ERROR) { + while (tokenizer.get_token() != GDScriptTokenizer::TK_EOF && tokenizer.get_token() != GDScriptTokenizer::TK_ERROR) { - if (tokenizer.get_token() == GDTokenizer::TK_NEWLINE) { + if (tokenizer.get_token() == GDScriptTokenizer::TK_NEWLINE) { indent = tokenizer.get_token_line_indent(); } - //print_line("TOKEN: "+String(GDTokenizer::get_token_name(tokenizer.get_token()))); - if (indent == 0 && tokenizer.get_token() == GDTokenizer::TK_PR_FUNCTION && tokenizer.get_token(1) == GDTokenizer::TK_IDENTIFIER) { + //print_line("TOKEN: "+String(GDScriptTokenizer::get_token_name(tokenizer.get_token()))); + if (indent == 0 && tokenizer.get_token() == GDScriptTokenizer::TK_PR_FUNCTION && tokenizer.get_token(1) == GDScriptTokenizer::TK_IDENTIFIER) { String identifier = tokenizer.get_token_identifier(1); if (identifier == p_function) { @@ -155,7 +155,7 @@ int GDScriptLanguage::find_function(const String &p_function, const String &p_co } } tokenizer.advance(); - //print_line("NEXT: "+String(GDTokenizer::get_token_name(tokenizer.get_token()))); + //print_line("NEXT: "+String(GDScriptTokenizer::get_token_name(tokenizer.get_token()))); } return -1; } @@ -245,7 +245,7 @@ void GDScriptLanguage::debug_get_stack_level_locals(int p_level, List<String> *p ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); int l = _debug_call_stack_pos - p_level - 1; - GDFunction *f = _call_stack[l].function; + GDScriptFunction *f = _call_stack[l].function; List<Pair<StringName, int> > locals; @@ -264,7 +264,7 @@ void GDScriptLanguage::debug_get_stack_level_members(int p_level, List<String> * ERR_FAIL_INDEX(p_level, _debug_call_stack_pos); int l = _debug_call_stack_pos - p_level - 1; - GDInstance *instance = _call_stack[l].instance; + GDScriptInstance *instance = _call_stack[l].instance; if (!instance) return; @@ -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) @@ -298,9 +350,9 @@ void GDScriptLanguage::get_recognized_extensions(List<String> *p_extensions) con void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const { - for (int i = 0; i < GDFunctions::FUNC_MAX; i++) { + for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) { - p_functions->push_back(GDFunctions::get_info(GDFunctions::Function(i))); + p_functions->push_back(GDScriptFunctions::get_info(GDScriptFunctions::Function(i))); } //not really "functions", but.. @@ -318,7 +370,7 @@ void GDScriptLanguage::get_public_functions(List<MethodInfo> *p_functions) const mi.arguments.push_back(PropertyInfo(Variant::STRING, "signal")); mi.default_arguments.push_back(Variant::NIL); mi.default_arguments.push_back(Variant::STRING); - mi.return_val = PropertyInfo(Variant::OBJECT, "", PROPERTY_HINT_RESOURCE_TYPE, "GDFunctionState"); + mi.return_val = PropertyInfo(Variant::OBJECT, "", PROPERTY_HINT_RESOURCE_TYPE, "GDScriptFunctionState"); p_functions->push_back(mi); } { @@ -365,14 +417,14 @@ String GDScriptLanguage::make_function(const String &p_class, const String &p_na } s += " "; } - s += "):\n\tpass # replace with function body\n"; + s += "):\n" + _get_indentation() + "pass # replace with function body\n"; return s; } #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) -struct GDCompletionIdentifier { +struct GDScriptCompletionIdentifier { String enumeration; StringName obj_type; @@ -381,17 +433,17 @@ struct GDCompletionIdentifier { Variant value; //im case there is a value, also return it }; -static GDCompletionIdentifier _get_type_from_variant(const Variant &p_variant, bool p_allow_gdnative_class = false) { +static GDScriptCompletionIdentifier _get_type_from_variant(const Variant &p_variant, bool p_allow_gdnative_class = false) { - GDCompletionIdentifier t; + GDScriptCompletionIdentifier t; t.type = p_variant.get_type(); t.value = p_variant; if (p_variant.get_type() == Variant::OBJECT) { Object *obj = p_variant; if (obj) { - if (p_allow_gdnative_class && Object::cast_to<GDNativeClass>(obj)) { - t.obj_type = Object::cast_to<GDNativeClass>(obj)->get_name(); + if (p_allow_gdnative_class && Object::cast_to<GDScriptNativeClass>(obj)) { + t.obj_type = Object::cast_to<GDScriptNativeClass>(obj)->get_name(); t.value = Variant(); } else { @@ -402,9 +454,9 @@ static GDCompletionIdentifier _get_type_from_variant(const Variant &p_variant, b return t; } -static GDCompletionIdentifier _get_type_from_pinfo(const PropertyInfo &p_info) { +static GDScriptCompletionIdentifier _get_type_from_pinfo(const PropertyInfo &p_info) { - GDCompletionIdentifier t; + GDScriptCompletionIdentifier t; t.type = p_info.type; if (p_info.hint == PROPERTY_HINT_RESOURCE_TYPE) { t.obj_type = p_info.hint_string; @@ -412,23 +464,23 @@ static GDCompletionIdentifier _get_type_from_pinfo(const PropertyInfo &p_info) { return t; } -struct GDCompletionContext { +struct GDScriptCompletionContext { - const GDParser::ClassNode *_class; - const GDParser::FunctionNode *function; - const GDParser::BlockNode *block; + const GDScriptParser::ClassNode *_class; + const GDScriptParser::FunctionNode *function; + const GDScriptParser::BlockNode *block; Object *base; String base_path; }; -static Ref<Reference> _get_parent_class(GDCompletionContext &context) { +static Ref<Reference> _get_parent_class(GDScriptCompletionContext &context) { if (context._class->extends_used) { //do inheritance String path = context._class->extends_file; Ref<GDScript> script; - Ref<GDNativeClass> native; + Ref<GDScriptNativeClass> native; if (path != "") { //path (and optionally subclasses) @@ -498,17 +550,17 @@ static Ref<Reference> _get_parent_class(GDCompletionContext &context) { return Ref<Reference>(); } -static GDCompletionIdentifier _get_native_class(GDCompletionContext &context) { +static GDScriptCompletionIdentifier _get_native_class(GDScriptCompletionContext &context) { //eeh... - GDCompletionIdentifier id; + GDScriptCompletionIdentifier id; id.type = Variant::NIL; REF pc = _get_parent_class(context); if (!pc.is_valid()) { return id; } - Ref<GDNativeClass> nc = pc; + Ref<GDScriptNativeClass> nc = pc; Ref<GDScript> s = pc; if (s.is_null() && nc.is_null()) { @@ -529,28 +581,28 @@ static GDCompletionIdentifier _get_native_class(GDCompletionContext &context) { return id; } -static bool _guess_identifier_type(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type, bool p_for_indexing); +static bool _guess_identifier_type(GDScriptCompletionContext &context, int p_line, const StringName &p_identifier, GDScriptCompletionIdentifier &r_type, bool p_for_indexing); -static bool _guess_expression_type(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, GDCompletionIdentifier &r_type, bool p_for_indexing = false) { +static bool _guess_expression_type(GDScriptCompletionContext &context, const GDScriptParser::Node *p_node, int p_line, GDScriptCompletionIdentifier &r_type, bool p_for_indexing = false) { - if (p_node->type == GDParser::Node::TYPE_CONSTANT) { + if (p_node->type == GDScriptParser::Node::TYPE_CONSTANT) { - const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode *>(p_node); + const GDScriptParser::ConstantNode *cn = static_cast<const GDScriptParser::ConstantNode *>(p_node); r_type = _get_type_from_variant(cn->value); return true; - } else if (p_node->type == GDParser::Node::TYPE_DICTIONARY) { + } else if (p_node->type == GDScriptParser::Node::TYPE_DICTIONARY) { r_type.type = Variant::DICTIONARY; //what the heck, fill it anyway - const GDParser::DictionaryNode *an = static_cast<const GDParser::DictionaryNode *>(p_node); + const GDScriptParser::DictionaryNode *an = static_cast<const GDScriptParser::DictionaryNode *>(p_node); Dictionary d; for (int i = 0; i < an->elements.size(); i++) { - GDCompletionIdentifier k; + GDScriptCompletionIdentifier k; if (_guess_expression_type(context, an->elements[i].key, p_line, k) && k.value.get_type() != Variant::NIL) { - GDCompletionIdentifier v; + GDScriptCompletionIdentifier v; if (_guess_expression_type(context, an->elements[i].value, p_line, v)) { d[k.value] = v.value; } @@ -558,15 +610,15 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: } r_type.value = d; return true; - } else if (p_node->type == GDParser::Node::TYPE_ARRAY) { + } else if (p_node->type == GDScriptParser::Node::TYPE_ARRAY) { r_type.type = Variant::ARRAY; //what the heck, fill it anyway - const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode *>(p_node); + const GDScriptParser::ArrayNode *an = static_cast<const GDScriptParser::ArrayNode *>(p_node); Array arr; arr.resize(an->elements.size()); for (int i = 0; i < an->elements.size(); i++) { - GDCompletionIdentifier ci; + GDScriptCompletionIdentifier ci; if (_guess_expression_type(context, an->elements[i], p_line, ci)) { arr[i] = ci.value; } @@ -574,44 +626,44 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: r_type.value = arr; return true; - } else if (p_node->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) { + } else if (p_node->type == GDScriptParser::Node::TYPE_BUILT_IN_FUNCTION) { - MethodInfo mi = GDFunctions::get_info(static_cast<const GDParser::BuiltInFunctionNode *>(p_node)->function); + MethodInfo mi = GDScriptFunctions::get_info(static_cast<const GDScriptParser::BuiltInFunctionNode *>(p_node)->function); r_type = _get_type_from_pinfo(mi.return_val); return true; - } else if (p_node->type == GDParser::Node::TYPE_IDENTIFIER) { + } else if (p_node->type == GDScriptParser::Node::TYPE_IDENTIFIER) { - return _guess_identifier_type(context, p_line - 1, static_cast<const GDParser::IdentifierNode *>(p_node)->name, r_type, p_for_indexing); - } else if (p_node->type == GDParser::Node::TYPE_SELF) { + return _guess_identifier_type(context, p_line - 1, static_cast<const GDScriptParser::IdentifierNode *>(p_node)->name, r_type, p_for_indexing); + } else if (p_node->type == GDScriptParser::Node::TYPE_SELF) { //eeh... r_type = _get_native_class(context); return r_type.type != Variant::NIL; - } else if (p_node->type == GDParser::Node::TYPE_OPERATOR) { + } else if (p_node->type == GDScriptParser::Node::TYPE_OPERATOR) { - const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_node); - if (op->op == GDParser::OperatorNode::OP_CALL) { + const GDScriptParser::OperatorNode *op = static_cast<const GDScriptParser::OperatorNode *>(p_node); + if (op->op == GDScriptParser::OperatorNode::OP_CALL) { - if (op->arguments[0]->type == GDParser::Node::TYPE_TYPE) { + if (op->arguments[0]->type == GDScriptParser::Node::TYPE_TYPE) { - const GDParser::TypeNode *tn = static_cast<const GDParser::TypeNode *>(op->arguments[0]); + const GDScriptParser::TypeNode *tn = static_cast<const GDScriptParser::TypeNode *>(op->arguments[0]); r_type.type = tn->vtype; return true; - } else if (op->arguments[0]->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) { + } else if (op->arguments[0]->type == GDScriptParser::Node::TYPE_BUILT_IN_FUNCTION) { - const GDParser::BuiltInFunctionNode *bin = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]); + const GDScriptParser::BuiltInFunctionNode *bin = static_cast<const GDScriptParser::BuiltInFunctionNode *>(op->arguments[0]); return _guess_expression_type(context, bin, p_line, r_type); - } else if (op->arguments.size() > 1 && op->arguments[1]->type == GDParser::Node::TYPE_IDENTIFIER) { + } else if (op->arguments.size() > 1 && op->arguments[1]->type == GDScriptParser::Node::TYPE_IDENTIFIER) { - StringName id = static_cast<const GDParser::IdentifierNode *>(op->arguments[1])->name; + StringName id = static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[1])->name; - if (op->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER && String(id) == "new") { + if (op->arguments[0]->type == GDScriptParser::Node::TYPE_IDENTIFIER && String(id) == "new") { //shortcut - StringName identifier = static_cast<const GDParser::IdentifierNode *>(op->arguments[0])->name; + StringName identifier = static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[0])->name; if (ClassDB::class_exists(identifier)) { r_type.type = Variant::OBJECT; @@ -621,7 +673,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: } } - GDCompletionIdentifier base; + GDScriptCompletionIdentifier base; if (!_guess_expression_type(context, op->arguments[0], p_line, base)) return false; @@ -630,8 +682,8 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: if (id.operator String() == "new" && base.value.get_type() == Variant::OBJECT) { Object *obj = base.value; - if (obj && Object::cast_to<GDNativeClass>(obj)) { - GDNativeClass *gdnc = Object::cast_to<GDNativeClass>(obj); + if (obj && Object::cast_to<GDScriptNativeClass>(obj)) { + GDScriptNativeClass *gdnc = Object::cast_to<GDScriptNativeClass>(obj); r_type.type = Variant::OBJECT; r_type.value = Variant(); r_type.obj_type = gdnc->get_name(); @@ -662,7 +714,7 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: bool all_valid = true; Vector<Variant> args; for (int i = 2; i < op->arguments.size(); i++) { - GDCompletionIdentifier arg; + GDScriptCompletionIdentifier arg; if (_guess_expression_type(context, op->arguments[i], p_line, arg)) { if (arg.value.get_type() != Variant::NIL && arg.value.get_type() != Variant::OBJECT) { // calling with object seems dangerous, i don' t know @@ -785,15 +837,15 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: } } } - } else if (op->op == GDParser::OperatorNode::OP_INDEX || op->op == GDParser::OperatorNode::OP_INDEX_NAMED) { + } else if (op->op == GDScriptParser::OperatorNode::OP_INDEX || op->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED) { - GDCompletionIdentifier p1; - GDCompletionIdentifier p2; + GDScriptCompletionIdentifier p1; + GDScriptCompletionIdentifier p2; - if (op->op == GDParser::OperatorNode::OP_INDEX_NAMED) { + if (op->op == GDScriptParser::OperatorNode::OP_INDEX_NAMED) { - if (op->arguments[1]->type == GDParser::Node::TYPE_IDENTIFIER) { - String id = static_cast<const GDParser::IdentifierNode *>(op->arguments[1])->name; + if (op->arguments[1]->type == GDScriptParser::Node::TYPE_IDENTIFIER) { + String id = static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[1])->name; p2.type = Variant::STRING; p2.value = id; } @@ -807,9 +859,9 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: } } - if (op->arguments[0]->type == GDParser::Node::TYPE_ARRAY) { + if (op->arguments[0]->type == GDScriptParser::Node::TYPE_ARRAY) { - const GDParser::ArrayNode *an = static_cast<const GDParser::ArrayNode *>(op->arguments[0]); + const GDScriptParser::ArrayNode *an = static_cast<const GDScriptParser::ArrayNode *>(op->arguments[0]); if (p2.value.is_num()) { int index = p2.value; if (index < 0 || index >= an->elements.size()) @@ -817,16 +869,16 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: return _guess_expression_type(context, an->elements[index], p_line, r_type); } - } else if (op->arguments[0]->type == GDParser::Node::TYPE_DICTIONARY) { + } else if (op->arguments[0]->type == GDScriptParser::Node::TYPE_DICTIONARY) { - const GDParser::DictionaryNode *dn = static_cast<const GDParser::DictionaryNode *>(op->arguments[0]); + const GDScriptParser::DictionaryNode *dn = static_cast<const GDScriptParser::DictionaryNode *>(op->arguments[0]); if (p2.value.get_type() == Variant::NIL) return false; for (int i = 0; i < dn->elements.size(); i++) { - GDCompletionIdentifier k; + GDScriptCompletionIdentifier k; if (!_guess_expression_type(context, dn->elements[i].key, p_line, k)) { @@ -858,9 +910,9 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: StringName base_type = p1.obj_type; - if (p1.obj_type == "GDNativeClass") { + if (p1.obj_type == "GDScriptNativeClass") { //native enum - Ref<GDNativeClass> gdn = p1.value; + Ref<GDScriptNativeClass> gdn = p1.value; if (gdn.is_valid()) { base_type = gdn->get_name(); @@ -921,24 +973,24 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: Variant::Operator vop = Variant::OP_MAX; switch (op->op) { - case GDParser::OperatorNode::OP_ADD: vop = Variant::OP_ADD; break; - case GDParser::OperatorNode::OP_SUB: vop = Variant::OP_SUBTRACT; break; - case GDParser::OperatorNode::OP_MUL: vop = Variant::OP_MULTIPLY; break; - case GDParser::OperatorNode::OP_DIV: vop = Variant::OP_DIVIDE; break; - case GDParser::OperatorNode::OP_MOD: vop = Variant::OP_MODULE; break; - case GDParser::OperatorNode::OP_SHIFT_LEFT: vop = Variant::OP_SHIFT_LEFT; break; - case GDParser::OperatorNode::OP_SHIFT_RIGHT: vop = Variant::OP_SHIFT_RIGHT; break; - case GDParser::OperatorNode::OP_BIT_AND: vop = Variant::OP_BIT_AND; break; - case GDParser::OperatorNode::OP_BIT_OR: vop = Variant::OP_BIT_OR; break; - case GDParser::OperatorNode::OP_BIT_XOR: vop = Variant::OP_BIT_XOR; break; + case GDScriptParser::OperatorNode::OP_ADD: vop = Variant::OP_ADD; break; + case GDScriptParser::OperatorNode::OP_SUB: vop = Variant::OP_SUBTRACT; break; + case GDScriptParser::OperatorNode::OP_MUL: vop = Variant::OP_MULTIPLY; break; + case GDScriptParser::OperatorNode::OP_DIV: vop = Variant::OP_DIVIDE; break; + case GDScriptParser::OperatorNode::OP_MOD: vop = Variant::OP_MODULE; break; + case GDScriptParser::OperatorNode::OP_SHIFT_LEFT: vop = Variant::OP_SHIFT_LEFT; break; + case GDScriptParser::OperatorNode::OP_SHIFT_RIGHT: vop = Variant::OP_SHIFT_RIGHT; break; + case GDScriptParser::OperatorNode::OP_BIT_AND: vop = Variant::OP_BIT_AND; break; + case GDScriptParser::OperatorNode::OP_BIT_OR: vop = Variant::OP_BIT_OR; break; + case GDScriptParser::OperatorNode::OP_BIT_XOR: vop = Variant::OP_BIT_XOR; break; default: {} } if (vop == Variant::OP_MAX) return false; - GDCompletionIdentifier p1; - GDCompletionIdentifier p2; + GDScriptCompletionIdentifier p1; + GDScriptCompletionIdentifier p2; if (op->arguments[0]) { if (!_guess_expression_type(context, op->arguments[0], p_line, p1)) { @@ -985,15 +1037,15 @@ static bool _guess_expression_type(GDCompletionContext &context, const GDParser: return false; } -static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type) { +static bool _guess_identifier_type_in_block(GDScriptCompletionContext &context, int p_line, const StringName &p_identifier, GDScriptCompletionIdentifier &r_type) { - if (context.block->if_condition && context.block->if_condition->type == GDParser::Node::TYPE_OPERATOR && static_cast<const GDParser::OperatorNode *>(context.block->if_condition)->op == GDParser::OperatorNode::OP_IS) { + if (context.block->if_condition && context.block->if_condition->type == GDScriptParser::Node::TYPE_OPERATOR && static_cast<const GDScriptParser::OperatorNode *>(context.block->if_condition)->op == GDScriptParser::OperatorNode::OP_IS) { //is used, check if identifier is in there! this helps resolve in blocks that are (if (identifier is value)): which are very common.. //super dirty hack, but very useful //credit: Zylann //TODO: this could be hacked to detect ANDed conditions too.. - const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(context.block->if_condition); - if (op->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER && static_cast<const GDParser::IdentifierNode *>(op->arguments[0])->name == p_identifier) { + const GDScriptParser::OperatorNode *op = static_cast<const GDScriptParser::OperatorNode *>(context.block->if_condition); + if (op->arguments[0]->type == GDScriptParser::Node::TYPE_IDENTIFIER && static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[0])->name == p_identifier) { //bingo if (_guess_expression_type(context, op->arguments[1], op->line, r_type)) { return true; @@ -1001,7 +1053,7 @@ static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_ } } - GDCompletionIdentifier gdi = _get_native_class(context); + GDScriptCompletionIdentifier gdi = _get_native_class(context); if (gdi.obj_type != StringName()) { bool valid; Variant::Type t = ClassDB::get_property_type(gdi.obj_type, p_identifier, &valid); @@ -1027,7 +1079,7 @@ static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_ } } - const GDParser::Node *last_assign = NULL; + const GDScriptParser::Node *last_assign = NULL; int last_assign_line = -1; for (int i = 0; i < context.block->statements.size(); i++) { @@ -1035,9 +1087,9 @@ static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_ if (context.block->statements[i]->line > p_line) continue; - if (context.block->statements[i]->type == GDParser::BlockNode::TYPE_LOCAL_VAR) { + if (context.block->statements[i]->type == GDScriptParser::BlockNode::TYPE_LOCAL_VAR) { - const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode *>(context.block->statements[i]); + const GDScriptParser::LocalVarNode *lv = static_cast<const GDScriptParser::LocalVarNode *>(context.block->statements[i]); if (lv->assign && lv->name == p_identifier) { @@ -1046,13 +1098,13 @@ static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_ } } - if (context.block->statements[i]->type == GDParser::BlockNode::TYPE_OPERATOR) { - const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(context.block->statements[i]); - if (op->op == GDParser::OperatorNode::OP_ASSIGN) { + if (context.block->statements[i]->type == GDScriptParser::BlockNode::TYPE_OPERATOR) { + const GDScriptParser::OperatorNode *op = static_cast<const GDScriptParser::OperatorNode *>(context.block->statements[i]); + if (op->op == GDScriptParser::OperatorNode::OP_ASSIGN) { - if (op->arguments.size() && op->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER) { + if (op->arguments.size() && op->arguments[0]->type == GDScriptParser::Node::TYPE_IDENTIFIER) { - const GDParser::IdentifierNode *id = static_cast<const GDParser::IdentifierNode *>(op->arguments[0]); + const GDScriptParser::IdentifierNode *id = static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[0]); if (id->name == p_identifier) { @@ -1073,9 +1125,9 @@ static bool _guess_identifier_type_in_block(GDCompletionContext &context, int p_ return false; } -static bool _guess_identifier_from_assignment_in_function(GDCompletionContext &context, int p_src_line, const StringName &p_identifier, const StringName &p_function, GDCompletionIdentifier &r_type) { +static bool _guess_identifier_from_assignment_in_function(GDScriptCompletionContext &context, int p_src_line, const StringName &p_identifier, const StringName &p_function, GDScriptCompletionIdentifier &r_type) { - const GDParser::FunctionNode *func = NULL; + const GDScriptParser::FunctionNode *func = NULL; for (int i = 0; i < context._class->functions.size(); i++) { if (context._class->functions[i]->name == p_function) { func = context._class->functions[i]; @@ -1092,13 +1144,13 @@ static bool _guess_identifier_from_assignment_in_function(GDCompletionContext &c break; } - if (func->body->statements[i]->type == GDParser::BlockNode::TYPE_OPERATOR) { - const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(func->body->statements[i]); - if (op->op == GDParser::OperatorNode::OP_ASSIGN) { + if (func->body->statements[i]->type == GDScriptParser::BlockNode::TYPE_OPERATOR) { + const GDScriptParser::OperatorNode *op = static_cast<const GDScriptParser::OperatorNode *>(func->body->statements[i]); + if (op->op == GDScriptParser::OperatorNode::OP_ASSIGN) { - if (op->arguments.size() && op->arguments[0]->type == GDParser::Node::TYPE_IDENTIFIER) { + if (op->arguments.size() && op->arguments[0]->type == GDScriptParser::Node::TYPE_IDENTIFIER) { - const GDParser::IdentifierNode *id = static_cast<const GDParser::IdentifierNode *>(op->arguments[0]); + const GDScriptParser::IdentifierNode *id = static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[0]); if (id->name == p_identifier) { @@ -1112,15 +1164,15 @@ static bool _guess_identifier_from_assignment_in_function(GDCompletionContext &c return false; } -static bool _guess_identifier_type(GDCompletionContext &context, int p_line, const StringName &p_identifier, GDCompletionIdentifier &r_type, bool p_for_indexing) { +static bool _guess_identifier_type(GDScriptCompletionContext &context, int p_line, const StringName &p_identifier, GDScriptCompletionIdentifier &r_type, bool p_for_indexing) { //go to block first - const GDParser::BlockNode *block = context.block; + const GDScriptParser::BlockNode *block = context.block; while (block) { - GDCompletionContext c = context; + GDScriptCompletionContext c = context; c.block = block; if (_guess_identifier_type_in_block(c, p_line, p_identifier, r_type)) { @@ -1144,7 +1196,7 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con } if (argindex != -1) { - GDCompletionIdentifier id = _get_native_class(context); + GDScriptCompletionIdentifier id = _get_native_class(context); if (id.type == Variant::OBJECT && id.obj_type != StringName()) { //this kinda sucks but meh @@ -1182,8 +1234,8 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con if (context._class->constant_expressions[i].identifier == p_identifier) { - ERR_FAIL_COND_V(context._class->constant_expressions[i].expression->type != GDParser::Node::TYPE_CONSTANT, false); - r_type = _get_type_from_variant(static_cast<const GDParser::ConstantNode *>(context._class->constant_expressions[i].expression)->value); + ERR_FAIL_COND_V(context._class->constant_expressions[i].expression->type != GDScriptParser::Node::TYPE_CONSTANT, false); + r_type = _get_type_from_variant(static_cast<const GDScriptParser::ConstantNode *>(context._class->constant_expressions[i].expression)->value); return true; } } @@ -1275,7 +1327,7 @@ static bool _guess_identifier_type(GDCompletionContext &context, int p_line, con return false; } -static void _find_identifiers_in_block(GDCompletionContext &context, int p_line, bool p_only_functions, Set<String> &result) { +static void _find_identifiers_in_block(GDScriptCompletionContext &context, int p_line, bool p_only_functions, Set<String> &result) { if (p_only_functions) return; @@ -1285,15 +1337,15 @@ static void _find_identifiers_in_block(GDCompletionContext &context, int p_line, if (context.block->statements[i]->line > p_line) continue; - if (context.block->statements[i]->type == GDParser::BlockNode::TYPE_LOCAL_VAR) { + if (context.block->statements[i]->type == GDScriptParser::BlockNode::TYPE_LOCAL_VAR) { - const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode *>(context.block->statements[i]); + const GDScriptParser::LocalVarNode *lv = static_cast<const GDScriptParser::LocalVarNode *>(context.block->statements[i]); result.insert(lv->name.operator String()); } } } -static void _find_identifiers_in_class(GDCompletionContext &context, bool p_static, bool p_only_functions, Set<String> &result) { +static void _find_identifiers_in_class(GDScriptCompletionContext &context, bool p_static, bool p_only_functions, Set<String> &result) { if (!p_static && !p_only_functions) { @@ -1336,7 +1388,7 @@ static void _find_identifiers_in_class(GDCompletionContext &context, bool p_stat while (true) { Ref<GDScript> script = base; - Ref<GDNativeClass> nc = base; + Ref<GDScriptNativeClass> nc = base; if (script.is_valid()) { if (!p_static && !p_only_functions) { @@ -1351,7 +1403,7 @@ static void _find_identifiers_in_class(GDCompletionContext &context, bool p_stat } } - for (const Map<StringName, GDFunction *>::Element *E = script->get_member_functions().front(); E; E = E->next()) { + for (const Map<StringName, GDScriptFunction *>::Element *E = script->get_member_functions().front(); E; E = E->next()) { if (!p_static || E->get()->is_static()) { if (E->get()->get_argument_count()) result.insert(E->key().operator String() + "("); @@ -1410,13 +1462,13 @@ static void _find_identifiers_in_class(GDCompletionContext &context, bool p_stat } } -static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_only_functions, Set<String> &result) { +static void _find_identifiers(GDScriptCompletionContext &context, int p_line, bool p_only_functions, Set<String> &result) { - const GDParser::BlockNode *block = context.block; + const GDScriptParser::BlockNode *block = context.block; if (context.function) { - const GDParser::FunctionNode *f = context.function; + const GDScriptParser::FunctionNode *f = context.function; for (int i = 0; i < f->arguments.size(); i++) { result.insert(f->arguments[i].operator String()); @@ -1425,19 +1477,19 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o while (block) { - GDCompletionContext c = context; + GDScriptCompletionContext c = context; c.block = block; _find_identifiers_in_block(c, p_line, p_only_functions, result); block = block->parent_block; } - const GDParser::ClassNode *clss = context._class; + const GDScriptParser::ClassNode *clss = context._class; bool _static = context.function && context.function->_static; while (clss) { - GDCompletionContext c = context; + GDScriptCompletionContext c = context; c._class = clss; c.block = NULL; c.function = NULL; @@ -1445,9 +1497,9 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o clss = clss->owner; } - for (int i = 0; i < GDFunctions::FUNC_MAX; i++) { + for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) { - result.insert(GDFunctions::get_func_name(GDFunctions::Function(i))); + result.insert(GDScriptFunctions::get_func_name(GDScriptFunctions::Function(i))); } static const char *_type_names[Variant::VARIANT_MAX] = { @@ -1501,7 +1553,7 @@ static String _get_visual_datatype(const PropertyInfo &p_info, bool p_isarg = tr return Variant::get_type_name(p_info.type); } -static void _make_function_hint(const GDParser::FunctionNode *p_func, int p_argidx, String &arghint) { +static void _make_function_hint(const GDScriptParser::FunctionNode *p_func, int p_argidx, String &arghint) { arghint = "func " + p_func->name + "("; for (int i = 0; i < p_func->arguments.size(); i++) { @@ -1521,11 +1573,11 @@ static void _make_function_hint(const GDParser::FunctionNode *p_func, int p_argi if (defidx >= 0 && defidx < p_func->default_values.size()) { - if (p_func->default_values[defidx]->type == GDParser::Node::TYPE_OPERATOR) { + if (p_func->default_values[defidx]->type == GDScriptParser::Node::TYPE_OPERATOR) { - const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_func->default_values[defidx]); - if (op->op == GDParser::OperatorNode::OP_ASSIGN) { - const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode *>(op->arguments[1]); + const GDScriptParser::OperatorNode *op = static_cast<const GDScriptParser::OperatorNode *>(p_func->default_values[defidx]); + if (op->op == GDScriptParser::OperatorNode::OP_ASSIGN) { + const GDScriptParser::ConstantNode *cn = static_cast<const GDScriptParser::ConstantNode *>(op->arguments[1]); arghint += "=" + cn->value.get_construct_string(); } } else { @@ -1553,7 +1605,7 @@ void get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &r_lis } } -static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, bool &r_forced, String &arghint) { +static void _find_type_arguments(GDScriptCompletionContext &context, const GDScriptParser::Node *p_node, int p_line, const StringName &p_method, const GDScriptCompletionIdentifier &id, int p_argidx, Set<String> &result, bool &r_forced, String &arghint) { //print_line("find type arguments?"); if (id.type == Variant::OBJECT && id.obj_type != StringName()) { @@ -1572,7 +1624,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (scr) { while (scr) { - for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { + for (const Map<StringName, GDScriptFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { if (E->get()->is_static() && p_method == E->get()->get_name()) { arghint = "static func " + String(p_method) + "("; for (int i = 0; i < E->get()->get_argument_count(); i++) { @@ -1629,7 +1681,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (code != "") { //if there is code, parse it. This way is slower but updates in real-time - GDParser p; + GDScriptParser p; //Error parse(const String& p_code, const String& p_base_path="", bool p_just_validate=false,const String& p_self_path="",bool p_for_completion=false); Error err = p.parse(scr->get_source_code(), scr->get_path().get_base_dir(), true, "", false); @@ -1637,13 +1689,13 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (err == OK) { //print_line("checking the functions..."); //only if ok, otherwise use what is cached on the script - //GDParser::ClassNode *base = p. - const GDParser::Node *root = p.get_parse_tree(); - ERR_FAIL_COND(root->type != GDParser::Node::TYPE_CLASS); + //GDScriptParser::ClassNode *base = p. + const GDScriptParser::Node *root = p.get_parse_tree(); + ERR_FAIL_COND(root->type != GDScriptParser::Node::TYPE_CLASS); - const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode *>(root); + const GDScriptParser::ClassNode *cl = static_cast<const GDScriptParser::ClassNode *>(root); - const GDParser::FunctionNode *func = NULL; + const GDScriptParser::FunctionNode *func = NULL; bool st = false; for (int i = 0; i < cl->functions.size(); i++) { @@ -1681,10 +1733,10 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N int defidx = deffrom - i; - if (defidx >= 0 && defidx < func->default_values.size() && func->default_values[defidx]->type == GDParser::Node::TYPE_OPERATOR) { - const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(func->default_values[defidx]); - if (op->op == GDParser::OperatorNode::OP_ASSIGN) { - const GDParser::ConstantNode *cn = static_cast<const GDParser::ConstantNode *>(op->arguments[1]); + if (defidx >= 0 && defidx < func->default_values.size() && func->default_values[defidx]->type == GDScriptParser::Node::TYPE_OPERATOR) { + const GDScriptParser::OperatorNode *op = static_cast<const GDScriptParser::OperatorNode *>(func->default_values[defidx]); + if (op->op == GDScriptParser::OperatorNode::OP_ASSIGN) { + const GDScriptParser::ConstantNode *cn = static_cast<const GDScriptParser::ConstantNode *>(op->arguments[1]); arghint += "=" + cn->value.get_construct_string(); } } @@ -1705,7 +1757,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N if (code == "") { - for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { + for (const Map<StringName, GDScriptFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { if (p_method == E->get()->get_name()) { arghint = "func " + String(p_method) + "("; for (int i = 0; i < E->get()->get_argument_count(); i++) { @@ -1743,7 +1795,7 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N } } else { -//regular method + //regular method #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) if (p_argidx < m->get_argument_count()) { @@ -1814,8 +1866,8 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N } /*if (p_argidx==2) { - ERR_FAIL_COND(p_node->type!=GDParser::Node::TYPE_OPERATOR); - const GDParser::OperatorNode *op=static_cast<const GDParser::OperatorNode *>(p_node); + ERR_FAIL_COND(p_node->type!=GDScriptParser::Node::TYPE_OPERATOR); + const GDScriptParser::OperatorNode *op=static_cast<const GDScriptParser::OperatorNode *>(p_node); if (op->arguments.size()>) }*/ @@ -1890,30 +1942,30 @@ static void _find_type_arguments(GDCompletionContext &context, const GDParser::N } } -static void _find_call_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, int p_argidx, Set<String> &result, bool &r_forced, String &arghint) { +static void _find_call_arguments(GDScriptCompletionContext &context, const GDScriptParser::Node *p_node, int p_line, int p_argidx, Set<String> &result, bool &r_forced, String &arghint) { - if (!p_node || p_node->type != GDParser::Node::TYPE_OPERATOR) { + if (!p_node || p_node->type != GDScriptParser::Node::TYPE_OPERATOR) { return; } - const GDParser::OperatorNode *op = static_cast<const GDParser::OperatorNode *>(p_node); + const GDScriptParser::OperatorNode *op = static_cast<const GDScriptParser::OperatorNode *>(p_node); - if (op->op != GDParser::OperatorNode::OP_CALL) { + if (op->op != GDScriptParser::OperatorNode::OP_CALL) { return; } - if (op->arguments[0]->type == GDParser::Node::TYPE_BUILT_IN_FUNCTION) { + if (op->arguments[0]->type == GDScriptParser::Node::TYPE_BUILT_IN_FUNCTION) { //complete built-in function - const GDParser::BuiltInFunctionNode *fn = static_cast<const GDParser::BuiltInFunctionNode *>(op->arguments[0]); - MethodInfo mi = GDFunctions::get_info(fn->function); + const GDScriptParser::BuiltInFunctionNode *fn = static_cast<const GDScriptParser::BuiltInFunctionNode *>(op->arguments[0]); + MethodInfo mi = GDScriptFunctions::get_info(fn->function); if (mi.name == "load" && bool(EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths"))) { get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), result); } - arghint = _get_visual_datatype(mi.return_val, false) + " " + GDFunctions::get_func_name(fn->function) + String("("); + arghint = _get_visual_datatype(mi.return_val, false) + " " + GDScriptFunctions::get_func_name(fn->function) + String("("); for (int i = 0; i < mi.arguments.size(); i++) { if (i > 0) arghint += ", "; @@ -1931,9 +1983,9 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N arghint += " "; arghint += ")"; - } else if (op->arguments[0]->type == GDParser::Node::TYPE_TYPE) { + } else if (op->arguments[0]->type == GDScriptParser::Node::TYPE_TYPE) { //complete constructor - const GDParser::TypeNode *tn = static_cast<const GDParser::TypeNode *>(op->arguments[0]); + const GDScriptParser::TypeNode *tn = static_cast<const GDScriptParser::TypeNode *>(op->arguments[0]); List<MethodInfo> mil; Variant::get_constructor_list(tn->vtype, &mil); @@ -1964,11 +2016,11 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N arghint += ")"; } - } else if (op->arguments.size() >= 2 && op->arguments[1]->type == GDParser::Node::TYPE_IDENTIFIER) { + } else if (op->arguments.size() >= 2 && op->arguments[1]->type == GDScriptParser::Node::TYPE_IDENTIFIER) { //make sure identifier exists... - const GDParser::IdentifierNode *id = static_cast<const GDParser::IdentifierNode *>(op->arguments[1]); - if (op->arguments[0]->type == GDParser::Node::TYPE_SELF) { + const GDScriptParser::IdentifierNode *id = static_cast<const GDScriptParser::IdentifierNode *>(op->arguments[1]); + if (op->arguments[0]->type == GDScriptParser::Node::TYPE_SELF) { //self, look up for (int i = 0; i < context._class->static_functions.size(); i++) { @@ -1993,10 +2045,10 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N while (true) { Ref<GDScript> script = base; - Ref<GDNativeClass> nc = base; + Ref<GDScriptNativeClass> nc = base; if (script.is_valid()) { - for (const Map<StringName, GDFunction *>::Element *E = script->get_member_functions().front(); E; E = E->next()) { + for (const Map<StringName, GDScriptFunction *>::Element *E = script->get_member_functions().front(); E; E = E->next()) { if (E->key() == id->name) { @@ -2038,7 +2090,7 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N if (!(context.function && context.function->_static)) { - GDCompletionIdentifier ci; + GDScriptCompletionIdentifier ci; ci.type = Variant::OBJECT; ci.obj_type = nc->get_name(); if (!context._class->owner) @@ -2063,7 +2115,7 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N } else { //indexed lookup - GDCompletionIdentifier ci; + GDScriptCompletionIdentifier ci; if (_guess_expression_type(context, op->arguments[0], p_line, ci)) { _find_type_arguments(context, p_node, p_line, id->name, ci, p_argidx, result, r_forced, arghint); @@ -2075,13 +2127,13 @@ static void _find_call_arguments(GDCompletionContext &context, const GDParser::N Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base_path, Object *p_owner, List<String> *r_options, bool &r_forced, String &r_call_hint) { - GDParser p; + GDScriptParser p; p.parse(p_code, p_base_path, false, "", true); bool isfunction = false; Set<String> options; r_forced = false; - GDCompletionContext context; + GDScriptCompletionContext context; context._class = p.get_completion_class(); context.block = p.get_completion_block(); context.function = p.get_completion_function(); @@ -2090,9 +2142,9 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base switch (p.get_completion_type()) { - case GDParser::COMPLETION_NONE: { + case GDScriptParser::COMPLETION_NONE: { } break; - case GDParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: { + case GDScriptParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: { List<StringName> constants; Variant::get_numeric_constants_for_type(p.get_completion_built_in_constant(), &constants); for (List<StringName>::Element *E = constants.front(); E; E = E->next()) { @@ -2100,16 +2152,16 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } break; - case GDParser::COMPLETION_FUNCTION: + case GDScriptParser::COMPLETION_FUNCTION: isfunction = true; - case GDParser::COMPLETION_IDENTIFIER: { + case GDScriptParser::COMPLETION_IDENTIFIER: { _find_identifiers(context, p.get_completion_line(), isfunction, options); } break; - case GDParser::COMPLETION_PARENT_FUNCTION: { + case GDScriptParser::COMPLETION_PARENT_FUNCTION: { } break; - case GDParser::COMPLETION_GET_NODE: { + case GDScriptParser::COMPLETION_GET_NODE: { if (p_owner) { List<String> opts; @@ -2130,20 +2182,20 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } } break; - case GDParser::COMPLETION_METHOD: + case GDScriptParser::COMPLETION_METHOD: isfunction = true; - case GDParser::COMPLETION_INDEX: { + case GDScriptParser::COMPLETION_INDEX: { - const GDParser::Node *node = p.get_completion_node(); - if (node->type != GDParser::Node::TYPE_OPERATOR) + const GDScriptParser::Node *node = p.get_completion_node(); + if (node->type != GDScriptParser::Node::TYPE_OPERATOR) break; - GDCompletionIdentifier t; - if (_guess_expression_type(context, static_cast<const GDParser::OperatorNode *>(node)->arguments[0], p.get_completion_line(), t, true)) { + GDScriptCompletionIdentifier t; + if (_guess_expression_type(context, static_cast<const GDScriptParser::OperatorNode *>(node)->arguments[0], p.get_completion_line(), t, true)) { - if (t.type == Variant::OBJECT && t.obj_type == "GDNativeClass") { + if (t.type == Variant::OBJECT && t.obj_type == "GDScriptNativeClass") { //native enum - Ref<GDNativeClass> gdn = t.value; + Ref<GDScriptNativeClass> gdn = t.value; if (gdn.is_valid()) { StringName cn = gdn->get_name(); List<String> cnames; @@ -2179,7 +2231,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base options.insert(E->key()); } } - for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { + for (const Map<StringName, GDScriptFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { if (E->get()->is_static()) options.insert(E->key()); } @@ -2210,17 +2262,17 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base if (code != "") { //if there is code, parse it. This way is slower but updates in real-time - GDParser p; + GDScriptParser p; Error err = p.parse(scr->get_source_code(), scr->get_path().get_base_dir(), true, "", false); if (err == OK) { //only if ok, otherwise use what is cached on the script - //GDParser::ClassNode *base = p. - const GDParser::Node *root = p.get_parse_tree(); - ERR_FAIL_COND_V(root->type != GDParser::Node::TYPE_CLASS, ERR_PARSE_ERROR); + //GDScriptParser::ClassNode *base = p. + const GDScriptParser::Node *root = p.get_parse_tree(); + ERR_FAIL_COND_V(root->type != GDScriptParser::Node::TYPE_CLASS, ERR_PARSE_ERROR); - const GDParser::ClassNode *cl = static_cast<const GDParser::ClassNode *>(root); + const GDScriptParser::ClassNode *cl = static_cast<const GDScriptParser::ClassNode *>(root); for (int i = 0; i < cl->functions.size(); i++) { @@ -2262,7 +2314,7 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base options.insert(E->key()); } } - for (const Map<StringName, GDFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { + for (const Map<StringName, GDScriptFunction *>::Element *E = scr->get_member_functions().front(); E; E = E->next()) { if (E->get()->get_argument_count()) options.insert(String(E->key()) + "()"); else @@ -2341,13 +2393,13 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } break; - case GDParser::COMPLETION_CALL_ARGUMENTS: { + case GDScriptParser::COMPLETION_CALL_ARGUMENTS: { _find_call_arguments(context, p.get_completion_node(), p.get_completion_line(), p.get_completion_argument_index(), options, r_forced, r_call_hint); } break; - case GDParser::COMPLETION_VIRTUAL_FUNC: { + case GDScriptParser::COMPLETION_VIRTUAL_FUNC: { - GDCompletionIdentifier cid = _get_native_class(context); + GDScriptCompletionIdentifier cid = _get_native_class(context); if (cid.obj_type != StringName()) { List<MethodInfo> vm; @@ -2376,11 +2428,11 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } } break; - case GDParser::COMPLETION_YIELD: { + case GDScriptParser::COMPLETION_YIELD: { - const GDParser::Node *node = p.get_completion_node(); + const GDScriptParser::Node *node = p.get_completion_node(); - GDCompletionIdentifier t; + GDScriptCompletionIdentifier t; if (!_guess_expression_type(context, node, p.get_completion_line(), t)) break; @@ -2395,15 +2447,15 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base } } break; - case GDParser::COMPLETION_RESOURCE_PATH: { + case GDScriptParser::COMPLETION_RESOURCE_PATH: { if (EditorSettings::get_singleton()->get("text_editor/completion/complete_file_paths")) get_directory_contents(EditorFileSystem::get_singleton()->get_filesystem(), options); } break; - case GDParser::COMPLETION_ASSIGN: { + case GDScriptParser::COMPLETION_ASSIGN: { #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED) - GDCompletionIdentifier ci; + GDScriptCompletionIdentifier ci; if (_guess_expression_type(context, p.get_completion_node(), p.get_completion_line(), ci)) { String enumeration = ci.enumeration; @@ -2556,8 +2608,8 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } - for (int i = 0; i < GDFunctions::FUNC_MAX; i++) { - if (GDFunctions::get_func_name(GDFunctions::Function(i)) == p_symbol) { + for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) { + if (GDScriptFunctions::get_func_name(GDScriptFunctions::Function(i)) == p_symbol) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_METHOD; r_result.class_name = "@GDScript"; r_result.class_member = p_symbol; @@ -2565,13 +2617,13 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } - GDParser p; + GDScriptParser p; p.parse(p_code, p_base_path, false, "", true); - if (p.get_completion_type() == GDParser::COMPLETION_NONE) + if (p.get_completion_type() == GDScriptParser::COMPLETION_NONE) return ERR_CANT_RESOLVE; - GDCompletionContext context; + GDScriptCompletionContext context; context._class = p.get_completion_class(); context.block = p.get_completion_block(); @@ -2582,10 +2634,10 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol switch (p.get_completion_type()) { - case GDParser::COMPLETION_GET_NODE: - case GDParser::COMPLETION_NONE: { + case GDScriptParser::COMPLETION_GET_NODE: + case GDScriptParser::COMPLETION_NONE: { } break; - case GDParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: { + case GDScriptParser::COMPLETION_BUILT_IN_TYPE_CONSTANT: { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT; r_result.class_name = Variant::get_type_name(p.get_completion_built_in_constant()); @@ -2593,7 +2645,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol return OK; } break; - case GDParser::COMPLETION_FUNCTION: { + case GDScriptParser::COMPLETION_FUNCTION: { if (context._class && context._class->functions.size()) { for (int i = 0; i < context._class->functions.size(); i++) { @@ -2618,7 +2670,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol parent = parent->get_base(); } - GDCompletionIdentifier identifier = _get_native_class(context); + GDScriptCompletionIdentifier identifier = _get_native_class(context); print_line("identifier: " + String(identifier.obj_type)); if (ClassDB::has_method(identifier.obj_type, p_symbol)) { @@ -2630,7 +2682,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } break; - case GDParser::COMPLETION_IDENTIFIER: { + case GDScriptParser::COMPLETION_IDENTIFIER: { //check if a function if (p.get_completion_identifier_is_function()) { @@ -2657,7 +2709,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol parent = parent->get_base(); } - GDCompletionIdentifier identifier = _get_native_class(context); + GDScriptCompletionIdentifier identifier = _get_native_class(context); if (ClassDB::has_method(identifier.obj_type, p_symbol)) { @@ -2668,7 +2720,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } else { - GDCompletionIdentifier gdi = _get_native_class(context); + GDScriptCompletionIdentifier gdi = _get_native_class(context); if (gdi.obj_type != StringName()) { bool valid; Variant::Type t = ClassDB::get_property_type(gdi.obj_type, p_symbol, &valid); @@ -2680,7 +2732,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } - const GDParser::BlockNode *block = context.block; + const GDScriptParser::BlockNode *block = context.block; //search in blocks going up (local var?) while (block) { @@ -2689,9 +2741,9 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol if (block->statements[i]->line > p.get_completion_line()) continue; - if (block->statements[i]->type == GDParser::BlockNode::TYPE_LOCAL_VAR) { + if (block->statements[i]->type == GDScriptParser::BlockNode::TYPE_LOCAL_VAR) { - const GDParser::LocalVarNode *lv = static_cast<const GDParser::LocalVarNode *>(block->statements[i]); + const GDScriptParser::LocalVarNode *lv = static_cast<const GDScriptParser::LocalVarNode *>(block->statements[i]); if (lv->assign && lv->name == p_symbol) { @@ -2782,9 +2834,9 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol if (value.get_type() == Variant::OBJECT) { Object *obj = value; if (obj) { - if (Object::cast_to<GDNativeClass>(obj)) { + if (Object::cast_to<GDScriptNativeClass>(obj)) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; - r_result.class_name = Object::cast_to<GDNativeClass>(obj)->get_name(); + r_result.class_name = Object::cast_to<GDScriptNativeClass>(obj)->get_name(); } else { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS; r_result.class_name = obj->get_class(); @@ -2798,7 +2850,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } else { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT; - r_result.class_name = "@Global Scope"; + r_result.class_name = "@GlobalScope"; r_result.class_member = p_symbol; return OK; } @@ -2806,23 +2858,23 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } break; - case GDParser::COMPLETION_PARENT_FUNCTION: { + case GDScriptParser::COMPLETION_PARENT_FUNCTION: { } break; - case GDParser::COMPLETION_METHOD: + case GDScriptParser::COMPLETION_METHOD: isfunction = true; - case GDParser::COMPLETION_INDEX: { + case GDScriptParser::COMPLETION_INDEX: { - const GDParser::Node *node = p.get_completion_node(); - if (node->type != GDParser::Node::TYPE_OPERATOR) + const GDScriptParser::Node *node = p.get_completion_node(); + if (node->type != GDScriptParser::Node::TYPE_OPERATOR) break; - GDCompletionIdentifier t; - if (_guess_expression_type(context, static_cast<const GDParser::OperatorNode *>(node)->arguments[0], p.get_completion_line(), t)) { + GDScriptCompletionIdentifier t; + if (_guess_expression_type(context, static_cast<const GDScriptParser::OperatorNode *>(node)->arguments[0], p.get_completion_line(), t)) { - if (t.type == Variant::OBJECT && t.obj_type == "GDNativeClass") { + if (t.type == Variant::OBJECT && t.obj_type == "GDScriptNativeClass") { //native enum - Ref<GDNativeClass> gdn = t.value; + Ref<GDScriptNativeClass> gdn = t.value; if (gdn.is_valid()) { r_result.type = ScriptLanguage::LookupResult::RESULT_CLASS_CONSTANT; r_result.class_name = gdn->get_name(); @@ -2914,13 +2966,13 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } break; - case GDParser::COMPLETION_CALL_ARGUMENTS: { + case GDScriptParser::COMPLETION_CALL_ARGUMENTS: { return ERR_CANT_RESOLVE; } break; - case GDParser::COMPLETION_VIRTUAL_FUNC: { + case GDScriptParser::COMPLETION_VIRTUAL_FUNC: { - GDCompletionIdentifier cid = _get_native_class(context); + GDScriptCompletionIdentifier cid = _get_native_class(context); if (cid.obj_type != StringName()) { List<MethodInfo> vm; @@ -2937,7 +2989,7 @@ Error GDScriptLanguage::lookup_code(const String &p_code, const String &p_symbol } } } break; - case GDParser::COMPLETION_YIELD: { + case GDScriptParser::COMPLETION_YIELD: { return ERR_CANT_RESOLVE; diff --git a/modules/gdscript/gd_function.cpp b/modules/gdscript/gdscript_function.cpp index 1a46ad324a..765a76fec4 100644 --- a/modules/gdscript/gd_function.cpp +++ b/modules/gdscript/gdscript_function.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_function.cpp */ +/* gdscript_function.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,13 +27,13 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_function.h" +#include "gdscript_function.h" -#include "gd_functions.h" -#include "gd_script.h" +#include "gdscript.h" +#include "gdscript_functions.h" #include "os/os.h" -Variant *GDFunction::_get_variant(int p_address, GDInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const { +Variant *GDScriptFunction::_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const { int address = p_address & ADDR_MASK; @@ -85,7 +85,7 @@ Variant *GDFunction::_get_variant(int p_address, GDInstance *p_instance, GDScrip o = o->_owner; } - ERR_EXPLAIN("GDCompiler bug.."); + ERR_EXPLAIN("GDScriptCompiler bug.."); ERR_FAIL_V(NULL); } break; case ADDR_TYPE_LOCAL_CONSTANT: { @@ -117,7 +117,7 @@ Variant *GDFunction::_get_variant(int p_address, GDInstance *p_instance, GDScrip return NULL; } -String GDFunction::_get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const { +String GDScriptFunction::_get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const { String err_text; @@ -231,7 +231,7 @@ static String _get_var_type(const Variant *p_type) { #define OPCODE_OUT break #endif -Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError &r_err, CallState *p_state) { +Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError &r_err, CallState *p_state) { OPCODES_TABLE; @@ -479,7 +479,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a } else { - GDNativeClass *nc = Object::cast_to<GDNativeClass>(obj_B); + GDScriptNativeClass *nc = Object::cast_to<GDScriptNativeClass>(obj_B); #ifdef DEBUG_ENABLED if (!nc) { @@ -851,7 +851,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a CHECK_SPACE(4); - GDFunctions::Function func = GDFunctions::Function(_code_ptr[ip + 1]); + GDScriptFunctions::Function func = GDScriptFunctions::Function(_code_ptr[ip + 1]); int argc = _code_ptr[ip + 2]; GD_ERR_BREAK(argc < 0); @@ -868,12 +868,12 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a Variant::CallError err; - GDFunctions::call(func, (const Variant **)argptrs, argc, *dst, err); + GDScriptFunctions::call(func, (const Variant **)argptrs, argc, *dst, err); #ifdef DEBUG_ENABLED if (err.error != Variant::CallError::CALL_OK) { - String methodstr = GDFunctions::get_func_name(func); + String methodstr = GDScriptFunctions::get_func_name(func); if (dst->get_type() == Variant::STRING) { //call provided error string err_text = "Error calling built-in function '" + methodstr + "': " + String(*dst); @@ -921,7 +921,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a const GDScript *gds = _script; - const Map<StringName, GDFunction *>::Element *E = NULL; + const Map<StringName, GDScriptFunction *>::Element *E = NULL; while (gds->base.ptr()) { gds = gds->base.ptr(); E = gds->member_functions.find(*methodname); @@ -979,7 +979,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a CHECK_SPACE(2); } - Ref<GDFunctionState> gdfs = memnew(GDFunctionState); + Ref<GDScriptFunctionState> gdfs = memnew(GDScriptFunctionState); gdfs->function = this; gdfs->state.stack.resize(alloca_size); @@ -1321,43 +1321,43 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a return retvalue; } -const int *GDFunction::get_code() const { +const int *GDScriptFunction::get_code() const { return _code_ptr; } -int GDFunction::get_code_size() const { +int GDScriptFunction::get_code_size() const { return _code_size; } -Variant GDFunction::get_constant(int p_idx) const { +Variant GDScriptFunction::get_constant(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, constants.size(), "<errconst>"); return constants[p_idx]; } -StringName GDFunction::get_global_name(int p_idx) const { +StringName GDScriptFunction::get_global_name(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, global_names.size(), "<errgname>"); return global_names[p_idx]; } -int GDFunction::get_default_argument_count() const { +int GDScriptFunction::get_default_argument_count() const { return default_arguments.size(); } -int GDFunction::get_default_argument_addr(int p_idx) const { +int GDScriptFunction::get_default_argument_addr(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, default_arguments.size(), -1); return default_arguments[p_idx]; } -StringName GDFunction::get_name() const { +StringName GDScriptFunction::get_name() const { return name; } -int GDFunction::get_max_stack_size() const { +int GDScriptFunction::get_max_stack_size() const { return _stack_size; } @@ -1380,7 +1380,7 @@ struct _GDFKCS { } }; -void GDFunction::debug_get_stack_member_state(int p_line, List<Pair<StringName, int> > *r_stackvars) const { +void GDScriptFunction::debug_get_stack_member_state(int p_line, List<Pair<StringName, int> > *r_stackvars) const { int oc = 0; Map<StringName, _GDFKC> sdmap; @@ -1432,7 +1432,7 @@ void GDFunction::debug_get_stack_member_state(int p_line, List<Pair<StringName, } } -GDFunction::GDFunction() +GDScriptFunction::GDScriptFunction() : function_list(this) { _stack_size = 0; @@ -1464,7 +1464,7 @@ GDFunction::GDFunction() #endif } -GDFunction::~GDFunction() { +GDScriptFunction::~GDScriptFunction() { #ifdef DEBUG_ENABLED if (GDScriptLanguage::get_singleton()->lock) { GDScriptLanguage::get_singleton()->lock->lock(); @@ -1479,7 +1479,7 @@ GDFunction::~GDFunction() { ///////////////////// -Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { +Variant GDScriptFunctionState::_signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { #ifdef DEBUG_ENABLED if (state.instance_id && !ObjectDB::get_instance(state.instance_id)) { @@ -1514,7 +1514,7 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount arg = extra_args; } - Ref<GDFunctionState> self = *p_args[p_argcount - 1]; + Ref<GDScriptFunctionState> self = *p_args[p_argcount - 1]; if (self.is_null()) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; @@ -1528,10 +1528,10 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount bool completed = true; - // If the return value is a GDFunctionState reference, + // If the return value is a GDScriptFunctionState reference, // then the function did yield again after resuming. if (ret.is_ref()) { - GDFunctionState *gdfs = Object::cast_to<GDFunctionState>(ret); + GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret); if (gdfs && gdfs->function == function) completed = false; } @@ -1546,7 +1546,7 @@ Variant GDFunctionState::_signal_callback(const Variant **p_args, int p_argcount return ret; } -bool GDFunctionState::is_valid(bool p_extended_check) const { +bool GDScriptFunctionState::is_valid(bool p_extended_check) const { if (function == NULL) return false; @@ -1563,7 +1563,7 @@ bool GDFunctionState::is_valid(bool p_extended_check) const { return true; } -Variant GDFunctionState::resume(const Variant &p_arg) { +Variant GDScriptFunctionState::resume(const Variant &p_arg) { ERR_FAIL_COND_V(!function, Variant()); #ifdef DEBUG_ENABLED @@ -1584,10 +1584,10 @@ Variant GDFunctionState::resume(const Variant &p_arg) { bool completed = true; - // If the return value is a GDFunctionState reference, + // If the return value is a GDScriptFunctionState reference, // then the function did yield again after resuming. if (ret.is_ref()) { - GDFunctionState *gdfs = Object::cast_to<GDFunctionState>(ret); + GDScriptFunctionState *gdfs = Object::cast_to<GDScriptFunctionState>(ret); if (gdfs && gdfs->function == function) completed = false; } @@ -1602,21 +1602,21 @@ Variant GDFunctionState::resume(const Variant &p_arg) { return ret; } -void GDFunctionState::_bind_methods() { +void GDScriptFunctionState::_bind_methods() { - ClassDB::bind_method(D_METHOD("resume", "arg"), &GDFunctionState::resume, DEFVAL(Variant())); - ClassDB::bind_method(D_METHOD("is_valid", "extended_check"), &GDFunctionState::is_valid, DEFVAL(false)); - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &GDFunctionState::_signal_callback, MethodInfo("_signal_callback")); + ClassDB::bind_method(D_METHOD("resume", "arg"), &GDScriptFunctionState::resume, DEFVAL(Variant())); + ClassDB::bind_method(D_METHOD("is_valid", "extended_check"), &GDScriptFunctionState::is_valid, DEFVAL(false)); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "_signal_callback", &GDScriptFunctionState::_signal_callback, MethodInfo("_signal_callback")); ADD_SIGNAL(MethodInfo("completed", PropertyInfo(Variant::NIL, "result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT))); } -GDFunctionState::GDFunctionState() { +GDScriptFunctionState::GDScriptFunctionState() { function = NULL; } -GDFunctionState::~GDFunctionState() { +GDScriptFunctionState::~GDScriptFunctionState() { if (function != NULL) { //never called, deinitialize stack diff --git a/modules/gdscript/gd_function.h b/modules/gdscript/gdscript_function.h index bf5ff5f8da..03fd5d52dc 100644 --- a/modules/gdscript/gd_function.h +++ b/modules/gdscript/gdscript_function.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_function.h */ +/* gdscript_function.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,8 +27,8 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GD_FUNCTION_H -#define GD_FUNCTION_H +#ifndef GDSCRIPT_FUNCTION_H +#define GDSCRIPT_FUNCTION_H #include "os/thread.h" #include "pair.h" @@ -38,10 +38,10 @@ #include "string_db.h" #include "variant.h" -class GDInstance; +class GDScriptInstance; class GDScript; -class GDFunction { +class GDScriptFunction { public: enum Opcode { OPCODE_OPERATOR, @@ -111,7 +111,7 @@ public: }; private: - friend class GDCompiler; + friend class GDScriptCompiler; StringName source; @@ -145,12 +145,12 @@ private: List<StackDebug> stack_debug; - _FORCE_INLINE_ Variant *_get_variant(int p_address, GDInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const; + _FORCE_INLINE_ Variant *_get_variant(int p_address, GDScriptInstance *p_instance, GDScript *p_script, Variant &self, Variant *p_stack, String &r_error) const; _FORCE_INLINE_ String _get_call_error(const Variant::CallError &p_err, const String &p_where, const Variant **argptrs) const; friend class GDScriptLanguage; - SelfList<GDFunction> function_list; + SelfList<GDScriptFunction> function_list; #ifdef DEBUG_ENABLED CharString func_cname; const char *_func_cname; @@ -176,7 +176,7 @@ public: ObjectID instance_id; //by debug only ObjectID script_id; - GDInstance *instance; + GDScriptInstance *instance; Vector<uint8_t> stack; int stack_size; Variant self; @@ -219,19 +219,19 @@ public: return default_arguments[p_idx]; } - Variant call(GDInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError &r_err, CallState *p_state = NULL); + Variant call(GDScriptInstance *p_instance, const Variant **p_args, int p_argcount, Variant::CallError &r_err, CallState *p_state = NULL); _FORCE_INLINE_ ScriptInstance::RPCMode get_rpc_mode() const { return rpc_mode; } - GDFunction(); - ~GDFunction(); + GDScriptFunction(); + ~GDScriptFunction(); }; -class GDFunctionState : public Reference { +class GDScriptFunctionState : public Reference { - GDCLASS(GDFunctionState, Reference); - friend class GDFunction; - GDFunction *function; - GDFunction::CallState state; + GDCLASS(GDScriptFunctionState, Reference); + friend class GDScriptFunction; + GDScriptFunction *function; + GDScriptFunction::CallState state; Variant _signal_callback(const Variant **p_args, int p_argcount, Variant::CallError &r_error); protected: @@ -240,8 +240,8 @@ protected: public: bool is_valid(bool p_extended_check = false) const; Variant resume(const Variant &p_arg = Variant()); - GDFunctionState(); - ~GDFunctionState(); + GDScriptFunctionState(); + ~GDScriptFunctionState(); }; -#endif // GD_FUNCTION_H +#endif // GDSCRIPT_FUNCTION_H diff --git a/modules/gdscript/gd_functions.cpp b/modules/gdscript/gdscript_functions.cpp index b43ec409a1..ca0a9582a7 100644 --- a/modules/gdscript/gd_functions.cpp +++ b/modules/gdscript/gdscript_functions.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_functions.cpp */ +/* gdscript_functions.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,10 +27,11 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_functions.h" +#include "gdscript_functions.h" + #include "class_db.h" #include "func_ref.h" -#include "gd_script.h" +#include "gdscript.h" #include "io/json.h" #include "io/marshalls.h" #include "math_funcs.h" @@ -38,7 +39,7 @@ #include "reference.h" #include "variant_parser.h" -const char *GDFunctions::get_func_name(Function p_func) { +const char *GDScriptFunctions::get_func_name(Function p_func) { ERR_FAIL_INDEX_V(p_func, FUNC_MAX, ""); @@ -83,6 +84,8 @@ const char *GDFunctions::get_func_name(Function p_func) { "rad2deg", "linear2db", "db2linear", + "polar2cartesian", + "cartesian2polar", "wrapi", "wrapf", "max", @@ -123,7 +126,7 @@ const char *GDFunctions::get_func_name(Function p_func) { return _names[p_func]; } -void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, Variant &r_ret, Variant::CallError &r_error) { +void GDScriptFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, Variant &r_ret, Variant::CallError &r_error) { r_error.error = Variant::CallError::CALL_OK; #ifdef DEBUG_ENABLED @@ -407,6 +410,22 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, 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]); @@ -641,7 +660,7 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, } //str+="\n"; - OS::get_singleton()->printerr("%s\n", str.utf8().get_data()); + print_error(str); r_ret = Variant(); } break; @@ -899,7 +918,7 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, return; } else { - GDInstance *ins = static_cast<GDInstance *>(obj->get_script_instance()); + GDScriptInstance *ins = static_cast<GDScriptInstance *>(obj->get_script_instance()); Ref<GDScript> base = ins->get_script(); if (base.is_null()) { @@ -1030,7 +1049,7 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, r_ret = gdscr->_new(NULL, 0, r_error); - GDInstance *ins = static_cast<GDInstance *>(static_cast<Object *>(r_ret)->get_script_instance()); + GDScriptInstance *ins = static_cast<GDScriptInstance *>(static_cast<Object *>(r_ret)->get_script_instance()); Ref<GDScript> gd_ref = ins->get_script(); for (Map<StringName, GDScript::MemberInfo>::Element *E = gd_ref->member_indices.front(); E; E = E->next()) { @@ -1254,7 +1273,7 @@ void GDFunctions::call(Function p_func, const Variant **p_args, int p_arg_count, } } -bool GDFunctions::is_deterministic(Function p_func) { +bool GDScriptFunctions::is_deterministic(Function p_func) { //man i couldn't have chosen a worse function name, //way too controversial.. @@ -1295,6 +1314,8 @@ bool GDFunctions::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: @@ -1317,7 +1338,7 @@ bool GDFunctions::is_deterministic(Function p_func) { return false; } -MethodInfo GDFunctions::get_info(Function p_func) { +MethodInfo GDScriptFunctions::get_info(Function p_func) { #ifdef TOOLS_ENABLED //using a switch, so the compiler generates a jumptable @@ -1525,6 +1546,16 @@ MethodInfo GDFunctions::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/gd_functions.h b/modules/gdscript/gdscript_functions.h index 0de09f2e71..d1c5815cec 100644 --- a/modules/gdscript/gd_functions.h +++ b/modules/gdscript/gdscript_functions.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_functions.h */ +/* gdscript_functions.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,12 +27,12 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GD_FUNCTIONS_H -#define GD_FUNCTIONS_H +#ifndef GDSCRIPT_FUNCTIONS_H +#define GDSCRIPT_FUNCTIONS_H #include "variant.h" -class GDFunctions { +class GDScriptFunctions { public: enum Function { MATH_SIN, @@ -75,6 +75,8 @@ public: MATH_RAD2DEG, MATH_LINEAR2DB, MATH_DB2LINEAR, + MATH_POLAR2CARTESIAN, + MATH_CARTESIAN2POLAR, MATH_WRAP, MATH_WRAPF, LOGIC_MAX, @@ -120,4 +122,4 @@ public: static MethodInfo get_info(Function p_func); }; -#endif // GD_FUNCTIONS_H +#endif // GDSCRIPT_FUNCTIONS_H diff --git a/modules/gdscript/gd_parser.cpp b/modules/gdscript/gdscript_parser.cpp index d7e83c3a33..bee9ef1998 100644 --- a/modules/gdscript/gd_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_parser.cpp */ +/* gdscript_parser.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,15 +27,16 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_parser.h" -#include "gd_script.h" +#include "gdscript_parser.h" + +#include "gdscript.h" #include "io/resource_loader.h" #include "os/file_access.h" #include "print_string.h" #include "script_language.h" template <class T> -T *GDParser::alloc_node() { +T *GDScriptParser::alloc_node() { T *t = memnew(T); @@ -50,21 +51,21 @@ T *GDParser::alloc_node() { return t; } -bool GDParser::_end_statement() { +bool GDScriptParser::_end_statement() { - if (tokenizer->get_token() == GDTokenizer::TK_SEMICOLON) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_SEMICOLON) { tokenizer->advance(); return true; //handle next - } else if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE || tokenizer->get_token() == GDTokenizer::TK_EOF) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE || tokenizer->get_token() == GDScriptTokenizer::TK_EOF) { return true; //will be handled properly } return false; } -bool GDParser::_enter_indent_block(BlockNode *p_block) { +bool GDScriptParser::_enter_indent_block(BlockNode *p_block) { - if (tokenizer->get_token() != GDTokenizer::TK_COLON) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COLON) { // report location at the previous token (on the previous line) int error_line = tokenizer->get_token_line(-1); int error_column = tokenizer->get_token_column(-1); @@ -73,7 +74,7 @@ bool GDParser::_enter_indent_block(BlockNode *p_block) { } tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_NEWLINE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_NEWLINE) { // be more python-like int current = tab_level.back()->get(); @@ -85,10 +86,10 @@ bool GDParser::_enter_indent_block(BlockNode *p_block) { while (true) { - if (tokenizer->get_token() != GDTokenizer::TK_NEWLINE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_NEWLINE) { return false; //wtf - } else if (tokenizer->get_token(1) != GDTokenizer::TK_NEWLINE) { + } else if (tokenizer->get_token(1) != GDScriptTokenizer::TK_NEWLINE) { int indent = tokenizer->get_token_line_indent(); int current = tab_level.back()->get(); @@ -113,9 +114,9 @@ bool GDParser::_enter_indent_block(BlockNode *p_block) { } } -bool GDParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_static, bool p_can_codecomplete) { +bool GDScriptParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_static, bool p_can_codecomplete) { - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { tokenizer->advance(); } else { @@ -124,10 +125,10 @@ bool GDParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_s while (true) { - if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { _make_completable_call(argidx); completion_node = p_parent; - } else if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING && tokenizer->get_token(1) == GDTokenizer::TK_CURSOR) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING && tokenizer->get_token(1) == GDScriptTokenizer::TK_CURSOR) { //completing a string argument.. completion_cursor = tokenizer->get_token_constant(); @@ -143,13 +144,13 @@ bool GDParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_s p_args.push_back(arg); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { tokenizer->advance(); break; - } else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { - if (tokenizer->get_token(1) == GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token(1) == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expression expected"); return false; @@ -169,7 +170,7 @@ bool GDParser::_parse_arguments(Node *p_parent, Vector<Node *> &p_args, bool p_s return true; } -void GDParser::_make_completable_call(int p_arg) { +void GDScriptParser::_make_completable_call(int p_arg) { completion_cursor = StringName(); completion_type = COMPLETION_CALL_ARGUMENTS; @@ -182,14 +183,14 @@ void GDParser::_make_completable_call(int p_arg) { tokenizer->advance(); } -bool GDParser::_get_completable_identifier(CompletionType p_type, StringName &identifier) { +bool GDScriptParser::_get_completable_identifier(CompletionType p_type, StringName &identifier) { identifier = StringName(); if (tokenizer->is_token_literal()) { identifier = tokenizer->get_token_literal(); tokenizer->advance(); } - if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { completion_cursor = identifier; completion_type = p_type; @@ -206,7 +207,7 @@ bool GDParser::_get_completable_identifier(CompletionType p_type, StringName &id tokenizer->advance(); } - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_OPEN) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { completion_ident_is_call = true; } return true; @@ -215,7 +216,7 @@ bool GDParser::_get_completable_identifier(CompletionType p_type, StringName &id return false; } -GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool p_allow_assign, bool p_parsing_constant) { +GDScriptParser::Node *GDScriptParser::_parse_expression(Node *p_parent, bool p_static, bool p_allow_assign, bool p_parsing_constant) { //Vector<Node*> expressions; //Vector<OperatorNode::Operator> operators; @@ -234,12 +235,12 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool if (parenthesis > 0) { //remove empty space (only allowed if inside parenthesis - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); } } - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_OPEN) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { //subexpression () tokenizer->advance(); parenthesis++; @@ -248,7 +249,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool if (!subexpr) return NULL; - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' in expression"); return NULL; @@ -256,7 +257,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool tokenizer->advance(); expr = subexpr; - } else if (tokenizer->get_token() == GDTokenizer::TK_DOLLAR) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_DOLLAR) { tokenizer->advance(); String path; @@ -267,7 +268,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool while (!done) { switch (tokenizer->get_token()) { - case GDTokenizer::TK_CURSOR: { + case GDScriptTokenizer::TK_CURSOR: { completion_cursor = StringName(); completion_type = COMPLETION_GET_NODE; completion_class = current_class; @@ -279,7 +280,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool completion_found = true; tokenizer->advance(); } break; - case GDTokenizer::TK_CONSTANT: { + case GDScriptTokenizer::TK_CONSTANT: { if (!need_identifier) { done = true; @@ -296,7 +297,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool need_identifier = false; } break; - case GDTokenizer::TK_OP_DIV: { + case GDScriptTokenizer::TK_OP_DIV: { if (need_identifier) { done = true; @@ -344,56 +345,56 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool expr = op; - } else if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { tokenizer->advance(); continue; //no point in cursor in the middle of expression - } else if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT) { //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = tokenizer->get_token_constant(); tokenizer->advance(); expr = constant; - } else if (tokenizer->get_token() == GDTokenizer::TK_CONST_PI) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONST_PI) { //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = Math_PI; tokenizer->advance(); expr = constant; - } else if (tokenizer->get_token() == GDTokenizer::TK_CONST_TAU) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONST_TAU) { //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = Math_TAU; tokenizer->advance(); expr = constant; - } else if (tokenizer->get_token() == GDTokenizer::TK_CONST_INF) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONST_INF) { //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = Math_INF; tokenizer->advance(); expr = constant; - } else if (tokenizer->get_token() == GDTokenizer::TK_CONST_NAN) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CONST_NAN) { //constant defined by tokenizer ConstantNode *constant = alloc_node<ConstantNode>(); constant->value = Math_NAN; tokenizer->advance(); expr = constant; - } else if (tokenizer->get_token() == GDTokenizer::TK_PR_PRELOAD) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_PRELOAD) { //constant defined by tokenizer tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_OPEN) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after 'preload'"); return NULL; } tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { completion_cursor = StringName(); completion_node = p_parent; completion_type = COMPLETION_RESOURCE_PATH; @@ -473,7 +474,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool } } - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' after 'preload' path"); return NULL; } @@ -483,12 +484,12 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool constant->value = res; expr = constant; - } else if (tokenizer->get_token() == GDTokenizer::TK_PR_YIELD) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_YIELD) { //constant defined by tokenizer tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_OPEN) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after 'yield'"); return NULL; } @@ -498,11 +499,11 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool OperatorNode *yield = alloc_node<OperatorNode>(); yield->op = OperatorNode::OP_YIELD; - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); } - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { expr = yield; tokenizer->advance(); } else { @@ -514,14 +515,14 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool return NULL; yield->arguments.push_back(object); - if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { _set_error("Expected ',' after first argument of 'yield'"); return NULL; } tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { completion_cursor = StringName(); completion_node = object; @@ -540,7 +541,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool return NULL; yield->arguments.push_back(signal); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' after second argument of 'yield'"); return NULL; } @@ -552,7 +553,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool expr = yield; } - } else if (tokenizer->get_token() == GDTokenizer::TK_SELF) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_SELF) { if (p_static) { _set_error("'self'' not allowed in static function or constant expression"); @@ -562,7 +563,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool SelfNode *self = alloc_node<SelfNode>(); tokenizer->advance(); expr = self; - } else if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token(1) == GDScriptTokenizer::TK_PERIOD) { Variant::Type bi_type = tokenizer->get_token_type(); tokenizer->advance(2); @@ -589,20 +590,20 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool cn->value = Variant::get_numeric_constant_value(bi_type, identifier); expr = cn; - } else if (tokenizer->get_token(1) == GDTokenizer::TK_PARENTHESIS_OPEN && tokenizer->is_token_literal()) { + } else if (tokenizer->get_token(1) == GDScriptTokenizer::TK_PARENTHESIS_OPEN && tokenizer->is_token_literal()) { // We check with is_token_literal, as this allows us to use match/sync/etc. as a name //function or constructor OperatorNode *op = alloc_node<OperatorNode>(); op->op = OperatorNode::OP_CALL; - if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE) { TypeNode *tn = alloc_node<TypeNode>(); tn->vtype = tokenizer->get_token_type(); op->arguments.push_back(tn); tokenizer->advance(2); - } else if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_FUNC) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC) { BuiltInFunctionNode *bn = alloc_node<BuiltInFunctionNode>(); bn->function = tokenizer->get_token_built_in_func(); @@ -623,7 +624,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool tokenizer->advance(1); } - if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { _make_completable_call(0); completion_node = op; } @@ -668,7 +669,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool expr = id; } - } else if (tokenizer->get_token() == GDTokenizer::TK_OP_ADD || tokenizer->get_token() == GDTokenizer::TK_OP_SUB || tokenizer->get_token() == GDTokenizer::TK_OP_NOT || tokenizer->get_token() == GDTokenizer::TK_OP_BIT_INVERT) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ADD || tokenizer->get_token() == GDScriptTokenizer::TK_OP_SUB || tokenizer->get_token() == GDScriptTokenizer::TK_OP_NOT || tokenizer->get_token() == GDScriptTokenizer::TK_OP_BIT_INVERT) { //single prefix operators like !expr +expr -expr ++expr --expr alloc_node<OperatorNode>(); @@ -676,16 +677,16 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool e.is_op = true; switch (tokenizer->get_token()) { - case GDTokenizer::TK_OP_ADD: e.op = OperatorNode::OP_POS; break; - case GDTokenizer::TK_OP_SUB: e.op = OperatorNode::OP_NEG; break; - case GDTokenizer::TK_OP_NOT: e.op = OperatorNode::OP_NOT; break; - case GDTokenizer::TK_OP_BIT_INVERT: e.op = OperatorNode::OP_BIT_INVERT; break; + case GDScriptTokenizer::TK_OP_ADD: e.op = OperatorNode::OP_POS; break; + case GDScriptTokenizer::TK_OP_SUB: e.op = OperatorNode::OP_NEG; break; + case GDScriptTokenizer::TK_OP_NOT: e.op = OperatorNode::OP_NOT; break; + case GDScriptTokenizer::TK_OP_BIT_INVERT: e.op = OperatorNode::OP_BIT_INVERT; break; default: {} } tokenizer->advance(); - if (e.op != OperatorNode::OP_NOT && tokenizer->get_token() == GDTokenizer::TK_OP_NOT) { + if (e.op != OperatorNode::OP_NOT && tokenizer->get_token() == GDScriptTokenizer::TK_OP_NOT) { _set_error("Misplaced 'not'."); return NULL; } @@ -700,7 +701,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool op->arguments.push_back(subexpr); expr=op;*/ - } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_OPEN) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BRACKET_OPEN) { // array tokenizer->advance(); @@ -709,18 +710,18 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool while (true) { - if (tokenizer->get_token() == GDTokenizer::TK_EOF) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_EOF) { _set_error("Unterminated array"); return NULL; - } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BRACKET_CLOSE) { tokenizer->advance(); break; - } else if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); //ignore newline - } else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { if (!expecting_comma) { _set_error("expression or ']' expected"); return NULL; @@ -743,7 +744,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool } expr = arr; - } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_OPEN) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_OPEN) { // array tokenizer->advance(); @@ -765,12 +766,12 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool while (true) { - if (tokenizer->get_token() == GDTokenizer::TK_EOF) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_EOF) { _set_error("Unterminated dictionary"); return NULL; - } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { if (expecting == DICT_EXPECT_COLON) { _set_error("':' expected"); @@ -782,10 +783,10 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool } tokenizer->advance(); break; - } else if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); //ignore newline - } else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { if (expecting == DICT_EXPECT_KEY) { _set_error("key or '}' expected"); @@ -803,7 +804,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool expecting = DICT_EXPECT_KEY; tokenizer->advance(); //ignore newline - } else if (tokenizer->get_token() == GDTokenizer::TK_COLON) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_COLON) { if (expecting == DICT_EXPECT_KEY) { _set_error("key or '}' expected"); @@ -833,7 +834,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool if (expecting == DICT_EXPECT_KEY) { - if (tokenizer->is_token_literal() && tokenizer->get_token(1) == GDTokenizer::TK_OP_ASSIGN) { + if (tokenizer->is_token_literal() && tokenizer->get_token(1) == GDScriptTokenizer::TK_OP_ASSIGN) { // We check with is_token_literal, as this allows us to use match/sync/etc. as a name //lua style identifier, easier to write ConstantNode *cn = alloc_node<ConstantNode>(); @@ -856,8 +857,8 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool return NULL; expecting = DICT_EXPECT_COMMA; - if (key->type == GDParser::Node::TYPE_CONSTANT) { - Variant const &keyName = static_cast<const GDParser::ConstantNode *>(key)->value; + if (key->type == GDScriptParser::Node::TYPE_CONSTANT) { + Variant const &keyName = static_cast<const GDScriptParser::ConstantNode *>(key)->value; if (keys.has(keyName)) { _set_error("Duplicate key found in Dictionary literal"); @@ -877,7 +878,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool expr = dict; - } else if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && (tokenizer->is_token_literal(1) || tokenizer->get_token(1) == GDTokenizer::TK_CURSOR) && tokenizer->get_token(2) == GDTokenizer::TK_PARENTHESIS_OPEN) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD && (tokenizer->is_token_literal(1) || tokenizer->get_token(1) == GDScriptTokenizer::TK_CURSOR) && tokenizer->get_token(2) == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { // We check with is_token_literal, as this allows us to use match/sync/etc. as a name // parent call @@ -914,7 +915,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool } if (!expr) { - ERR_EXPLAIN("GDParser bug, couldn't figure out what expression is.."); + ERR_EXPLAIN("GDScriptParser bug, couldn't figure out what expression is.."); ERR_FAIL_COND_V(!expr, NULL); } @@ -926,15 +927,15 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool //expressions can be indexed any number of times - if (tokenizer->get_token() == GDTokenizer::TK_PERIOD) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD) { //indexing using "." - if (tokenizer->get_token(1) != GDTokenizer::TK_CURSOR && !tokenizer->is_token_literal(1)) { + if (tokenizer->get_token(1) != GDScriptTokenizer::TK_CURSOR && !tokenizer->is_token_literal(1)) { // We check with is_token_literal, as this allows us to use match/sync/etc. as a name _set_error("Expected identifier as member"); return NULL; - } else if (tokenizer->get_token(2) == GDTokenizer::TK_PARENTHESIS_OPEN) { + } else if (tokenizer->get_token(2) == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { //call!! OperatorNode *op = alloc_node<OperatorNode>(); op->op = OperatorNode::OP_CALL; @@ -942,10 +943,10 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool tokenizer->advance(); IdentifierNode *id = alloc_node<IdentifierNode>(); - if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_FUNC) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_FUNC) { //small hack so built in funcs don't obfuscate methods - id->name = GDFunctions::get_func_name(tokenizer->get_token_built_in_func()); + id->name = GDScriptFunctions::get_func_name(tokenizer->get_token_built_in_func()); tokenizer->advance(); } else { @@ -962,7 +963,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool op->arguments.push_back(id); // call func //get arguments tokenizer->advance(1); - if (tokenizer->get_token() == GDTokenizer::TK_CURSOR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CURSOR) { _make_completable_call(0); completion_node = op; } @@ -997,7 +998,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool expr = op; } - } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_OPEN) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BRACKET_OPEN) { //indexing using "[]" OperatorNode *op = alloc_node<OperatorNode>(); op->op = OperatorNode::OP_INDEX; @@ -1009,7 +1010,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool return NULL; } - if (tokenizer->get_token() != GDTokenizer::TK_BRACKET_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_BRACKET_CLOSE) { _set_error("Expected ']'"); return NULL; } @@ -1029,7 +1030,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool if (parenthesis > 0) { //remove empty space (only allowed if inside parenthesis - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); } } @@ -1054,29 +1055,29 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool switch (tokenizer->get_token()) { //see operator - case GDTokenizer::TK_OP_IN: op = OperatorNode::OP_IN; break; - case GDTokenizer::TK_OP_EQUAL: op = OperatorNode::OP_EQUAL; break; - case GDTokenizer::TK_OP_NOT_EQUAL: op = OperatorNode::OP_NOT_EQUAL; break; - case GDTokenizer::TK_OP_LESS: op = OperatorNode::OP_LESS; break; - case GDTokenizer::TK_OP_LESS_EQUAL: op = OperatorNode::OP_LESS_EQUAL; break; - case GDTokenizer::TK_OP_GREATER: op = OperatorNode::OP_GREATER; break; - case GDTokenizer::TK_OP_GREATER_EQUAL: op = OperatorNode::OP_GREATER_EQUAL; break; - case GDTokenizer::TK_OP_AND: op = OperatorNode::OP_AND; break; - case GDTokenizer::TK_OP_OR: op = OperatorNode::OP_OR; break; - case GDTokenizer::TK_OP_ADD: op = OperatorNode::OP_ADD; break; - case GDTokenizer::TK_OP_SUB: op = OperatorNode::OP_SUB; break; - case GDTokenizer::TK_OP_MUL: op = OperatorNode::OP_MUL; break; - case GDTokenizer::TK_OP_DIV: op = OperatorNode::OP_DIV; break; - case GDTokenizer::TK_OP_MOD: + case GDScriptTokenizer::TK_OP_IN: op = OperatorNode::OP_IN; break; + case GDScriptTokenizer::TK_OP_EQUAL: op = OperatorNode::OP_EQUAL; break; + case GDScriptTokenizer::TK_OP_NOT_EQUAL: op = OperatorNode::OP_NOT_EQUAL; break; + case GDScriptTokenizer::TK_OP_LESS: op = OperatorNode::OP_LESS; break; + case GDScriptTokenizer::TK_OP_LESS_EQUAL: op = OperatorNode::OP_LESS_EQUAL; break; + case GDScriptTokenizer::TK_OP_GREATER: op = OperatorNode::OP_GREATER; break; + case GDScriptTokenizer::TK_OP_GREATER_EQUAL: op = OperatorNode::OP_GREATER_EQUAL; break; + case GDScriptTokenizer::TK_OP_AND: op = OperatorNode::OP_AND; break; + case GDScriptTokenizer::TK_OP_OR: op = OperatorNode::OP_OR; break; + case GDScriptTokenizer::TK_OP_ADD: op = OperatorNode::OP_ADD; break; + case GDScriptTokenizer::TK_OP_SUB: op = OperatorNode::OP_SUB; break; + case GDScriptTokenizer::TK_OP_MUL: op = OperatorNode::OP_MUL; break; + case GDScriptTokenizer::TK_OP_DIV: op = OperatorNode::OP_DIV; break; + case GDScriptTokenizer::TK_OP_MOD: op = OperatorNode::OP_MOD; break; - //case GDTokenizer::TK_OP_NEG: op=OperatorNode::OP_NEG ; break; - case GDTokenizer::TK_OP_SHIFT_LEFT: op = OperatorNode::OP_SHIFT_LEFT; break; - case GDTokenizer::TK_OP_SHIFT_RIGHT: op = OperatorNode::OP_SHIFT_RIGHT; break; - case GDTokenizer::TK_OP_ASSIGN: { + //case GDScriptTokenizer::TK_OP_NEG: op=OperatorNode::OP_NEG ; break; + case GDScriptTokenizer::TK_OP_SHIFT_LEFT: op = OperatorNode::OP_SHIFT_LEFT; break; + case GDScriptTokenizer::TK_OP_SHIFT_RIGHT: op = OperatorNode::OP_SHIFT_RIGHT; break; + case GDScriptTokenizer::TK_OP_ASSIGN: { _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN; - if (tokenizer->get_token(1) == GDTokenizer::TK_CURSOR) { + if (tokenizer->get_token(1) == GDScriptTokenizer::TK_CURSOR) { //code complete assignment completion_type = COMPLETION_ASSIGN; completion_node = expr; @@ -1089,22 +1090,22 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool } } break; - case GDTokenizer::TK_OP_ASSIGN_ADD: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_ADD; break; - case GDTokenizer::TK_OP_ASSIGN_SUB: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SUB; break; - case GDTokenizer::TK_OP_ASSIGN_MUL: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_MUL; break; - case GDTokenizer::TK_OP_ASSIGN_DIV: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_DIV; break; - case GDTokenizer::TK_OP_ASSIGN_MOD: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_MOD; break; - case GDTokenizer::TK_OP_ASSIGN_SHIFT_LEFT: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SHIFT_LEFT; break; - case GDTokenizer::TK_OP_ASSIGN_SHIFT_RIGHT: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SHIFT_RIGHT; break; - case GDTokenizer::TK_OP_ASSIGN_BIT_AND: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_AND; break; - case GDTokenizer::TK_OP_ASSIGN_BIT_OR: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_OR; break; - case GDTokenizer::TK_OP_ASSIGN_BIT_XOR: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_XOR; break; - case GDTokenizer::TK_OP_BIT_AND: op = OperatorNode::OP_BIT_AND; break; - case GDTokenizer::TK_OP_BIT_OR: op = OperatorNode::OP_BIT_OR; break; - case GDTokenizer::TK_OP_BIT_XOR: op = OperatorNode::OP_BIT_XOR; break; - case GDTokenizer::TK_PR_IS: op = OperatorNode::OP_IS; break; - case GDTokenizer::TK_CF_IF: op = OperatorNode::OP_TERNARY_IF; break; - case GDTokenizer::TK_CF_ELSE: op = OperatorNode::OP_TERNARY_ELSE; break; + case GDScriptTokenizer::TK_OP_ASSIGN_ADD: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_ADD; break; + case GDScriptTokenizer::TK_OP_ASSIGN_SUB: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SUB; break; + case GDScriptTokenizer::TK_OP_ASSIGN_MUL: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_MUL; break; + case GDScriptTokenizer::TK_OP_ASSIGN_DIV: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_DIV; break; + case GDScriptTokenizer::TK_OP_ASSIGN_MOD: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_MOD; break; + case GDScriptTokenizer::TK_OP_ASSIGN_SHIFT_LEFT: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SHIFT_LEFT; break; + case GDScriptTokenizer::TK_OP_ASSIGN_SHIFT_RIGHT: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_SHIFT_RIGHT; break; + case GDScriptTokenizer::TK_OP_ASSIGN_BIT_AND: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_AND; break; + case GDScriptTokenizer::TK_OP_ASSIGN_BIT_OR: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_OR; break; + case GDScriptTokenizer::TK_OP_ASSIGN_BIT_XOR: _VALIDATE_ASSIGN op = OperatorNode::OP_ASSIGN_BIT_XOR; break; + case GDScriptTokenizer::TK_OP_BIT_AND: op = OperatorNode::OP_BIT_AND; break; + case GDScriptTokenizer::TK_OP_BIT_OR: op = OperatorNode::OP_BIT_OR; break; + case GDScriptTokenizer::TK_OP_BIT_XOR: op = OperatorNode::OP_BIT_XOR; break; + case GDScriptTokenizer::TK_PR_IS: op = OperatorNode::OP_IS; break; + case GDScriptTokenizer::TK_CF_IF: op = OperatorNode::OP_TERNARY_IF; break; + case GDScriptTokenizer::TK_CF_ELSE: op = OperatorNode::OP_TERNARY_ELSE; break; default: valid = false; break; } @@ -1212,7 +1213,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool case OperatorNode::OP_ASSIGN_BIT_XOR: priority = 15; break; default: { - _set_error("GDParser bug, invalid operator in expression: " + itos(expression[i].op)); + _set_error("GDScriptParser bug, invalid operator in expression: " + itos(expression[i].op)); return NULL; } } @@ -1358,7 +1359,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool return expression[0].node; } -GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) { +GDScriptParser::Node *GDScriptParser::_reduce_expression(Node *p_node, bool p_to_const) { switch (p_node->type) { @@ -1455,7 +1456,7 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) { } else if (op->op == OperatorNode::OP_CALL) { //can reduce base type constructors - if ((op->arguments[0]->type == Node::TYPE_TYPE || (op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && GDFunctions::is_deterministic(static_cast<BuiltInFunctionNode *>(op->arguments[0])->function))) && last_not_constant == 0) { + if ((op->arguments[0]->type == Node::TYPE_TYPE || (op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && GDScriptFunctions::is_deterministic(static_cast<BuiltInFunctionNode *>(op->arguments[0])->function))) && last_not_constant == 0) { //native type constructor or intrinsic function const Variant **vptr = NULL; @@ -1480,8 +1481,8 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) { v = Variant::construct(tn->vtype, vptr, ptrs.size(), ce); } else { - GDFunctions::Function func = static_cast<BuiltInFunctionNode *>(op->arguments[0])->function; - GDFunctions::call(func, vptr, ptrs.size(), v, ce); + GDScriptFunctions::Function func = static_cast<BuiltInFunctionNode *>(op->arguments[0])->function; + GDScriptFunctions::call(func, vptr, ptrs.size(), v, ce); } if (ce.error != Variant::CallError::CALL_OK) { @@ -1492,8 +1493,8 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) { errwhere = "'" + Variant::get_type_name(tn->vtype) + "'' constructor"; } else { - GDFunctions::Function func = static_cast<BuiltInFunctionNode *>(op->arguments[0])->function; - errwhere = String("'") + GDFunctions::get_func_name(func) + "'' intrinsic function"; + GDScriptFunctions::Function func = static_cast<BuiltInFunctionNode *>(op->arguments[0])->function; + errwhere = String("'") + GDScriptFunctions::get_func_name(func) + "'' intrinsic function"; } switch (ce.error) { @@ -1743,7 +1744,7 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) { } } -GDParser::Node *GDParser::_parse_and_reduce_expression(Node *p_parent, bool p_static, bool p_reduce_const, bool p_allow_assign) { +GDScriptParser::Node *GDScriptParser::_parse_and_reduce_expression(Node *p_parent, bool p_static, bool p_reduce_const, bool p_allow_assign) { Node *expr = _parse_expression(p_parent, p_static, p_allow_assign, p_reduce_const); if (!expr || error_set) @@ -1754,58 +1755,58 @@ GDParser::Node *GDParser::_parse_and_reduce_expression(Node *p_parent, bool p_st return expr; } -bool GDParser::_recover_from_completion() { +bool GDScriptParser::_recover_from_completion() { if (!completion_found) { return false; //can't recover if no completion } //skip stuff until newline - while (tokenizer->get_token() != GDTokenizer::TK_NEWLINE && tokenizer->get_token() != GDTokenizer::TK_EOF && tokenizer->get_token() != GDTokenizer::TK_ERROR) { + while (tokenizer->get_token() != GDScriptTokenizer::TK_NEWLINE && tokenizer->get_token() != GDScriptTokenizer::TK_EOF && tokenizer->get_token() != GDScriptTokenizer::TK_ERROR) { tokenizer->advance(); } completion_found = false; error_set = false; - if (tokenizer->get_token() == GDTokenizer::TK_ERROR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_ERROR) { error_set = true; } return true; } -GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { +GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) { PatternNode *pattern = alloc_node<PatternNode>(); - GDTokenizer::Token token = tokenizer->get_token(); + GDScriptTokenizer::Token token = tokenizer->get_token(); if (error_set) return NULL; - if (token == GDTokenizer::TK_EOF) { + if (token == GDScriptTokenizer::TK_EOF) { return NULL; } switch (token) { // array - case GDTokenizer::TK_BRACKET_OPEN: { + case GDScriptTokenizer::TK_BRACKET_OPEN: { tokenizer->advance(); - pattern->pt_type = GDParser::PatternNode::PT_ARRAY; + pattern->pt_type = GDScriptParser::PatternNode::PT_ARRAY; while (true) { - if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_BRACKET_CLOSE) { tokenizer->advance(); break; } - if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDScriptTokenizer::TK_PERIOD) { // match everything tokenizer->advance(2); PatternNode *sub_pattern = alloc_node<PatternNode>(); - sub_pattern->pt_type = GDParser::PatternNode::PT_IGNORE_REST; + sub_pattern->pt_type = GDScriptParser::PatternNode::PT_IGNORE_REST; pattern->array.push_back(sub_pattern); - if (tokenizer->get_token() == GDTokenizer::TK_COMMA && tokenizer->get_token(1) == GDTokenizer::TK_BRACKET_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA && tokenizer->get_token(1) == GDScriptTokenizer::TK_BRACKET_CLOSE) { tokenizer->advance(2); break; - } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BRACKET_CLOSE) { tokenizer->advance(1); break; } else { @@ -1821,10 +1822,10 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { pattern->array.push_back(sub_pattern); - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); continue; - } else if (tokenizer->get_token() == GDTokenizer::TK_BRACKET_CLOSE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_BRACKET_CLOSE) { tokenizer->advance(); break; } else { @@ -1834,33 +1835,33 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { } } break; // bind - case GDTokenizer::TK_PR_VAR: { + case GDScriptTokenizer::TK_PR_VAR: { tokenizer->advance(); - pattern->pt_type = GDParser::PatternNode::PT_BIND; + pattern->pt_type = GDScriptParser::PatternNode::PT_BIND; pattern->bind = tokenizer->get_token_identifier(); tokenizer->advance(); } break; // dictionary - case GDTokenizer::TK_CURLY_BRACKET_OPEN: { + case GDScriptTokenizer::TK_CURLY_BRACKET_OPEN: { tokenizer->advance(); - pattern->pt_type = GDParser::PatternNode::PT_DICTIONARY; + pattern->pt_type = GDScriptParser::PatternNode::PT_DICTIONARY; while (true) { - if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { tokenizer->advance(); break; } - if (tokenizer->get_token() == GDTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDTokenizer::TK_PERIOD) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD && tokenizer->get_token(1) == GDScriptTokenizer::TK_PERIOD) { // match everything tokenizer->advance(2); PatternNode *sub_pattern = alloc_node<PatternNode>(); sub_pattern->pt_type = PatternNode::PT_IGNORE_REST; pattern->array.push_back(sub_pattern); - if (tokenizer->get_token() == GDTokenizer::TK_COMMA && tokenizer->get_token(1) == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA && tokenizer->get_token(1) == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { tokenizer->advance(2); break; - } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { tokenizer->advance(1); break; } else { @@ -1875,12 +1876,12 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { return NULL; } - if (key->type != GDParser::Node::TYPE_CONSTANT) { + if (key->type != GDScriptParser::Node::TYPE_CONSTANT) { _set_error("Not a constant expression as key"); return NULL; } - if (tokenizer->get_token() == GDTokenizer::TK_COLON) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COLON) { tokenizer->advance(); PatternNode *value = _parse_pattern(p_static); @@ -1894,10 +1895,10 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { pattern->dictionary.insert(static_cast<ConstantNode *>(key), NULL); } - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); continue; - } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { tokenizer->advance(); break; } else { @@ -1906,7 +1907,7 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { } } } break; - case GDTokenizer::TK_WILDCARD: { + case GDScriptTokenizer::TK_WILDCARD: { tokenizer->advance(); pattern->pt_type = PatternNode::PT_WILDCARD; } break; @@ -1950,15 +1951,15 @@ GDParser::PatternNode *GDParser::_parse_pattern(bool p_static) { return pattern; } -void GDParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode *> &p_branches, bool p_static) { +void GDScriptParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode *> &p_branches, bool p_static) { int indent_level = tab_level.back()->get(); while (true) { - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE && _parse_newline()) + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) ; - // GDTokenizer::Token token = tokenizer->get_token(); + // GDScriptTokenizer::Token token = tokenizer->get_token(); if (error_set) return; @@ -1977,7 +1978,7 @@ void GDParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode return; } - while (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + while (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); branch->patterns.push_back(_parse_pattern(p_static)); if (!branch->patterns[branch->patterns.size() - 1]) { @@ -2003,13 +2004,13 @@ void GDParser::_parse_pattern_block(BlockNode *p_block, Vector<PatternBranchNode } } -void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node *> &p_bindings) { +void GDScriptParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, Node *&p_resulting_node, Map<StringName, Node *> &p_bindings) { switch (p_pattern->pt_type) { case PatternNode::PT_CONSTANT: { // typecheck BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); - typeof_node->function = GDFunctions::TYPE_OF; + typeof_node->function = GDScriptFunctions::TYPE_OF; OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); typeof_match_value->op = OperatorNode::OP_CALL; @@ -2064,7 +2065,7 @@ void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, { // typecheck BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); - typeof_node->function = GDFunctions::TYPE_OF; + typeof_node->function = GDScriptFunctions::TYPE_OF; OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); typeof_match_value->op = OperatorNode::OP_CALL; @@ -2143,7 +2144,7 @@ void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, { // typecheck BuiltInFunctionNode *typeof_node = alloc_node<BuiltInFunctionNode>(); - typeof_node->function = GDFunctions::TYPE_OF; + typeof_node->function = GDScriptFunctions::TYPE_OF; OperatorNode *typeof_match_value = alloc_node<OperatorNode>(); typeof_match_value->op = OperatorNode::OP_CALL; @@ -2241,7 +2242,7 @@ void GDParser::_generate_pattern(PatternNode *p_pattern, Node *p_node_to_match, } } -void GDParser::_transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement) { +void GDScriptParser::_transform_match_statment(BlockNode *p_block, MatchNode *p_match_statement) { IdentifierNode *id = alloc_node<IdentifierNode>(); id->name = "#match_value"; @@ -2305,7 +2306,7 @@ void GDParser::_transform_match_statment(BlockNode *p_block, MatchNode *p_match_ } } -void GDParser::_parse_block(BlockNode *p_block, bool p_static) { +void GDScriptParser::_parse_block(BlockNode *p_block, bool p_static) { int indent_level = tab_level.back()->get(); @@ -2328,7 +2329,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { } is_first_line = false; - GDTokenizer::Token token = tokenizer->get_token(); + GDScriptTokenizer::Token token = tokenizer->get_token(); if (error_set) return; @@ -2347,15 +2348,15 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { switch (token) { - case GDTokenizer::TK_EOF: + case GDScriptTokenizer::TK_EOF: p_block->end_line = tokenizer->get_token_line(); - case GDTokenizer::TK_ERROR: { + case GDScriptTokenizer::TK_ERROR: { return; //go back //end of file! } break; - case GDTokenizer::TK_NEWLINE: { + case GDScriptTokenizer::TK_NEWLINE: { if (!_parse_newline()) { if (!error_set) { @@ -2370,19 +2371,19 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { p_block->statements.push_back(nl); } break; - case GDTokenizer::TK_CF_PASS: { - if (tokenizer->get_token(1) != GDTokenizer::TK_SEMICOLON && tokenizer->get_token(1) != GDTokenizer::TK_NEWLINE && tokenizer->get_token(1) != GDTokenizer::TK_EOF) { + case GDScriptTokenizer::TK_CF_PASS: { + if (tokenizer->get_token(1) != GDScriptTokenizer::TK_SEMICOLON && tokenizer->get_token(1) != GDScriptTokenizer::TK_NEWLINE && tokenizer->get_token(1) != GDScriptTokenizer::TK_EOF) { _set_error("Expected ';' or <NewLine>."); return; } tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_SEMICOLON) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_SEMICOLON) { // Ignore semicolon after 'pass' tokenizer->advance(); } } break; - case GDTokenizer::TK_PR_VAR: { + case GDScriptTokenizer::TK_PR_VAR: { //variale declaration and (eventual) initialization tokenizer->advance(); @@ -2421,7 +2422,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { Node *assigned = NULL; - if (tokenizer->get_token() == GDTokenizer::TK_OP_ASSIGN) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { tokenizer->advance(); Node *subexpr = _parse_and_reduce_expression(p_block, p_static); @@ -2459,7 +2460,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { } } break; - case GDTokenizer::TK_CF_IF: { + case GDScriptTokenizer::TK_CF_IF: { tokenizer->advance(); @@ -2498,7 +2499,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { while (true) { - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE && _parse_newline()) + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE && _parse_newline()) ; if (tab_level.back()->get() < indent_level) { //not at current indent level @@ -2506,7 +2507,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { return; } - if (tokenizer->get_token() == GDTokenizer::TK_CF_ELIF) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CF_ELIF) { if (tab_level.back()->get() > indent_level) { @@ -2552,7 +2553,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { if (error_set) return; - } else if (tokenizer->get_token() == GDTokenizer::TK_CF_ELSE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CF_ELSE) { if (tab_level.back()->get() > indent_level) { _set_error("Invalid indent"); @@ -2582,7 +2583,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { } } break; - case GDTokenizer::TK_CF_WHILE: { + case GDScriptTokenizer::TK_CF_WHILE: { tokenizer->advance(); Node *condition = _parse_and_reduce_expression(p_block, p_static); @@ -2615,7 +2616,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { return; p_block->statements.push_back(cf_while); } break; - case GDTokenizer::TK_CF_FOR: { + case GDScriptTokenizer::TK_CF_FOR: { tokenizer->advance(); @@ -2629,7 +2630,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_OP_IN) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_OP_IN) { _set_error("'in' expected after identifier"); return; } @@ -2647,7 +2648,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { if (container->type == Node::TYPE_OPERATOR) { OperatorNode *op = static_cast<OperatorNode *>(container); - if (op->op == OperatorNode::OP_CALL && op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && static_cast<BuiltInFunctionNode *>(op->arguments[0])->function == GDFunctions::GEN_RANGE) { + if (op->op == OperatorNode::OP_CALL && op->arguments[0]->type == Node::TYPE_BUILT_IN_FUNCTION && static_cast<BuiltInFunctionNode *>(op->arguments[0])->function == GDScriptFunctions::GEN_RANGE) { //iterating a range, so see if range() can be optimized without allocating memory, by replacing it by vectors (which can work as iterable too!) Vector<Node *> args; @@ -2733,7 +2734,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { return; p_block->statements.push_back(cf_for); } break; - case GDTokenizer::TK_CF_CONTINUE: { + case GDScriptTokenizer::TK_CF_CONTINUE: { tokenizer->advance(); ControlFlowNode *cf_continue = alloc_node<ControlFlowNode>(); @@ -2744,7 +2745,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { return; } } break; - case GDTokenizer::TK_CF_BREAK: { + case GDScriptTokenizer::TK_CF_BREAK: { tokenizer->advance(); ControlFlowNode *cf_break = alloc_node<ControlFlowNode>(); @@ -2755,13 +2756,13 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { return; } } break; - case GDTokenizer::TK_CF_RETURN: { + case GDScriptTokenizer::TK_CF_RETURN: { tokenizer->advance(); ControlFlowNode *cf_return = alloc_node<ControlFlowNode>(); cf_return->cf_type = ControlFlowNode::CF_RETURN; - if (tokenizer->get_token() == GDTokenizer::TK_SEMICOLON || tokenizer->get_token() == GDTokenizer::TK_NEWLINE || tokenizer->get_token() == GDTokenizer::TK_EOF) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_SEMICOLON || tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE || tokenizer->get_token() == GDScriptTokenizer::TK_EOF) { //expect end of statement p_block->statements.push_back(cf_return); if (!_end_statement()) { @@ -2785,7 +2786,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { } } break; - case GDTokenizer::TK_CF_MATCH: { + case GDScriptTokenizer::TK_CF_MATCH: { tokenizer->advance(); @@ -2825,7 +2826,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { _end_statement(); } break; - case GDTokenizer::TK_PR_ASSERT: { + case GDScriptTokenizer::TK_PR_ASSERT: { tokenizer->advance(); Node *condition = _parse_and_reduce_expression(p_block, p_static); @@ -2844,7 +2845,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { return; } } break; - case GDTokenizer::TK_PR_BREAKPOINT: { + case GDScriptTokenizer::TK_PR_BREAKPOINT: { tokenizer->advance(); BreakpointNode *bn = alloc_node<BreakpointNode>(); @@ -2872,9 +2873,9 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { } break; /* - case GDTokenizer::TK_CF_LOCAL: { + case GDScriptTokenizer::TK_CF_LOCAL: { - if (tokenizer->get_token(1)!=GDTokenizer::TK_SEMICOLON && tokenizer->get_token(1)!=GDTokenizer::TK_NEWLINE ) { + if (tokenizer->get_token(1)!=GDScriptTokenizer::TK_SEMICOLON && tokenizer->get_token(1)!=GDScriptTokenizer::TK_NEWLINE ) { _set_error("Expected ';' or <NewLine>."); } @@ -2885,9 +2886,9 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) { } } -bool GDParser::_parse_newline() { +bool GDScriptParser::_parse_newline() { - if (tokenizer->get_token(1) != GDTokenizer::TK_EOF && tokenizer->get_token(1) != GDTokenizer::TK_NEWLINE) { + if (tokenizer->get_token(1) != GDScriptTokenizer::TK_EOF && tokenizer->get_token(1) != GDScriptTokenizer::TK_NEWLINE) { int indent = tokenizer->get_token_line_indent(); int current_indent = tab_level.back()->get(); @@ -2926,7 +2927,7 @@ bool GDParser::_parse_newline() { return true; } -void GDParser::_parse_extends(ClassNode *p_class) { +void GDScriptParser::_parse_extends(ClassNode *p_class) { if (p_class->extends_used) { @@ -2944,14 +2945,14 @@ void GDParser::_parse_extends(ClassNode *p_class) { tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token_type() == Variant::OBJECT) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE && tokenizer->get_token_type() == Variant::OBJECT) { p_class->extends_class.push_back(Variant::get_type_name(Variant::OBJECT)); tokenizer->advance(); return; } // see if inheritance happens from a file - if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT) { Variant constant = tokenizer->get_token_constant(); if (constant.get_type() != Variant::STRING) { @@ -2963,35 +2964,54 @@ void GDParser::_parse_extends(ClassNode *p_class) { p_class->extends_file = constant; tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PERIOD) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PERIOD) { return; } else tokenizer->advance(); } while (true) { - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { - _set_error("Invalid 'extends' syntax, expected string constant (path) and/or identifier (parent class)."); - return; - } + switch (tokenizer->get_token()) { - StringName identifier = tokenizer->get_token_identifier(); - p_class->extends_class.push_back(identifier); + case GDScriptTokenizer::TK_IDENTIFIER: { + + StringName identifier = tokenizer->get_token_identifier(); + p_class->extends_class.push_back(identifier); + } + break; + + 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() != GDTokenizer::TK_PERIOD) - return; + + switch (tokenizer->get_token()) { + + case GDScriptTokenizer::TK_IDENTIFIER: + case GDScriptTokenizer::TK_PERIOD: + continue; + + default: + return; + } } } -void GDParser::_parse_class(ClassNode *p_class) { +void GDScriptParser::_parse_class(ClassNode *p_class) { int indent_level = tab_level.back()->get(); while (true) { - GDTokenizer::Token token = tokenizer->get_token(); + GDScriptTokenizer::Token token = tokenizer->get_token(); if (error_set) return; @@ -3002,13 +3022,13 @@ void GDParser::_parse_class(ClassNode *p_class) { switch (token) { - case GDTokenizer::TK_EOF: + case GDScriptTokenizer::TK_EOF: p_class->end_line = tokenizer->get_token_line(); - case GDTokenizer::TK_ERROR: { + case GDScriptTokenizer::TK_ERROR: { return; //go back //end of file! } break; - case GDTokenizer::TK_NEWLINE: { + case GDScriptTokenizer::TK_NEWLINE: { if (!_parse_newline()) { if (!error_set) { p_class->end_line = tokenizer->get_token_line(); @@ -3016,7 +3036,7 @@ void GDParser::_parse_class(ClassNode *p_class) { return; } } break; - case GDTokenizer::TK_PR_EXTENDS: { + case GDScriptTokenizer::TK_PR_EXTENDS: { _parse_extends(p_class); if (error_set) @@ -3027,7 +3047,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } } break; - case GDTokenizer::TK_PR_TOOL: { + case GDScriptTokenizer::TK_PR_TOOL: { if (p_class->tool) { @@ -3039,13 +3059,13 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); } break; - case GDTokenizer::TK_PR_CLASS: { + case GDScriptTokenizer::TK_PR_CLASS: { //class inside class :D StringName name; StringName extends; - if (tokenizer->get_token(1) != GDTokenizer::TK_IDENTIFIER) { + if (tokenizer->get_token(1) != GDScriptTokenizer::TK_IDENTIFIER) { _set_error("'class' syntax: 'class <Name>:' or 'class <Name> extends <BaseClass>:'"); return; @@ -3063,7 +3083,7 @@ void GDParser::_parse_class(ClassNode *p_class) { p_class->subclasses.push_back(newclass); - if (tokenizer->get_token() == GDTokenizer::TK_PR_EXTENDS) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_EXTENDS) { _parse_extends(newclass); if (error_set) @@ -3081,26 +3101,26 @@ void GDParser::_parse_class(ClassNode *p_class) { } break; /* this is for functions.... - case GDTokenizer::TK_CF_PASS: { + case GDScriptTokenizer::TK_CF_PASS: { tokenizer->advance(1); } break; */ - case GDTokenizer::TK_PR_STATIC: { + case GDScriptTokenizer::TK_PR_STATIC: { tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { _set_error("Expected 'func'."); return; } }; //fallthrough to function - case GDTokenizer::TK_PR_FUNCTION: { + case GDScriptTokenizer::TK_PR_FUNCTION: { bool _static = false; pending_newline = -1; - if (tokenizer->get_token(-1) == GDTokenizer::TK_PR_STATIC) { + if (tokenizer->get_token(-1) == GDScriptTokenizer::TK_PR_STATIC) { _static = true; } @@ -3128,7 +3148,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } } - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_OPEN) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) { _set_error("Expected '(' after identifier (syntax: 'func <identifier>([arguments]):' )."); return; @@ -3141,17 +3161,17 @@ void GDParser::_parse_class(ClassNode *p_class) { int fnline = tokenizer->get_token_line(); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { //has arguments bool defaulting = false; while (true) { - if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); continue; } - if (tokenizer->get_token() == GDTokenizer::TK_PR_VAR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_VAR) { tokenizer->advance(); //var before the identifier is allowed } @@ -3167,7 +3187,7 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); - if (defaulting && tokenizer->get_token() != GDTokenizer::TK_OP_ASSIGN) { + if (defaulting && tokenizer->get_token() != GDScriptTokenizer::TK_OP_ASSIGN) { _set_error("Default parameter expected."); return; @@ -3175,7 +3195,7 @@ void GDParser::_parse_class(ClassNode *p_class) { //tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_OP_ASSIGN) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { defaulting = true; tokenizer->advance(1); Node *defval = _parse_and_reduce_expression(p_class, _static); @@ -3199,14 +3219,14 @@ void GDParser::_parse_class(ClassNode *p_class) { default_values.push_back(on); } - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); } - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); continue; - } else if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + } else if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ',' or ')'."); return; @@ -3233,14 +3253,14 @@ void GDParser::_parse_class(ClassNode *p_class) { id->name = "_init"; cparent->arguments.push_back(id); - if (tokenizer->get_token() == GDTokenizer::TK_PERIOD) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD) { tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_OPEN) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_OPEN) { _set_error("expected '(' for parent constructor arguments."); } tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { //has arguments parenthesis++; while (true) { @@ -3248,10 +3268,10 @@ void GDParser::_parse_class(ClassNode *p_class) { Node *arg = _parse_and_reduce_expression(p_class, _static); cparent->arguments.push_back(arg); - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); continue; - } else if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + } else if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ',' or ')'."); return; @@ -3266,7 +3286,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } } else { - if (tokenizer->get_token() == GDTokenizer::TK_PERIOD) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PERIOD) { _set_error("Parent constructor call found for a class without inheritance."); return; @@ -3303,7 +3323,7 @@ void GDParser::_parse_class(ClassNode *p_class) { //arguments } break; - case GDTokenizer::TK_PR_SIGNAL: { + case GDScriptTokenizer::TK_PR_SIGNAL: { tokenizer->advance(); if (!tokenizer->is_token_literal()) { @@ -3315,15 +3335,15 @@ void GDParser::_parse_class(ClassNode *p_class) { sig.name = tokenizer->get_token_identifier(); tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_OPEN) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { tokenizer->advance(); while (true) { - if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); continue; } - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { tokenizer->advance(); break; } @@ -3336,13 +3356,13 @@ void GDParser::_parse_class(ClassNode *p_class) { sig.arguments.push_back(tokenizer->get_token_identifier()); tokenizer->advance(); - while (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + while (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); } - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); - } else if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + } else if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ',' or ')' after signal parameter identifier."); return; } @@ -3356,14 +3376,14 @@ void GDParser::_parse_class(ClassNode *p_class) { return; } } break; - case GDTokenizer::TK_PR_EXPORT: { + case GDScriptTokenizer::TK_PR_EXPORT: { tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_OPEN) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE) { Variant::Type type = tokenizer->get_token_type(); if (type == Variant::NIL) { @@ -3376,17 +3396,17 @@ void GDParser::_parse_class(ClassNode *p_class) { String hint_prefix = ""; - if (type == Variant::ARRAY && tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (type == Variant::ARRAY && tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); - while (tokenizer->get_token() == GDTokenizer::TK_BUILT_IN_TYPE) { + while (tokenizer->get_token() == GDScriptTokenizer::TK_BUILT_IN_TYPE) { type = tokenizer->get_token_type(); tokenizer->advance(); if (type == Variant::ARRAY) { hint_prefix += itos(Variant::ARRAY) + ":"; - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); } } else { @@ -3396,7 +3416,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } } - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { // hint expected next! tokenizer->advance(); @@ -3404,15 +3424,15 @@ void GDParser::_parse_class(ClassNode *p_class) { case Variant::INT: { - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FLAGS") { + if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FLAGS") { //current_export.hint=PROPERTY_HINT_ALL_FLAGS; tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { break; } - if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { _set_error("Expected ')' or ',' in bit flags hint."); return; } @@ -3423,7 +3443,7 @@ void GDParser::_parse_class(ClassNode *p_class) { bool first = true; while (true) { - if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { current_export = PropertyInfo(); _set_error("Expected a string constant in named bit flags hint."); return; @@ -3438,10 +3458,10 @@ void GDParser::_parse_class(ClassNode *p_class) { current_export.hint_string += c.xml_escape(); tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) break; - if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); _set_error("Expected ')' or ',' in named bit flags hint."); return; @@ -3452,13 +3472,13 @@ void GDParser::_parse_class(ClassNode *p_class) { break; } - if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING) { //enumeration current_export.hint = PROPERTY_HINT_ENUM; bool first = true; while (true) { - if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { current_export = PropertyInfo(); _set_error("Expected a string constant in enumeration hint."); @@ -3474,10 +3494,10 @@ void GDParser::_parse_class(ClassNode *p_class) { current_export.hint_string += c.xml_escape(); tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) break; - if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); _set_error("Expected ')' or ',' in enumeration hint."); return; @@ -3492,10 +3512,10 @@ void GDParser::_parse_class(ClassNode *p_class) { }; //fallthrough to use the same case Variant::REAL: { - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EASE") { + if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EASE") { current_export.hint = PROPERTY_HINT_EXP_EASING; tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' in hint."); return; } @@ -3503,14 +3523,14 @@ void GDParser::_parse_class(ClassNode *p_class) { } // range - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EXP") { + if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "EXP") { current_export.hint = PROPERTY_HINT_EXP_RANGE; tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) break; - else if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + else if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { _set_error("Expected ')' or ',' in exponential range hint."); return; } @@ -3520,11 +3540,11 @@ void GDParser::_parse_class(ClassNode *p_class) { float sign = 1.0; - if (tokenizer->get_token() == GDTokenizer::TK_OP_SUB) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_SUB) { sign = -1; tokenizer->advance(); } - if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { current_export = PropertyInfo(); _set_error("Expected a range in numeric hint."); @@ -3534,12 +3554,12 @@ void GDParser::_parse_class(ClassNode *p_class) { current_export.hint_string = rtos(sign * double(tokenizer->get_token_constant())); tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { current_export.hint_string = "0," + current_export.hint_string; break; } - if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); _set_error("Expected ',' or ')' in numeric range hint."); @@ -3549,12 +3569,12 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); sign = 1.0; - if (tokenizer->get_token() == GDTokenizer::TK_OP_SUB) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_SUB) { sign = -1; tokenizer->advance(); } - if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { current_export = PropertyInfo(); _set_error("Expected a number as upper bound in numeric range hint."); @@ -3564,10 +3584,10 @@ void GDParser::_parse_class(ClassNode *p_class) { current_export.hint_string += "," + rtos(sign * double(tokenizer->get_token_constant())); tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) break; - if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); _set_error("Expected ',' or ')' in numeric range hint."); @@ -3576,12 +3596,12 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); sign = 1.0; - if (tokenizer->get_token() == GDTokenizer::TK_OP_SUB) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_SUB) { sign = -1; tokenizer->advance(); } - if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || !tokenizer->get_token_constant().is_num()) { current_export = PropertyInfo(); _set_error("Expected a number as step in numeric range hint."); @@ -3594,13 +3614,13 @@ void GDParser::_parse_class(ClassNode *p_class) { } break; case Variant::STRING: { - if (tokenizer->get_token() == GDTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_CONSTANT && tokenizer->get_token_constant().get_type() == Variant::STRING) { //enumeration current_export.hint = PROPERTY_HINT_ENUM; bool first = true; while (true) { - if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { current_export = PropertyInfo(); _set_error("Expected a string constant in enumeration hint."); @@ -3615,10 +3635,10 @@ void GDParser::_parse_class(ClassNode *p_class) { current_export.hint_string += c.xml_escape(); tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) break; - if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { current_export = PropertyInfo(); _set_error("Expected ')' or ',' in enumeration hint."); return; @@ -3629,17 +3649,17 @@ void GDParser::_parse_class(ClassNode *p_class) { break; } - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "DIR") { + if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "DIR") { tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) current_export.hint = PROPERTY_HINT_DIR; - else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier() == "GLOBAL")) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER || !(tokenizer->get_token_identifier() == "GLOBAL")) { _set_error("Expected 'GLOBAL' after comma in directory hint."); return; } @@ -3650,7 +3670,7 @@ void GDParser::_parse_class(ClassNode *p_class) { current_export.hint = PROPERTY_HINT_GLOBAL_DIR; tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' in hint."); return; } @@ -3661,16 +3681,16 @@ void GDParser::_parse_class(ClassNode *p_class) { break; } - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FILE") { + if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "FILE") { current_export.hint = PROPERTY_HINT_FILE; tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "GLOBAL") { + if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "GLOBAL") { if (!p_class->tool) { _set_error("Global filesystem hints may only be used in tool scripts."); @@ -3679,9 +3699,9 @@ void GDParser::_parse_class(ClassNode *p_class) { current_export.hint = PROPERTY_HINT_GLOBAL_FILE; tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_PARENTHESIS_CLOSE) + if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_CLOSE) break; - else if (tokenizer->get_token() == GDTokenizer::TK_COMMA) + else if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) tokenizer->advance(); else { _set_error("Expected ')' or ',' in hint."); @@ -3689,7 +3709,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } } - if (tokenizer->get_token() != GDTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_CONSTANT || tokenizer->get_token_constant().get_type() != Variant::STRING) { if (current_export.hint == PROPERTY_HINT_GLOBAL_FILE) _set_error("Expected string constant with filter"); @@ -3701,18 +3721,18 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); } - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' in hint."); return; } break; } - if (tokenizer->get_token() == GDTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "MULTILINE") { + if (tokenizer->get_token() == GDScriptTokenizer::TK_IDENTIFIER && tokenizer->get_token_identifier() == "MULTILINE") { current_export.hint = PROPERTY_HINT_MULTILINE_TEXT; tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { _set_error("Expected ')' in hint."); return; } @@ -3721,7 +3741,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } break; case Variant::COLOR: { - if (tokenizer->get_token() != GDTokenizer::TK_IDENTIFIER) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_IDENTIFIER) { current_export = PropertyInfo(); _set_error("Color type hint expects RGB or RGBA as hints"); @@ -3757,25 +3777,85 @@ void GDParser::_parse_class(ClassNode *p_class) { current_export.hint = PROPERTY_HINT_NONE; } - } else if (tokenizer->get_token() == GDTokenizer::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() != GDTokenizer::TK_PARENTHESIS_CLOSE) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PARENTHESIS_CLOSE) { current_export = PropertyInfo(); _set_error("Expected ')' or ',' after export hint."); @@ -3785,7 +3865,7 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); } - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_ONREADY && tokenizer->get_token() != GDTokenizer::TK_PR_REMOTE && tokenizer->get_token() != GDTokenizer::TK_PR_MASTER && tokenizer->get_token() != GDTokenizer::TK_PR_SLAVE && tokenizer->get_token() != GDTokenizer::TK_PR_SYNC) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_ONREADY && tokenizer->get_token() != GDScriptTokenizer::TK_PR_REMOTE && tokenizer->get_token() != GDScriptTokenizer::TK_PR_MASTER && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SLAVE && tokenizer->get_token() != GDScriptTokenizer::TK_PR_SYNC) { current_export = PropertyInfo(); _set_error("Expected 'var', 'onready', 'remote', 'master', 'slave' or 'sync'."); @@ -3794,29 +3874,29 @@ void GDParser::_parse_class(ClassNode *p_class) { continue; } break; - case GDTokenizer::TK_PR_ONREADY: { + case GDScriptTokenizer::TK_PR_ONREADY: { //may be fallthrough from export, ignore if so tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) { _set_error("Expected 'var'."); return; } continue; } break; - case GDTokenizer::TK_PR_REMOTE: { + case GDScriptTokenizer::TK_PR_REMOTE: { //may be fallthrough from export, ignore if so tokenizer->advance(); if (current_export.type) { - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) { _set_error("Expected 'var'."); return; } } else { - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { _set_error("Expected 'var' or 'func'."); return; } @@ -3825,18 +3905,18 @@ void GDParser::_parse_class(ClassNode *p_class) { continue; } break; - case GDTokenizer::TK_PR_MASTER: { + case GDScriptTokenizer::TK_PR_MASTER: { //may be fallthrough from export, ignore if so tokenizer->advance(); if (current_export.type) { - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) { _set_error("Expected 'var'."); return; } } else { - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { _set_error("Expected 'var' or 'func'."); return; } @@ -3845,18 +3925,18 @@ void GDParser::_parse_class(ClassNode *p_class) { rpc_mode = ScriptInstance::RPC_MODE_MASTER; continue; } break; - case GDTokenizer::TK_PR_SLAVE: { + case GDScriptTokenizer::TK_PR_SLAVE: { //may be fallthrough from export, ignore if so tokenizer->advance(); if (current_export.type) { - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR) { _set_error("Expected 'var'."); return; } } else { - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { _set_error("Expected 'var' or 'func'."); return; } @@ -3865,11 +3945,11 @@ void GDParser::_parse_class(ClassNode *p_class) { rpc_mode = ScriptInstance::RPC_MODE_SLAVE; continue; } break; - case GDTokenizer::TK_PR_SYNC: { + case GDScriptTokenizer::TK_PR_SYNC: { //may be fallthrough from export, ignore if so tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_PR_VAR && tokenizer->get_token() != GDTokenizer::TK_PR_FUNCTION) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_PR_VAR && tokenizer->get_token() != GDScriptTokenizer::TK_PR_FUNCTION) { if (current_export.type) _set_error("Expected 'var'."); else @@ -3880,17 +3960,17 @@ void GDParser::_parse_class(ClassNode *p_class) { rpc_mode = ScriptInstance::RPC_MODE_SYNC; continue; } break; - case GDTokenizer::TK_PR_VAR: { + case GDScriptTokenizer::TK_PR_VAR: { //variale declaration and (eventual) initialization ClassNode::Member member; - bool autoexport = tokenizer->get_token(-1) == GDTokenizer::TK_PR_EXPORT; + bool autoexport = tokenizer->get_token(-1) == GDScriptTokenizer::TK_PR_EXPORT; if (current_export.type != Variant::NIL) { member._export = current_export; current_export = PropertyInfo(); } - bool onready = tokenizer->get_token(-1) == GDTokenizer::TK_PR_ONREADY; + bool onready = tokenizer->get_token(-1) == GDScriptTokenizer::TK_PR_ONREADY; tokenizer->advance(); if (!tokenizer->is_token_literal(0, true)) { @@ -3909,7 +3989,7 @@ void GDParser::_parse_class(ClassNode *p_class) { rpc_mode = ScriptInstance::RPC_MODE_DISABLED; - if (tokenizer->get_token() == GDTokenizer::TK_OP_ASSIGN) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { #ifdef DEBUG_ENABLED int line = tokenizer->get_token_line(); @@ -4017,11 +4097,11 @@ void GDParser::_parse_class(ClassNode *p_class) { } } - if (tokenizer->get_token() == GDTokenizer::TK_PR_SETGET) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_SETGET) { tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_COMMA) { //just comma means using only getter if (!tokenizer->is_token_literal()) { _set_error("Expected identifier for setter function after 'setget'."); @@ -4032,7 +4112,7 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); } - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { //there is a getter tokenizer->advance(); @@ -4052,7 +4132,7 @@ void GDParser::_parse_class(ClassNode *p_class) { return; } } break; - case GDTokenizer::TK_PR_CONST: { + case GDScriptTokenizer::TK_PR_CONST: { //variale declaration and (eventual) initialization ClassNode::Constant constant; @@ -4067,7 +4147,7 @@ void GDParser::_parse_class(ClassNode *p_class) { constant.identifier = tokenizer->get_token_literal(); tokenizer->advance(); - if (tokenizer->get_token() != GDTokenizer::TK_OP_ASSIGN) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_OP_ASSIGN) { _set_error("Constant expects assignment."); return; } @@ -4095,7 +4175,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } } break; - case GDTokenizer::TK_PR_ENUM: { + case GDScriptTokenizer::TK_PR_ENUM: { //mutiple constant declarations.. int last_assign = -1; // Incremented by 1 right before the assingment. @@ -4107,26 +4187,26 @@ void GDParser::_parse_class(ClassNode *p_class) { enum_name = tokenizer->get_token_literal(); tokenizer->advance(); } - if (tokenizer->get_token() != GDTokenizer::TK_CURLY_BRACKET_OPEN) { + if (tokenizer->get_token() != GDScriptTokenizer::TK_CURLY_BRACKET_OPEN) { _set_error("Expected '{' in enum declaration"); return; } tokenizer->advance(); while (true) { - if (tokenizer->get_token() == GDTokenizer::TK_NEWLINE) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_NEWLINE) { tokenizer->advance(); // Ignore newlines - } else if (tokenizer->get_token() == GDTokenizer::TK_CURLY_BRACKET_CLOSE) { + } else if (tokenizer->get_token() == GDScriptTokenizer::TK_CURLY_BRACKET_CLOSE) { tokenizer->advance(); break; // End of enum } else if (!tokenizer->is_token_literal(0, true)) { - if (tokenizer->get_token() == GDTokenizer::TK_EOF) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_EOF) { _set_error("Unexpected end of file."); } else { - _set_error(String("Unexpected ") + GDTokenizer::get_token_name(tokenizer->get_token()) + ", expected identifier"); + _set_error(String("Unexpected ") + GDScriptTokenizer::get_token_name(tokenizer->get_token()) + ", expected identifier"); } return; @@ -4137,7 +4217,7 @@ void GDParser::_parse_class(ClassNode *p_class) { tokenizer->advance(); - if (tokenizer->get_token() == GDTokenizer::TK_OP_ASSIGN) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { tokenizer->advance(); Node *subexpr = _parse_and_reduce_expression(p_class, true, true); @@ -4169,7 +4249,7 @@ void GDParser::_parse_class(ClassNode *p_class) { constant.expression = cn; } - if (tokenizer->get_token() == GDTokenizer::TK_COMMA) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_COMMA) { tokenizer->advance(); } @@ -4198,7 +4278,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } break; - case GDTokenizer::TK_CONSTANT: { + case GDScriptTokenizer::TK_CONSTANT: { if (tokenizer->get_token_constant().get_type() == Variant::STRING) { tokenizer->advance(); // Ignore @@ -4218,7 +4298,7 @@ void GDParser::_parse_class(ClassNode *p_class) { } } -void GDParser::_set_error(const String &p_error, int p_line, int p_column) { +void GDScriptParser::_set_error(const String &p_error, int p_line, int p_column) { if (error_set) return; //allow no further errors @@ -4229,21 +4309,21 @@ void GDParser::_set_error(const String &p_error, int p_line, int p_column) { error_set = true; } -String GDParser::get_error() const { +String GDScriptParser::get_error() const { return error; } -int GDParser::get_error_line() const { +int GDScriptParser::get_error_line() const { return error_line; } -int GDParser::get_error_column() const { +int GDScriptParser::get_error_column() const { return error_column; } -Error GDParser::_parse(const String &p_base_path) { +Error GDScriptParser::_parse(const String &p_base_path) { base_path = p_base_path; @@ -4259,7 +4339,7 @@ Error GDParser::_parse(const String &p_base_path) { _parse_class(main_class); - if (tokenizer->get_token() == GDTokenizer::TK_ERROR) { + if (tokenizer->get_token() == GDScriptTokenizer::TK_ERROR) { error_set = false; _set_error("Parse Error: " + tokenizer->get_token_error()); } @@ -4271,7 +4351,7 @@ Error GDParser::_parse(const String &p_base_path) { return OK; } -Error GDParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const String &p_base_path, const String &p_self_path) { +Error GDScriptParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const String &p_base_path, const String &p_self_path) { for_completion = false; validating = false; @@ -4286,7 +4366,7 @@ Error GDParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const String & current_function = NULL; self_path = p_self_path; - GDTokenizerBuffer *tb = memnew(GDTokenizerBuffer); + GDScriptTokenizerBuffer *tb = memnew(GDScriptTokenizerBuffer); tb->set_code_buffer(p_bytecode); tokenizer = tb; Error ret = _parse(p_base_path); @@ -4295,7 +4375,7 @@ Error GDParser::parse_bytecode(const Vector<uint8_t> &p_bytecode, const String & return ret; } -Error GDParser::parse(const String &p_code, const String &p_base_path, bool p_just_validate, const String &p_self_path, bool p_for_completion) { +Error GDScriptParser::parse(const String &p_code, const String &p_base_path, bool p_just_validate, const String &p_self_path, bool p_for_completion) { completion_type = COMPLETION_NONE; completion_node = NULL; @@ -4309,7 +4389,7 @@ Error GDParser::parse(const String &p_code, const String &p_base_path, bool p_ju current_function = NULL; self_path = p_self_path; - GDTokenizerText *tt = memnew(GDTokenizerText); + GDScriptTokenizerText *tt = memnew(GDScriptTokenizerText); tt->set_code(p_code); validating = p_just_validate; @@ -4321,17 +4401,17 @@ Error GDParser::parse(const String &p_code, const String &p_base_path, bool p_ju return ret; } -bool GDParser::is_tool_script() const { +bool GDScriptParser::is_tool_script() const { return (head && head->type == Node::TYPE_CLASS && static_cast<const ClassNode *>(head)->tool); } -const GDParser::Node *GDParser::get_parse_tree() const { +const GDScriptParser::Node *GDScriptParser::get_parse_tree() const { return head; } -void GDParser::clear() { +void GDScriptParser::clear() { while (list) { @@ -4369,57 +4449,57 @@ void GDParser::clear() { error = ""; } -GDParser::CompletionType GDParser::get_completion_type() { +GDScriptParser::CompletionType GDScriptParser::get_completion_type() { return completion_type; } -StringName GDParser::get_completion_cursor() { +StringName GDScriptParser::get_completion_cursor() { return completion_cursor; } -int GDParser::get_completion_line() { +int GDScriptParser::get_completion_line() { return completion_line; } -Variant::Type GDParser::get_completion_built_in_constant() { +Variant::Type GDScriptParser::get_completion_built_in_constant() { return completion_built_in_constant; } -GDParser::Node *GDParser::get_completion_node() { +GDScriptParser::Node *GDScriptParser::get_completion_node() { return completion_node; } -GDParser::BlockNode *GDParser::get_completion_block() { +GDScriptParser::BlockNode *GDScriptParser::get_completion_block() { return completion_block; } -GDParser::ClassNode *GDParser::get_completion_class() { +GDScriptParser::ClassNode *GDScriptParser::get_completion_class() { return completion_class; } -GDParser::FunctionNode *GDParser::get_completion_function() { +GDScriptParser::FunctionNode *GDScriptParser::get_completion_function() { return completion_function; } -int GDParser::get_completion_argument_index() { +int GDScriptParser::get_completion_argument_index() { return completion_argument; } -int GDParser::get_completion_identifier_is_function() { +int GDScriptParser::get_completion_identifier_is_function() { return completion_ident_is_call; } -GDParser::GDParser() { +GDScriptParser::GDScriptParser() { head = NULL; list = NULL; @@ -4428,7 +4508,7 @@ GDParser::GDParser() { clear(); } -GDParser::~GDParser() { +GDScriptParser::~GDScriptParser() { clear(); } diff --git a/modules/gdscript/gd_parser.h b/modules/gdscript/gdscript_parser.h index 7e88fd9746..3c9c5ea02c 100644 --- a/modules/gdscript/gd_parser.h +++ b/modules/gdscript/gdscript_parser.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_parser.h */ +/* gdscript_parser.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,16 +27,16 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GD_PARSER_H -#define GD_PARSER_H +#ifndef GDSCRIPT_PARSER_H +#define GDSCRIPT_PARSER_H -#include "gd_functions.h" -#include "gd_tokenizer.h" +#include "gdscript_functions.h" +#include "gdscript_tokenizer.h" #include "map.h" #include "object.h" #include "script_language.h" -class GDParser { +class GDScriptParser { public: struct Node { @@ -166,7 +166,7 @@ public: TypeNode() { type = TYPE_TYPE; } }; struct BuiltInFunctionNode : public Node { - GDFunctions::Function function; + GDScriptFunctions::Function function; BuiltInFunctionNode() { type = TYPE_BUILT_IN_FUNCTION; } }; @@ -448,7 +448,7 @@ public: }; private: - GDTokenizer *tokenizer; + GDScriptTokenizer *tokenizer; Node *head; Node *list; @@ -540,8 +540,8 @@ public: int get_completion_identifier_is_function(); void clear(); - GDParser(); - ~GDParser(); + GDScriptParser(); + ~GDScriptParser(); }; -#endif // PARSER_H +#endif // GDSCRIPT_PARSER_H diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gdscript_tokenizer.cpp index 98ac0f473d..e3a0af8ee6 100644 --- a/modules/gdscript/gd_tokenizer.cpp +++ b/modules/gdscript/gdscript_tokenizer.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_tokenizer.cpp */ +/* gdscript_tokenizer.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,14 +27,14 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_tokenizer.h" +#include "gdscript_tokenizer.h" -#include "gd_functions.h" +#include "gdscript_functions.h" #include "io/marshalls.h" #include "map.h" #include "print_string.h" -const char *GDTokenizer::token_names[TK_MAX] = { +const char *GDScriptTokenizer::token_names[TK_MAX] = { "Empty", "Identifier", "Constant", @@ -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" }, @@ -170,68 +170,68 @@ static const _bit _type_list[] = { }; struct _kws { - GDTokenizer::Token token; + GDScriptTokenizer::Token token; const char *text; }; static const _kws _keyword_list[] = { //ops - { GDTokenizer::TK_OP_IN, "in" }, - { GDTokenizer::TK_OP_NOT, "not" }, - { GDTokenizer::TK_OP_OR, "or" }, - { GDTokenizer::TK_OP_AND, "and" }, + { GDScriptTokenizer::TK_OP_IN, "in" }, + { GDScriptTokenizer::TK_OP_NOT, "not" }, + { GDScriptTokenizer::TK_OP_OR, "or" }, + { GDScriptTokenizer::TK_OP_AND, "and" }, //func - { GDTokenizer::TK_PR_FUNCTION, "func" }, - { GDTokenizer::TK_PR_CLASS, "class" }, - { GDTokenizer::TK_PR_EXTENDS, "extends" }, - { GDTokenizer::TK_PR_IS, "is" }, - { GDTokenizer::TK_PR_ONREADY, "onready" }, - { GDTokenizer::TK_PR_TOOL, "tool" }, - { GDTokenizer::TK_PR_STATIC, "static" }, - { GDTokenizer::TK_PR_EXPORT, "export" }, - { GDTokenizer::TK_PR_SETGET, "setget" }, - { GDTokenizer::TK_PR_VAR, "var" }, - { GDTokenizer::TK_PR_PRELOAD, "preload" }, - { GDTokenizer::TK_PR_ASSERT, "assert" }, - { GDTokenizer::TK_PR_YIELD, "yield" }, - { GDTokenizer::TK_PR_SIGNAL, "signal" }, - { GDTokenizer::TK_PR_BREAKPOINT, "breakpoint" }, - { GDTokenizer::TK_PR_REMOTE, "remote" }, - { GDTokenizer::TK_PR_MASTER, "master" }, - { GDTokenizer::TK_PR_SLAVE, "slave" }, - { GDTokenizer::TK_PR_SYNC, "sync" }, - { GDTokenizer::TK_PR_CONST, "const" }, - { GDTokenizer::TK_PR_ENUM, "enum" }, + { GDScriptTokenizer::TK_PR_FUNCTION, "func" }, + { GDScriptTokenizer::TK_PR_CLASS, "class" }, + { GDScriptTokenizer::TK_PR_EXTENDS, "extends" }, + { GDScriptTokenizer::TK_PR_IS, "is" }, + { GDScriptTokenizer::TK_PR_ONREADY, "onready" }, + { GDScriptTokenizer::TK_PR_TOOL, "tool" }, + { GDScriptTokenizer::TK_PR_STATIC, "static" }, + { GDScriptTokenizer::TK_PR_EXPORT, "export" }, + { GDScriptTokenizer::TK_PR_SETGET, "setget" }, + { GDScriptTokenizer::TK_PR_VAR, "var" }, + { GDScriptTokenizer::TK_PR_PRELOAD, "preload" }, + { GDScriptTokenizer::TK_PR_ASSERT, "assert" }, + { GDScriptTokenizer::TK_PR_YIELD, "yield" }, + { GDScriptTokenizer::TK_PR_SIGNAL, "signal" }, + { GDScriptTokenizer::TK_PR_BREAKPOINT, "breakpoint" }, + { GDScriptTokenizer::TK_PR_REMOTE, "remote" }, + { GDScriptTokenizer::TK_PR_MASTER, "master" }, + { GDScriptTokenizer::TK_PR_SLAVE, "slave" }, + { GDScriptTokenizer::TK_PR_SYNC, "sync" }, + { GDScriptTokenizer::TK_PR_CONST, "const" }, + { GDScriptTokenizer::TK_PR_ENUM, "enum" }, //controlflow - { GDTokenizer::TK_CF_IF, "if" }, - { GDTokenizer::TK_CF_ELIF, "elif" }, - { GDTokenizer::TK_CF_ELSE, "else" }, - { GDTokenizer::TK_CF_FOR, "for" }, - { GDTokenizer::TK_CF_WHILE, "while" }, - { GDTokenizer::TK_CF_DO, "do" }, - { GDTokenizer::TK_CF_SWITCH, "switch" }, - { GDTokenizer::TK_CF_CASE, "case" }, - { GDTokenizer::TK_CF_BREAK, "break" }, - { GDTokenizer::TK_CF_CONTINUE, "continue" }, - { GDTokenizer::TK_CF_RETURN, "return" }, - { GDTokenizer::TK_CF_MATCH, "match" }, - { GDTokenizer::TK_CF_PASS, "pass" }, - { GDTokenizer::TK_SELF, "self" }, - { GDTokenizer::TK_CONST_PI, "PI" }, - { GDTokenizer::TK_CONST_TAU, "TAU" }, - { GDTokenizer::TK_WILDCARD, "_" }, - { GDTokenizer::TK_CONST_INF, "INF" }, - { GDTokenizer::TK_CONST_NAN, "NAN" }, - { GDTokenizer::TK_ERROR, NULL } + { GDScriptTokenizer::TK_CF_IF, "if" }, + { GDScriptTokenizer::TK_CF_ELIF, "elif" }, + { GDScriptTokenizer::TK_CF_ELSE, "else" }, + { GDScriptTokenizer::TK_CF_FOR, "for" }, + { GDScriptTokenizer::TK_CF_WHILE, "while" }, + { GDScriptTokenizer::TK_CF_DO, "do" }, + { GDScriptTokenizer::TK_CF_SWITCH, "switch" }, + { GDScriptTokenizer::TK_CF_CASE, "case" }, + { GDScriptTokenizer::TK_CF_BREAK, "break" }, + { GDScriptTokenizer::TK_CF_CONTINUE, "continue" }, + { GDScriptTokenizer::TK_CF_RETURN, "return" }, + { GDScriptTokenizer::TK_CF_MATCH, "match" }, + { GDScriptTokenizer::TK_CF_PASS, "pass" }, + { GDScriptTokenizer::TK_SELF, "self" }, + { GDScriptTokenizer::TK_CONST_PI, "PI" }, + { GDScriptTokenizer::TK_CONST_TAU, "TAU" }, + { GDScriptTokenizer::TK_WILDCARD, "_" }, + { GDScriptTokenizer::TK_CONST_INF, "INF" }, + { GDScriptTokenizer::TK_CONST_NAN, "NAN" }, + { GDScriptTokenizer::TK_ERROR, NULL } }; -const char *GDTokenizer::get_token_name(Token p_token) { +const char *GDScriptTokenizer::get_token_name(Token p_token) { ERR_FAIL_INDEX_V(p_token, TK_MAX, "<error>"); return token_names[p_token]; } -bool GDTokenizer::is_token_literal(int p_offset, bool variable_safe) const { +bool GDScriptTokenizer::is_token_literal(int p_offset, bool variable_safe) const { switch (get_token(p_offset)) { // Can always be literal: case TK_IDENTIFIER: @@ -253,9 +253,9 @@ bool GDTokenizer::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: @@ -303,7 +303,7 @@ bool GDTokenizer::is_token_literal(int p_offset, bool variable_safe) const { } } -StringName GDTokenizer::get_token_literal(int p_offset) const { +StringName GDScriptTokenizer::get_token_literal(int p_offset) const { Token token = get_token(p_offset); switch (token) { case TK_IDENTIFIER: @@ -320,7 +320,7 @@ StringName GDTokenizer::get_token_literal(int p_offset) const { } } break; // Shouldn't get here, stuff happens case TK_BUILT_IN_FUNC: - return GDFunctions::get_func_name(get_token_built_in_func(p_offset)); + return GDScriptFunctions::get_func_name(get_token_built_in_func(p_offset)); case TK_CONSTANT: { const Variant value = get_token_constant(p_offset); @@ -365,7 +365,7 @@ static bool _is_hex(CharType c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } -void GDTokenizerText::_make_token(Token p_type) { +void GDScriptTokenizerText::_make_token(Token p_type) { TokenData &tk = tk_rb[tk_rb_pos]; @@ -375,7 +375,7 @@ void GDTokenizerText::_make_token(Token p_type) { tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } -void GDTokenizerText::_make_identifier(const StringName &p_identifier) { +void GDScriptTokenizerText::_make_identifier(const StringName &p_identifier) { TokenData &tk = tk_rb[tk_rb_pos]; @@ -387,7 +387,7 @@ void GDTokenizerText::_make_identifier(const StringName &p_identifier) { tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } -void GDTokenizerText::_make_built_in_func(GDFunctions::Function p_func) { +void GDScriptTokenizerText::_make_built_in_func(GDScriptFunctions::Function p_func) { TokenData &tk = tk_rb[tk_rb_pos]; @@ -398,7 +398,7 @@ void GDTokenizerText::_make_built_in_func(GDFunctions::Function p_func) { tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } -void GDTokenizerText::_make_constant(const Variant &p_constant) { +void GDScriptTokenizerText::_make_constant(const Variant &p_constant) { TokenData &tk = tk_rb[tk_rb_pos]; @@ -410,7 +410,7 @@ void GDTokenizerText::_make_constant(const Variant &p_constant) { tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } -void GDTokenizerText::_make_type(const Variant::Type &p_type) { +void GDScriptTokenizerText::_make_type(const Variant::Type &p_type) { TokenData &tk = tk_rb[tk_rb_pos]; @@ -422,7 +422,7 @@ void GDTokenizerText::_make_type(const Variant::Type &p_type) { tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } -void GDTokenizerText::_make_error(const String &p_error) { +void GDScriptTokenizerText::_make_error(const String &p_error) { error_flag = true; last_error = p_error; @@ -435,7 +435,7 @@ void GDTokenizerText::_make_error(const String &p_error) { tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } -void GDTokenizerText::_make_newline(int p_spaces) { +void GDScriptTokenizerText::_make_newline(int p_spaces) { TokenData &tk = tk_rb[tk_rb_pos]; tk.type = TK_NEWLINE; @@ -445,7 +445,7 @@ void GDTokenizerText::_make_newline(int p_spaces) { tk_rb_pos = (tk_rb_pos + 1) % TK_RB_SIZE; } -void GDTokenizerText::_advance() { +void GDScriptTokenizerText::_advance() { if (error_flag) { //parser broke @@ -885,6 +885,9 @@ void GDTokenizerText::_advance() { return; } sign_found = true; + } else if (GETCHAR(i) == '_') { + i++; + continue; // Included for readability, shouldn't be a part of the string } else break; @@ -897,7 +900,7 @@ void GDTokenizerText::_advance() { return; } - INCPOS(str.length()); + INCPOS(i); if (hexa_found) { int64_t val = str.hex_to_int64(); _make_constant(val); @@ -963,11 +966,11 @@ void GDTokenizerText::_advance() { //built in func? - for (int i = 0; i < GDFunctions::FUNC_MAX; i++) { + for (int i = 0; i < GDScriptFunctions::FUNC_MAX; i++) { - if (str == GDFunctions::get_func_name(GDFunctions::Function(i))) { + if (str == GDScriptFunctions::get_func_name(GDScriptFunctions::Function(i))) { - _make_built_in_func(GDFunctions::Function(i)); + _make_built_in_func(GDScriptFunctions::Function(i)); found = true; break; } @@ -1013,7 +1016,7 @@ void GDTokenizerText::_advance() { } } -void GDTokenizerText::set_code(const String &p_code) { +void GDScriptTokenizerText::set_code(const String &p_code) { code = p_code; len = p_code.length(); @@ -1032,7 +1035,7 @@ void GDTokenizerText::set_code(const String &p_code) { _advance(); } -GDTokenizerText::Token GDTokenizerText::get_token(int p_offset) const { +GDScriptTokenizerText::Token GDScriptTokenizerText::get_token(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, TK_ERROR); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, TK_ERROR); @@ -1040,7 +1043,7 @@ GDTokenizerText::Token GDTokenizerText::get_token(int p_offset) const { return tk_rb[ofs].type; } -int GDTokenizerText::get_token_line(int p_offset) const { +int GDScriptTokenizerText::get_token_line(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, -1); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, -1); @@ -1048,7 +1051,7 @@ int GDTokenizerText::get_token_line(int p_offset) const { return tk_rb[ofs].line; } -int GDTokenizerText::get_token_column(int p_offset) const { +int GDScriptTokenizerText::get_token_column(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, -1); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, -1); @@ -1056,7 +1059,7 @@ int GDTokenizerText::get_token_column(int p_offset) const { return tk_rb[ofs].col; } -const Variant &GDTokenizerText::get_token_constant(int p_offset) const { +const Variant &GDScriptTokenizerText::get_token_constant(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, tk_rb[0].constant); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, tk_rb[0].constant); @@ -1065,7 +1068,7 @@ const Variant &GDTokenizerText::get_token_constant(int p_offset) const { return tk_rb[ofs].constant; } -StringName GDTokenizerText::get_token_identifier(int p_offset) const { +StringName GDScriptTokenizerText::get_token_identifier(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, StringName()); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, StringName()); @@ -1075,17 +1078,17 @@ StringName GDTokenizerText::get_token_identifier(int p_offset) const { return tk_rb[ofs].identifier; } -GDFunctions::Function GDTokenizerText::get_token_built_in_func(int p_offset) const { +GDScriptFunctions::Function GDScriptTokenizerText::get_token_built_in_func(int p_offset) const { - ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, GDFunctions::FUNC_MAX); - ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, GDFunctions::FUNC_MAX); + ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, GDScriptFunctions::FUNC_MAX); + ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, GDScriptFunctions::FUNC_MAX); int ofs = (TK_RB_SIZE + tk_rb_pos + p_offset - MAX_LOOKAHEAD - 1) % TK_RB_SIZE; - ERR_FAIL_COND_V(tk_rb[ofs].type != TK_BUILT_IN_FUNC, GDFunctions::FUNC_MAX); + ERR_FAIL_COND_V(tk_rb[ofs].type != TK_BUILT_IN_FUNC, GDScriptFunctions::FUNC_MAX); return tk_rb[ofs].func; } -Variant::Type GDTokenizerText::get_token_type(int p_offset) const { +Variant::Type GDScriptTokenizerText::get_token_type(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, Variant::NIL); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, Variant::NIL); @@ -1095,7 +1098,7 @@ Variant::Type GDTokenizerText::get_token_type(int p_offset) const { return tk_rb[ofs].vtype; } -int GDTokenizerText::get_token_line_indent(int p_offset) const { +int GDScriptTokenizerText::get_token_line_indent(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, 0); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, 0); @@ -1105,7 +1108,7 @@ int GDTokenizerText::get_token_line_indent(int p_offset) const { return tk_rb[ofs].constant; } -String GDTokenizerText::get_token_error(int p_offset) const { +String GDScriptTokenizerText::get_token_error(int p_offset) const { ERR_FAIL_COND_V(p_offset <= -MAX_LOOKAHEAD, String()); ERR_FAIL_COND_V(p_offset >= MAX_LOOKAHEAD, String()); @@ -1115,18 +1118,18 @@ String GDTokenizerText::get_token_error(int p_offset) const { return tk_rb[ofs].constant; } -void GDTokenizerText::advance(int p_amount) { +void GDScriptTokenizerText::advance(int p_amount) { ERR_FAIL_COND(p_amount <= 0); for (int i = 0; i < p_amount; i++) _advance(); } -////////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////////// #define BYTECODE_VERSION 12 -Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) { +Error GDScriptTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) { const uint8_t *buf = p_buffer.ptr(); int total_len = p_buffer.size(); @@ -1214,7 +1217,7 @@ Error GDTokenizerBuffer::set_code_buffer(const Vector<uint8_t> &p_buffer) { return OK; } -Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String &p_code) { +Vector<uint8_t> GDScriptTokenizerBuffer::parse_code_string(const String &p_code) { Vector<uint8_t> buf; @@ -1223,7 +1226,7 @@ Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String &p_code) { Map<uint32_t, int> line_map; Vector<uint32_t> token_array; - GDTokenizerText tt; + GDScriptTokenizerText tt; tt.set_code(p_code); int line = -1; @@ -1372,17 +1375,17 @@ Vector<uint8_t> GDTokenizerBuffer::parse_code_string(const String &p_code) { return buf; } -GDTokenizerBuffer::Token GDTokenizerBuffer::get_token(int p_offset) const { +GDScriptTokenizerBuffer::Token GDScriptTokenizerBuffer::get_token(int p_offset) const { int offset = token + p_offset; if (offset < 0 || offset >= tokens.size()) return TK_EOF; - return GDTokenizerBuffer::Token(tokens[offset] & TOKEN_MASK); + return GDScriptTokenizerBuffer::Token(tokens[offset] & TOKEN_MASK); } -StringName GDTokenizerBuffer::get_token_identifier(int p_offset) const { +StringName GDScriptTokenizerBuffer::get_token_identifier(int p_offset) const { int offset = token + p_offset; @@ -1393,14 +1396,14 @@ StringName GDTokenizerBuffer::get_token_identifier(int p_offset) const { return identifiers[identifier]; } -GDFunctions::Function GDTokenizerBuffer::get_token_built_in_func(int p_offset) const { +GDScriptFunctions::Function GDScriptTokenizerBuffer::get_token_built_in_func(int p_offset) const { int offset = token + p_offset; - ERR_FAIL_INDEX_V(offset, tokens.size(), GDFunctions::FUNC_MAX); - return GDFunctions::Function(tokens[offset] >> TOKEN_BITS); + ERR_FAIL_INDEX_V(offset, tokens.size(), GDScriptFunctions::FUNC_MAX); + return GDScriptFunctions::Function(tokens[offset] >> TOKEN_BITS); } -Variant::Type GDTokenizerBuffer::get_token_type(int p_offset) const { +Variant::Type GDScriptTokenizerBuffer::get_token_type(int p_offset) const { int offset = token + p_offset; ERR_FAIL_INDEX_V(offset, tokens.size(), Variant::NIL); @@ -1408,7 +1411,7 @@ Variant::Type GDTokenizerBuffer::get_token_type(int p_offset) const { return Variant::Type(tokens[offset] >> TOKEN_BITS); } -int GDTokenizerBuffer::get_token_line(int p_offset) const { +int GDScriptTokenizerBuffer::get_token_line(int p_offset) const { int offset = token + p_offset; int pos = lines.find_nearest(offset); @@ -1421,7 +1424,7 @@ int GDTokenizerBuffer::get_token_line(int p_offset) const { uint32_t l = lines.getv(pos); return l & TOKEN_LINE_MASK; } -int GDTokenizerBuffer::get_token_column(int p_offset) const { +int GDScriptTokenizerBuffer::get_token_column(int p_offset) const { int offset = token + p_offset; int pos = lines.find_nearest(offset); @@ -1433,13 +1436,13 @@ int GDTokenizerBuffer::get_token_column(int p_offset) const { uint32_t l = lines.getv(pos); return l >> TOKEN_LINE_BITS; } -int GDTokenizerBuffer::get_token_line_indent(int p_offset) const { +int GDScriptTokenizerBuffer::get_token_line_indent(int p_offset) const { int offset = token + p_offset; ERR_FAIL_INDEX_V(offset, tokens.size(), 0); return tokens[offset] >> TOKEN_BITS; } -const Variant &GDTokenizerBuffer::get_token_constant(int p_offset) const { +const Variant &GDScriptTokenizerBuffer::get_token_constant(int p_offset) const { int offset = token + p_offset; ERR_FAIL_INDEX_V(offset, tokens.size(), nil); @@ -1447,17 +1450,17 @@ const Variant &GDTokenizerBuffer::get_token_constant(int p_offset) const { ERR_FAIL_INDEX_V(constant, (uint32_t)constants.size(), nil); return constants[constant]; } -String GDTokenizerBuffer::get_token_error(int p_offset) const { +String GDScriptTokenizerBuffer::get_token_error(int p_offset) const { ERR_FAIL_V(String()); } -void GDTokenizerBuffer::advance(int p_amount) { +void GDScriptTokenizerBuffer::advance(int p_amount) { ERR_FAIL_INDEX(p_amount + token, tokens.size()); token += p_amount; } -GDTokenizerBuffer::GDTokenizerBuffer() { +GDScriptTokenizerBuffer::GDScriptTokenizerBuffer() { token = 0; } diff --git a/modules/gdscript/gd_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h index f4b579def4..d19367177b 100644 --- a/modules/gdscript/gd_tokenizer.h +++ b/modules/gdscript/gdscript_tokenizer.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* gd_tokenizer.h */ +/* gdscript_tokenizer.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -27,16 +27,16 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GD_TOKENIZER_H -#define GD_TOKENIZER_H +#ifndef GDSCRIPT_TOKENIZER_H +#define GDSCRIPT_TOKENIZER_H -#include "gd_functions.h" +#include "gdscript_functions.h" #include "string_db.h" #include "ustring.h" #include "variant.h" #include "vmap.h" -class GDTokenizer { +class GDScriptTokenizer { public: enum Token { @@ -156,7 +156,7 @@ public: virtual const Variant &get_token_constant(int p_offset = 0) const = 0; virtual Token get_token(int p_offset = 0) const = 0; virtual StringName get_token_identifier(int p_offset = 0) const = 0; - virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const = 0; + virtual GDScriptFunctions::Function get_token_built_in_func(int p_offset = 0) const = 0; virtual Variant::Type get_token_type(int p_offset = 0) const = 0; virtual int get_token_line(int p_offset = 0) const = 0; virtual int get_token_column(int p_offset = 0) const = 0; @@ -164,10 +164,10 @@ public: virtual String get_token_error(int p_offset = 0) const = 0; virtual void advance(int p_amount = 1) = 0; - virtual ~GDTokenizer(){}; + virtual ~GDScriptTokenizer(){}; }; -class GDTokenizerText : public GDTokenizer { +class GDScriptTokenizerText : public GDScriptTokenizer { enum { MAX_LOOKAHEAD = 4, @@ -181,7 +181,7 @@ class GDTokenizerText : public GDTokenizer { Variant constant; //for constant types union { Variant::Type vtype; //for type types - GDFunctions::Function func; //function for built in functions + GDScriptFunctions::Function func; //function for built in functions }; int line, col; TokenData() { @@ -194,7 +194,7 @@ class GDTokenizerText : public GDTokenizer { void _make_token(Token p_type); void _make_newline(int p_spaces = 0); void _make_identifier(const StringName &p_identifier); - void _make_built_in_func(GDFunctions::Function p_func); + void _make_built_in_func(GDScriptFunctions::Function p_func); void _make_constant(const Variant &p_constant); void _make_type(const Variant::Type &p_type); void _make_error(const String &p_error); @@ -216,7 +216,7 @@ public: void set_code(const String &p_code); virtual Token get_token(int p_offset = 0) const; virtual StringName get_token_identifier(int p_offset = 0) const; - virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const; + virtual GDScriptFunctions::Function get_token_built_in_func(int p_offset = 0) const; virtual Variant::Type get_token_type(int p_offset = 0) const; virtual int get_token_line(int p_offset = 0) const; virtual int get_token_column(int p_offset = 0) const; @@ -226,7 +226,7 @@ public: virtual void advance(int p_amount = 1); }; -class GDTokenizerBuffer : public GDTokenizer { +class GDScriptTokenizerBuffer : public GDScriptTokenizer { enum { @@ -249,7 +249,7 @@ public: static Vector<uint8_t> parse_code_string(const String &p_code); virtual Token get_token(int p_offset = 0) const; virtual StringName get_token_identifier(int p_offset = 0) const; - virtual GDFunctions::Function get_token_built_in_func(int p_offset = 0) const; + virtual GDScriptFunctions::Function get_token_built_in_func(int p_offset = 0) const; virtual Variant::Type get_token_type(int p_offset = 0) const; virtual int get_token_line(int p_offset = 0) const; virtual int get_token_column(int p_offset = 0) const; @@ -257,7 +257,7 @@ public: virtual const Variant &get_token_constant(int p_offset = 0) const; virtual String get_token_error(int p_offset = 0) const; virtual void advance(int p_amount = 1); - GDTokenizerBuffer(); + GDScriptTokenizerBuffer(); }; -#endif // TOKENIZER_H +#endif // GDSCRIPT_TOKENIZER_H diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 036274c8f2..1e007ddb0f 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "register_types.h" -#include "gd_script.h" +#include "gdscript.h" #include "io/file_access_encrypted.h" #include "io/resource_loader.h" #include "os/file_access.h" @@ -41,10 +41,9 @@ ResourceFormatSaverGDScript *resource_saver_gd = NULL; void register_gdscript_types() { ClassDB::register_class<GDScript>(); - ClassDB::register_virtual_class<GDFunctionState>(); + ClassDB::register_virtual_class<GDScriptFunctionState>(); script_language_gd = memnew(GDScriptLanguage); - //script_language_gd->init(); ScriptServer::register_language(script_language_gd); resource_loader_gd = memnew(ResourceFormatLoaderGDScript); ResourceLoader::add_resource_format_loader(resource_loader_gd); diff --git a/modules/gridmap/config.py b/modules/gridmap/config.py index b3dbb9f46a..a93f4edb81 100644 --- a/modules/gridmap/config.py +++ b/modules/gridmap/config.py @@ -1,14 +1,13 @@ - - def can_build(platform): return True - def configure(env): pass def get_doc_classes(): - return ["GridMap"] + return [ + "GridMap", + ] def get_doc_path(): - return "doc_classes" + return "doc_classes" diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml index 5b0fe56f25..ee8ecfff66 100644 --- a/modules/gridmap/doc_classes/GridMap.xml +++ b/modules/gridmap/doc_classes/GridMap.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="GridMap" inherits="Spatial" category="Core" version="3.0.alpha.custom_build"> +<class name="GridMap" inherits="Spatial" category="Core" version="3.0-alpha"> <brief_description> Node for 3D tile-based maps. </brief_description> diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index cb14a5ee9c..b3a1947647 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -747,7 +747,6 @@ void GridMap::_update_octants_callback() { } while (to_delete.front()) { - memdelete(octant_map[to_delete.front()->get()]); octant_map.erase(to_delete.front()->get()); to_delete.pop_back(); } diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index f6a76ad2a1..3a5d0fd3fc 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -28,8 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "grid_map_editor_plugin.h" +#include "editor/editor_scale.h" #include "editor/editor_settings.h" #include "editor/plugins/spatial_editor_plugin.h" +#include "os/input.h" #include "scene/3d/camera.h" #include "geometry.h" @@ -56,6 +58,14 @@ void GridMapEditor::_menu_option(int p_option) { switch (p_option) { + case MENU_OPTION_PREV_LEVEL: { + floor->set_value(floor->get_value() - 1); + } break; + + case MENU_OPTION_NEXT_LEVEL: { + floor->set_value(floor->get_value() + 1); + } break; + case MENU_OPTION_CONFIGURE: { } break; @@ -94,6 +104,7 @@ void GridMapEditor::_menu_option(int p_option) { } break; case MENU_OPTION_CURSOR_ROTATE_Y: { + Basis r; if (input_action == INPUT_DUPLICATE) { @@ -109,6 +120,7 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_ROTATE_X: { + Basis r; if (input_action == INPUT_DUPLICATE) { @@ -125,6 +137,7 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_ROTATE_Z: { + Basis r; if (input_action == INPUT_DUPLICATE) { @@ -141,6 +154,7 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_Y: { + Basis r; r.set_orthogonal_index(cursor_rot); r.rotate(Vector3(0, 1, 0), Math_PI / 2.0); @@ -148,6 +162,7 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_X: { + Basis r; r.set_orthogonal_index(cursor_rot); r.rotate(Vector3(1, 0, 0), Math_PI / 2.0); @@ -155,6 +170,7 @@ void GridMapEditor::_menu_option(int p_option) { _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_Z: { + Basis r; r.set_orthogonal_index(cursor_rot); r.rotate(Vector3(0, 0, 1), Math_PI / 2.0); @@ -184,6 +200,9 @@ void GridMapEditor::_menu_option(int p_option) { if (last_mouseover == Vector3(-1, -1, -1)) //nono mouseovering anythin break; + last_mouseover = selection.begin; + VS::get_singleton()->instance_set_transform(grid_instance[edit_axis], Transform(Basis(), grid_ofs)); + input_action = INPUT_DUPLICATE; selection.click = last_mouseover; selection.current = last_mouseover; @@ -198,7 +217,7 @@ void GridMapEditor::_menu_option(int p_option) { } break; case MENU_OPTION_GRIDMAP_SETTINGS: { - settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50)); + settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50) * EDSCALE); } break; } } @@ -551,12 +570,11 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu input_action = INPUT_NONE; _update_duplicate_indicator(); - } else { + } else if (mb->get_shift()) { input_action = INPUT_ERASE; set_items.clear(); - } - else - return false; + } else + return false; return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); } else { @@ -605,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; } @@ -829,70 +857,77 @@ void GridMapEditor::update_grid() { void GridMapEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { + switch (p_what) { - theme_pallete->connect("item_selected", this, "_item_selected_cbk"); - for (int i = 0; i < 3; i++) { - - grid[i] = VS::get_singleton()->mesh_create(); - grid_instance[i] = VS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario()); - selection_level_instance[i] = VisualServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world()->get_scenario()); - } + case NOTIFICATION_ENTER_TREE: { + theme_pallete->connect("item_selected", this, "_item_selected_cbk"); + for (int i = 0; i < 3; i++) { - selection_instance = VisualServer::get_singleton()->instance_create2(selection_mesh, get_tree()->get_root()->get_world()->get_scenario()); - duplicate_instance = VisualServer::get_singleton()->instance_create2(duplicate_mesh, get_tree()->get_root()->get_world()->get_scenario()); + grid[i] = VS::get_singleton()->mesh_create(); + grid_instance[i] = VS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario()); + selection_level_instance[i] = VisualServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world()->get_scenario()); + } - _update_selection_transform(); - _update_duplicate_indicator(); + selection_instance = VisualServer::get_singleton()->instance_create2(selection_mesh, get_tree()->get_root()->get_world()->get_scenario()); + duplicate_instance = VisualServer::get_singleton()->instance_create2(duplicate_mesh, get_tree()->get_root()->get_world()->get_scenario()); - } else if (p_what == NOTIFICATION_EXIT_TREE) { + _update_selection_transform(); + _update_duplicate_indicator(); + } break; - for (int i = 0; i < 3; i++) { + case NOTIFICATION_EXIT_TREE: { + for (int i = 0; i < 3; i++) { - VS::get_singleton()->free(grid_instance[i]); - VS::get_singleton()->free(grid[i]); - grid_instance[i] = RID(); - grid[i] = RID(); - VisualServer::get_singleton()->free(selection_level_instance[i]); - } + VS::get_singleton()->free(grid_instance[i]); + VS::get_singleton()->free(grid[i]); + grid_instance[i] = RID(); + grid[i] = RID(); + VisualServer::get_singleton()->free(selection_level_instance[i]); + } - VisualServer::get_singleton()->free(selection_instance); - VisualServer::get_singleton()->free(duplicate_instance); - selection_instance = RID(); - duplicate_instance = RID(); + VisualServer::get_singleton()->free(selection_instance); + VisualServer::get_singleton()->free(duplicate_instance); + selection_instance = RID(); + duplicate_instance = RID(); + } break; - } else if (p_what == NOTIFICATION_PROCESS) { - if (!node) { - return; - } + case NOTIFICATION_PROCESS: { + if (!node) { + return; + } - Transform xf = node->get_global_transform(); + Transform xf = node->get_global_transform(); - if (xf != grid_xform) { - for (int i = 0; i < 3; i++) { + if (xf != grid_xform) { + for (int i = 0; i < 3; i++) { - VS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform); + VS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform); + } + grid_xform = xf; } - grid_xform = xf; - } - Ref<MeshLibrary> cgmt = node->get_theme(); - if (cgmt.operator->() != last_theme) - update_pallete(); + Ref<MeshLibrary> cgmt = node->get_theme(); + if (cgmt.operator->() != last_theme) + update_pallete(); - if (lock_view) { + if (lock_view) { - EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0)); + EditorNode *editor = Object::cast_to<EditorNode>(get_tree()->get_root()->get_child(0)); - Plane p; - p.normal[edit_axis] = 1.0; - p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis]; - p = node->get_transform().xform(p); // plane to snap + Plane p; + p.normal[edit_axis] = 1.0; + p.d = edit_floor[edit_axis] * node->get_cell_size()[edit_axis]; + p = node->get_transform().xform(p); // plane to snap - SpatialEditorPlugin *sep = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen()); - if (sep) - sep->snap_cursor_to_plane(p); - //editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p); - } + SpatialEditorPlugin *sep = Object::cast_to<SpatialEditorPlugin>(editor->get_editor_plugin_screen()); + if (sep) + sep->snap_cursor_to_plane(p); + //editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p); + } + } break; + + case NOTIFICATION_THEME_CHANGED: { + options->set_icon(get_icon("GridMap", "EditorIcons")); + } break; } } @@ -954,20 +989,38 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { int mw = EDITOR_DEF("editors/grid_map/palette_min_width", 230); Control *ec = memnew(Control); - ec->set_custom_minimum_size(Size2(mw, 0)); + ec->set_custom_minimum_size(Size2(mw, 0) * EDSCALE); add_child(ec); spatial_editor_hb = memnew(HBoxContainer); + spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL); + spatial_editor_hb->set_alignment(BoxContainer::ALIGN_END); SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb); + + Label *fl = memnew(Label); + fl->set_text(TTR("Floor:")); + spatial_editor_hb->add_child(fl); + + floor = memnew(SpinBox); + floor->set_min(-32767); + floor->set_max(32767); + floor->set_step(1); + floor->get_line_edit()->add_constant_override("minimum_spaces", 16); + + spatial_editor_hb->add_child(floor); + floor->connect("value_changed", this, "_floor_changed"); + + spatial_editor_hb->add_child(memnew(VSeparator)); + options = memnew(MenuButton); spatial_editor_hb->add_child(options); spatial_editor_hb->hide(); - options->set_text("Grid"); + options->set_text(TTR("Grid Map")); options->get_popup()->add_check_item(TTR("Snap View"), MENU_OPTION_LOCK_VIEW); options->get_popup()->add_separator(); - options->get_popup()->add_item(vformat(TTR("Prev Level (%sDown Wheel)"), keycode_get_string(KEY_MASK_CMD)), MENU_OPTION_PREV_LEVEL); - options->get_popup()->add_item(vformat(TTR("Next Level (%sUp Wheel)"), keycode_get_string(KEY_MASK_CMD)), MENU_OPTION_NEXT_LEVEL); + options->get_popup()->add_item(TTR("Previous Floor"), MENU_OPTION_PREV_LEVEL, KEY_Q); + options->get_popup()->add_item(TTR("Next Floor"), MENU_OPTION_NEXT_LEVEL, KEY_E); options->get_popup()->add_separator(); options->get_popup()->add_check_item(TTR("Clip Disabled"), MENU_OPTION_CLIP_DISABLED); options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true); @@ -993,8 +1046,8 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { options->get_popup()->add_item(TTR("Create Exterior Connector"), MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR); options->get_popup()->add_item(TTR("Erase Area"), MENU_OPTION_REMOVE_AREA); options->get_popup()->add_separator(); - options->get_popup()->add_item(TTR("Selection -> Duplicate"), MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_SHIFT + KEY_INSERT); - options->get_popup()->add_item(TTR("Selection -> Clear"), MENU_OPTION_SELECTION_CLEAR, KEY_MASK_SHIFT + KEY_DELETE); + options->get_popup()->add_item(TTR("Duplicate Selection"), MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_SHIFT + KEY_C); + options->get_popup()->add_item(TTR("Clear Selection"), MENU_OPTION_SELECTION_CLEAR, KEY_MASK_SHIFT + KEY_X); options->get_popup()->add_separator(); options->get_popup()->add_item(TTR("Settings"), MENU_OPTION_GRIDMAP_SETTINGS); @@ -1003,7 +1056,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { settings_dialog->set_title(TTR("GridMap Settings")); add_child(settings_dialog); settings_vbc = memnew(VBoxContainer); - settings_vbc->set_custom_minimum_size(Size2(200, 0)); + settings_vbc->set_custom_minimum_size(Size2(200, 0) * EDSCALE); settings_dialog->add_child(settings_vbc); settings_pick_distance = memnew(SpinBox); @@ -1042,20 +1095,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { add_child(theme_pallete); theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL); - spatial_editor_hb->add_child(memnew(VSeparator)); - Label *fl = memnew(Label); - fl->set_text(" Floor: "); - spatial_editor_hb->add_child(fl); - - floor = memnew(SpinBox); - floor->set_min(-32767); - floor->set_max(32767); - floor->set_step(1); - floor->get_line_edit()->add_constant_override("minimum_spaces", 16); - - spatial_editor_hb->add_child(floor); - floor->connect("value_changed", this, "_floor_changed"); - edit_axis = Vector3::AXIS_Y; edit_floor[0] = -1; edit_floor[1] = -1; @@ -1108,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); @@ -1250,7 +1289,9 @@ GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) { gridmap_editor = memnew(GridMapEditor(editor)); SpatialEditor::get_singleton()->get_palette_split()->add_child(gridmap_editor); - SpatialEditor::get_singleton()->get_palette_split()->move_child(gridmap_editor, 0); + // TODO: make this configurable, so the user can choose were to put this, it makes more sense + // on the right, but some people might find it strange. + SpatialEditor::get_singleton()->get_palette_split()->move_child(gridmap_editor, 1); gridmap_editor->hide(); } diff --git a/modules/hdr/config.py b/modules/hdr/config.py index fb920482f5..5f133eba90 100644 --- a/modules/hdr/config.py +++ b/modules/hdr/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/jpg/config.py b/modules/jpg/config.py index fb920482f5..5f133eba90 100644 --- a/modules/jpg/config.py +++ b/modules/jpg/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/mobile_vr/config.py b/modules/mobile_vr/config.py index cf96c66125..4e1155f0c6 100644 --- a/modules/mobile_vr/config.py +++ b/modules/mobile_vr/config.py @@ -1,12 +1,14 @@ def can_build(platform): - # should probably change this to only be true on iOS and Android - return True + # should probably change this to only be true on iOS and Android + return True def configure(env): - pass + pass def get_doc_classes(): - return ["MobileVRInterface"] + return [ + "MobileVRInterface", + ] def get_doc_path(): - return "doc_classes" + return "doc_classes" diff --git a/modules/mobile_vr/doc_classes/MobileVRInterface.xml b/modules/mobile_vr/doc_classes/MobileVRInterface.xml index c945a99a9a..c99934aea9 100644 --- a/modules/mobile_vr/doc_classes/MobileVRInterface.xml +++ b/modules/mobile_vr/doc_classes/MobileVRInterface.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="MobileVRInterface" inherits="ARVRInterface" category="Core" version="3.0.alpha.custom_build"> +<class name="MobileVRInterface" inherits="ARVRInterface" category="Core" version="3.0-alpha"> <brief_description> Generic mobile VR implementation </brief_description> diff --git a/modules/mobile_vr/mobile_interface.cpp b/modules/mobile_vr/mobile_interface.cpp index dccdcd3070..3a0b83d534 100644 --- a/modules/mobile_vr/mobile_interface.cpp +++ b/modules/mobile_vr/mobile_interface.cpp @@ -323,7 +323,7 @@ void MobileVRInterface::uninitialize() { }; }; -Size2 MobileVRInterface::get_recommended_render_targetsize() { +Size2 MobileVRInterface::get_render_targetsize() { _THREAD_SAFE_METHOD_ // we use half our window size diff --git a/modules/mobile_vr/mobile_interface.h b/modules/mobile_vr/mobile_interface.h index 747377ae46..b652edc1c6 100644 --- a/modules/mobile_vr/mobile_interface.h +++ b/modules/mobile_vr/mobile_interface.h @@ -137,7 +137,7 @@ public: virtual bool initialize(); virtual void uninitialize(); - virtual Size2 get_recommended_render_targetsize(); + virtual Size2 get_render_targetsize(); virtual bool is_stereo(); virtual Transform get_transform_for_eye(ARVRInterface::Eyes p_eye, const Transform &p_cam_transform); virtual CameraMatrix get_projection_for_eye(ARVRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); diff --git a/modules/mono/config.py b/modules/mono/config.py index 7ad135e0b9..b4e6433256 100644 --- a/modules/mono/config.py +++ b/modules/mono/config.py @@ -177,7 +177,11 @@ def configure(env): def get_doc_classes(): - return ["@C#", "CSharpScript", "GodotSharp"] + return [ + "@C#", + "CSharpScript", + "GodotSharp", + ] def get_doc_path(): 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/doc_classes/@C#.xml b/modules/mono/doc_classes/@C#.xml index 487ba9835f..5d27b32200 100644 --- a/modules/mono/doc_classes/@C#.xml +++ b/modules/mono/doc_classes/@C#.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="@C#" category="Core" version="3.0.alpha.custom_build"> +<class name="@C#" category="Core" version="3.0-alpha"> <brief_description> </brief_description> <description> diff --git a/modules/mono/doc_classes/CSharpScript.xml b/modules/mono/doc_classes/CSharpScript.xml index 5f21c9774d..ccc24b832c 100644 --- a/modules/mono/doc_classes/CSharpScript.xml +++ b/modules/mono/doc_classes/CSharpScript.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="CSharpScript" inherits="Script" category="Core" version="3.0.alpha.custom_build"> +<class name="CSharpScript" inherits="Script" category="Core" version="3.0-alpha"> <brief_description> </brief_description> <description> diff --git a/modules/mono/doc_classes/GodotSharp.xml b/modules/mono/doc_classes/GodotSharp.xml index e7e06ddd8f..9edbd18fc1 100644 --- a/modules/mono/doc_classes/GodotSharp.xml +++ b/modules/mono/doc_classes/GodotSharp.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<class name="GodotSharp" inherits="Object" category="Core" version="3.0.alpha.custom_build"> +<class name="GodotSharp" inherits="Object" category="Core" version="3.0-alpha"> <brief_description> </brief_description> <description> diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index eb504ec021..59a2b73dbc 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -31,12 +31,12 @@ #ifdef DEBUG_METHODS_ENABLED +#include "engine.h" #include "global_constants.h" #include "io/compression.h" #include "os/dir_access.h" #include "os/file_access.h" #include "os/os.h" -#include "project_settings.h" #include "ucaps.h" #include "../glue/cs_compressed.gen.h" @@ -320,9 +320,9 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_output_dir, bo int global_constants_count = GlobalConstants::get_global_constant_count(); if (global_constants_count > 0) { - Map<String, DocData::ClassDoc>::Element *match = EditorHelp::get_doc_data()->class_list.find("@Global Scope"); + Map<String, DocData::ClassDoc>::Element *match = EditorHelp::get_doc_data()->class_list.find("@GlobalScope"); - ERR_EXPLAIN("Could not find `@Global Scope` in DocData"); + ERR_EXPLAIN("Could not find `@GlobalScope` in DocData"); ERR_FAIL_COND_V(!match, ERR_BUG); const DocData::ClassDoc &global_scope_doc = match->value(); @@ -1169,7 +1169,7 @@ Error BindingsGenerator::generate_glue(const String &p_output_dir) { output.push_back("Object* "); output.push_back(singleton_icall_name); - output.push_back("() " OPEN_BLOCK "\treturn ProjectSettings::get_singleton()->get_singleton_object(\""); + output.push_back("() " OPEN_BLOCK "\treturn Engine::get_singleton()->get_singleton_object(\""); output.push_back(itype.proxy_name); output.push_back("\");\n" CLOSE_BLOCK "\n"); } @@ -1505,7 +1505,7 @@ void BindingsGenerator::_populate_object_type_interfaces() { TypeInterface itype = TypeInterface::create_object_type(type_cname, api_type); itype.base_name = ClassDB::get_parent_class(type_cname); - itype.is_singleton = ProjectSettings::get_singleton()->has_singleton(itype.proxy_name); + itype.is_singleton = Engine::get_singleton()->has_singleton(itype.proxy_name); itype.is_instantiable = ClassDB::can_instance(type_cname) && !itype.is_singleton; itype.is_reference = ClassDB::is_parent_class(type_cname, refclass_name); itype.memory_own = itype.is_reference; @@ -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/glue/glue_header.h b/modules/mono/glue/glue_header.h index 0751a0160f..75a4eb2b40 100644 --- a/modules/mono/glue/glue_header.h +++ b/modules/mono/glue/glue_header.h @@ -35,10 +35,10 @@ #include "bind/core_bind.h" #include "class_db.h" +#include "engine.h" #include "io/marshalls.h" #include "object.h" #include "os/os.h" -#include "project_settings.h" #include "reference.h" #include "variant_parser.h" 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/mono/register_types.cpp b/modules/mono/register_types.cpp index 2656de5b14..217460a439 100644 --- a/modules/mono/register_types.cpp +++ b/modules/mono/register_types.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "register_types.h" -#include "project_settings.h" +#include "engine.h" #include "csharp_script.h" @@ -45,7 +45,7 @@ void register_mono_types() { _godotsharp = memnew(_GodotSharp); ClassDB::register_class<_GodotSharp>(); - ProjectSettings::get_singleton()->add_singleton(ProjectSettings::Singleton("GodotSharp", _GodotSharp::get_singleton())); + Engine::get_singleton()->add_singleton(Engine::Singleton("GodotSharp", _GodotSharp::get_singleton())); script_language_cs = memnew(CSharpLanguage); script_language_cs->set_language_index(ScriptServer::get_language_count()); diff --git a/modules/ogg/config.py b/modules/ogg/config.py index ef5daca05c..5f133eba90 100644 --- a/modules/ogg/config.py +++ b/modules/ogg/config.py @@ -1,8 +1,5 @@ - def can_build(platform): -# return True - return False - + return True def configure(env): pass diff --git a/modules/openssl/config.py b/modules/openssl/config.py index fb920482f5..5f133eba90 100644 --- a/modules/openssl/config.py +++ b/modules/openssl/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/opus/SCsub b/modules/opus/SCsub index fee06bd267..6f643ef08c 100644 --- a/modules/opus/SCsub +++ b/modules/opus/SCsub @@ -3,6 +3,9 @@ Import('env') Import('env_modules') + +stub = True + env_opus = env_modules.Clone() # Thirdparty source files @@ -212,5 +215,9 @@ if env['builtin_opus']: if env['builtin_libogg']: env_opus.Append(CPPPATH=["#thirdparty/libogg"]) -# Module files -env_opus.add_source_files(env.modules_sources, "*.cpp") +if not stub: + # Module files + env_opus.add_source_files(env.modules_sources, "*.cpp") +else: + # Module files + env_opus.add_source_files(env.modules_sources, "stub/register_types.cpp") diff --git a/modules/opus/config.py b/modules/opus/config.py index ef5daca05c..60f8d838d6 100644 --- a/modules/opus/config.py +++ b/modules/opus/config.py @@ -1,8 +1,13 @@ - def can_build(platform): -# return True - return False - + return True def configure(env): pass + +def get_doc_classes(): + return [ + "AudioStreamOpus", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/opus/stub/register_types.cpp b/modules/opus/stub/register_types.cpp new file mode 100644 index 0000000000..c5ae3e274e --- /dev/null +++ b/modules/opus/stub/register_types.cpp @@ -0,0 +1,36 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.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 "register_types.h" + +// Dummy module as libvorbis is needed by other modules (theora ...) + +void register_opus_types() {} + +void unregister_opus_types() {} diff --git a/modules/opus/stub/register_types.h b/modules/opus/stub/register_types.h new file mode 100644 index 0000000000..4517dc5df7 --- /dev/null +++ b/modules/opus/stub/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.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. */ +/*************************************************************************/ +void register_opus_types(); +void unregister_opus_types(); diff --git a/modules/pbm/config.py b/modules/pbm/config.py index fb920482f5..5f133eba90 100644 --- a/modules/pbm/config.py +++ b/modules/pbm/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/pvr/config.py b/modules/pvr/config.py index fb920482f5..5f133eba90 100644 --- a/modules/pvr/config.py +++ b/modules/pvr/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/recast/config.py b/modules/recast/config.py index d42f07b2a9..fc074cf661 100644 --- a/modules/recast/config.py +++ b/modules/recast/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return platform != "android" - def configure(env): pass diff --git a/modules/regex/config.py b/modules/regex/config.py index 5347cfd243..cb2da26738 100644 --- a/modules/regex/config.py +++ b/modules/regex/config.py @@ -1,9 +1,14 @@ -#!/usr/bin/env python - - def can_build(platform): return True - def configure(env): pass + +def get_doc_classes(): + return [ + "RegEx", + "RegExMatch", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/regex/doc_classes/RegEx.xml b/modules/regex/doc_classes/RegEx.xml new file mode 100644 index 0000000000..4cf272fe8c --- /dev/null +++ b/modules/regex/doc_classes/RegEx.xml @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="RegEx" inherits="Reference" category="Core" version="3.0-alpha"> + <brief_description> + Class for searching text for patterns using regular expressions. + </brief_description> + <description> + Regular Expression (or regex) is a compact programming language that can be used to recognise strings that follow a specific pattern, such as URLs, email addresses, complete sentences, etc. For instance, a regex of [code]ab[0-9][/code] would find any string that is [code]ab[/code] followed by any number from [code]0[/code] to [code]9[/code]. For a more in-depth look, you can easily find various tutorials and detailed explainations on the Internet. + To begin, the RegEx object needs to be compiled with the search pattern using [method compile] before it can be used. + [codeblock] + var regex = RegEx.new() + regex.compile("\\w-(\\d+)") + [/codeblock] + The search pattern must be escaped first for gdscript before it is escaped for the expression. For example, [code]compile("\\d+")[/code] would be read by RegEx as [code]\d+[/code]. Similarly, [code]compile("\"(?:\\\\.|[^\"])*\"")[/code] would be read as [code]"(?:\\.|[^"])*"[/code] + Using [method search] you can find the pattern within the given text. If a pattern is found, [RegExMatch] is returned and you can retrieve details of the results using fuctions such as [method RegExMatch.get_string] and [method RegExMatch.get_start]. + [codeblock] + var regex = RegEx.new() + regex.compile("\\w-(\\d+)") + var result = regex.search("abc n-0123") + if result: + print(result.get_string()) # Would print n-0123 + [/codeblock] + The results of capturing groups [code]()[/code] can be retrieved by passing the group number to the various functions in [RegExMatch]. Group 0 is the default and would always refer to the entire pattern. In the above example, calling [code]result.get_string(1)[/code] would give you [code]0123[/code]. + This version of RegEx also supports named capturing groups, and the names can be used to retrieve the results. If two or more groups have the same name, the name would only refer to the first one with a match. + [codeblock] + var regex = RegEx.new() + regex.compile("d(?<digit>[0-9]+)|x(?<digit>[0-9a-f]+)") + var result = regex.search("the number is x2f") + if result: + print(result.get_string("digit")) # Would print 2f + [/codeblock] + If you need to process multiple results, [method search_all] generates a list of all non-overlapping results. This can be combined with a for-loop for convenience. + [codeblock] + for result in regex.search_all("d01, d03, d0c, x3f and x42"): + print(result.get_string("digit")) + # Would print 01 03 3f 42 + # Note that d0c would not match + [/codeblock] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="clear"> + <return type="void"> + </return> + <description> + This method resets the state of the object, as it was freshly created. Namely, it unassigns the regular expression of this object. + </description> + </method> + <method name="compile"> + <return type="int" enum="Error"> + </return> + <argument index="0" name="pattern" type="String"> + </argument> + <description> + Compiles and assign the search pattern to use. Returns OK if the compilation is successful. If an error is encountered the details are printed to STDOUT and FAILED is returned. + </description> + </method> + <method name="get_group_count" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the number of capturing groups in compiled pattern. + </description> + </method> + <method name="get_names" qualifiers="const"> + <return type="Array"> + </return> + <description> + Returns an array of names of named capturing groups in the compiled pattern. They are ordered by appearance. + </description> + </method> + <method name="get_pattern" qualifiers="const"> + <return type="String"> + </return> + <description> + Returns the original search pattern that was compiled. + </description> + </method> + <method name="is_valid" qualifiers="const"> + <return type="bool"> + </return> + <description> + Returns whether this object has a valid search pattern assigned. + </description> + </method> + <method name="search" qualifiers="const"> + <return type="RegExMatch"> + </return> + <argument index="0" name="subject" type="String"> + </argument> + <argument index="1" name="offset" type="int" default="0"> + </argument> + <argument index="2" name="end" type="int" default="-1"> + </argument> + <description> + Searches the text for the compiled pattern. Returns a [RegExMatch] container of the first matching result if found, otherwise null. The region to search within can be specified without modifying where the start and end anchor would be. + </description> + </method> + <method name="search_all" qualifiers="const"> + <return type="Array"> + </return> + <argument index="0" name="subject" type="String"> + </argument> + <argument index="1" name="offset" type="int" default="0"> + </argument> + <argument index="2" name="end" type="int" default="-1"> + </argument> + <description> + Searches the text for the compiled pattern. Returns an array of [RegExMatch] containers for each non-overlapping result. If no results were found an empty array is returned instead. The region to search within can be specified without modifying where the start and end anchor would be. + </description> + </method> + <method name="sub" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="subject" type="String"> + </argument> + <argument index="1" name="replacement" type="String"> + </argument> + <argument index="2" name="all" type="bool" default="false"> + </argument> + <argument index="3" name="offset" type="int" default="0"> + </argument> + <argument index="4" name="end" type="int" default="-1"> + </argument> + <description> + Searches the text for the compiled pattern and replaces it with the specified string. Escapes and backreferences such as [code]\1[/code] and [code]\g<name>[/code] expanded and resolved. By default only the first instance is replaced but it can be changed for all instances (global replacement). The region to search within can be specified without modifying where the start and end anchor would be. + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/modules/regex/doc_classes/RegExMatch.xml b/modules/regex/doc_classes/RegExMatch.xml new file mode 100644 index 0000000000..8c6951fea2 --- /dev/null +++ b/modules/regex/doc_classes/RegExMatch.xml @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="RegExMatch" inherits="Reference" category="Core" version="3.0-alpha"> + <brief_description> + 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. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_end" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="name" type="Variant" default="0"> + </argument> + <description> + Returns the end position of the match within the source string. The end position of capturing groups can be retrieved by providing its group number as an integer or its string name (if it's a named group). The default value of 0 refers to the whole pattern. + Returns -1 if the group did not match or doesn't exist. + </description> + </method> + <method name="get_group_count" qualifiers="const"> + <return type="int"> + </return> + <description> + Returns the number of capturing groups. + </description> + </method> + <method name="get_names" qualifiers="const"> + <return type="Dictionary"> + </return> + <description> + Returns a dictionary of named groups and its corresponding group number. Only groups with that were matched are included. If multiple groups have the same name, that name would refer to the first matching one. + </description> + </method> + <method name="get_start" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="name" type="Variant" default="0"> + </argument> + <description> + Returns the starting position of the match within the source string. The starting position of capturing groups can be retrieved by providing its group number as an integer or its string name (if it's a named group). The default value of 0 refers to the whole pattern. + Returns -1 if the group did not match or doesn't exist. + </description> + </method> + <method name="get_string" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="name" type="Variant" default="0"> + </argument> + <description> + Returns the substring of the match from the source string. Capturing groups can be retrieved by providing its group number as an integer or its string name (if it's a named group). The default value of 0 refers to the whole pattern. + Returns an empty string if the group did not match or doesn't exist. + </description> + </method> + <method name="get_strings" qualifiers="const"> + <return type="Array"> + </return> + <description> + Returns an [Array] of the match and its capturing groups. + </description> + </method> + <method name="get_subject" qualifiers="const"> + <return type="String"> + </return> + <description> + Returns the source string used with the search pattern to find this matching result. + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/modules/regex/regex.cpp b/modules/regex/regex.cpp index 00e8ce0f54..daadfcc659 100644 --- a/modules/regex/regex.cpp +++ b/modules/regex/regex.cpp @@ -324,6 +324,21 @@ Ref<RegExMatch> RegEx::search(const String &p_subject, int p_offset, int p_end) return result; } +Array RegEx::search_all(const String &p_subject, int p_offset, int p_end) const { + + int last_end = -1; + Array result; + Ref<RegExMatch> match = search(p_subject, p_offset, p_end); + while (match.is_valid()) { + if (last_end == match->get_end(0)) + break; + result.push_back(match); + last_end = match->get_end(0); + match = search(p_subject, match->get_end(0), p_end); + } + return result; +} + String RegEx::sub(const String &p_subject, const String &p_replacement, bool p_all, int p_offset, int p_end) const { ERR_FAIL_COND_V(!is_valid(), String()); @@ -489,6 +504,7 @@ void RegEx::_bind_methods() { ClassDB::bind_method(D_METHOD("clear"), &RegEx::clear); ClassDB::bind_method(D_METHOD("compile", "pattern"), &RegEx::compile); ClassDB::bind_method(D_METHOD("search", "subject", "offset", "end"), &RegEx::search, DEFVAL(0), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("search_all", "subject", "offset", "end"), &RegEx::search_all, DEFVAL(0), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("sub", "subject", "replacement", "all", "offset", "end"), &RegEx::sub, DEFVAL(false), DEFVAL(0), DEFVAL(-1)); ClassDB::bind_method(D_METHOD("is_valid"), &RegEx::is_valid); ClassDB::bind_method(D_METHOD("get_pattern"), &RegEx::get_pattern); diff --git a/modules/regex/regex.h b/modules/regex/regex.h index bfa9c84042..21387222f2 100644 --- a/modules/regex/regex.h +++ b/modules/regex/regex.h @@ -88,6 +88,7 @@ public: void _init(const String &p_pattern = ""); Ref<RegExMatch> search(const String &p_subject, int p_offset = 0, int p_end = -1) const; + Array search_all(const String &p_subject, int p_offset = 0, int p_end = -1) const; String sub(const String &p_subject, const String &p_replacement, bool p_all = false, int p_offset = 0, int p_end = -1) const; bool is_valid() const; diff --git a/modules/squish/config.py b/modules/squish/config.py index 9b7729bda4..97c95999c8 100644 --- a/modules/squish/config.py +++ b/modules/squish/config.py @@ -1,8 +1,6 @@ - def can_build(platform): return True - def configure(env): # Tools only, disabled for non-tools # TODO: Find a cleaner way to achieve that diff --git a/modules/stb_vorbis/config.py b/modules/stb_vorbis/config.py index fb920482f5..defe8d0c94 100644 --- a/modules/stb_vorbis/config.py +++ b/modules/stb_vorbis/config.py @@ -1,7 +1,14 @@ - def can_build(platform): return True - def configure(env): pass + +def get_doc_classes(): + return [ + "AudioStreamOGGVorbis", + "ResourceImporterOGGVorbis", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/stb_vorbis/doc_classes/AudioStreamOGGVorbis.xml b/modules/stb_vorbis/doc_classes/AudioStreamOGGVorbis.xml new file mode 100644 index 0000000000..ee6c28c36a --- /dev/null +++ b/modules/stb_vorbis/doc_classes/AudioStreamOGGVorbis.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="AudioStreamOGGVorbis" inherits="AudioStream" category="Core" version="3.0-alpha"> + <brief_description> + OGG Vorbis audio stream driver. + </brief_description> + <description> + OGG Vorbis audio stream driver. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_data" qualifiers="const"> + <return type="PoolByteArray"> + </return> + <description> + </description> + </method> + <method name="get_loop_offset" qualifiers="const"> + <return type="float"> + </return> + <description> + </description> + </method> + <method name="has_loop" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="set_data"> + <return type="void"> + </return> + <argument index="0" name="data" type="PoolByteArray"> + </argument> + <description> + </description> + </method> + <method name="set_loop"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="set_loop_offset"> + <return type="void"> + </return> + <argument index="0" name="seconds" type="float"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="data" type="PoolByteArray" setter="set_data" getter="get_data"> + Raw audio data. + </member> + <member name="loop" type="bool" setter="set_loop" getter="has_loop"> + If [code]true[/code], audio will loop continuously. Default value: [code]false[/code]. + </member> + <member name="loop_offset" type="float" setter="set_loop_offset" getter="get_loop_offset"> + If loop is [code]true[/code], loop starts from this position, in seconds. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/stb_vorbis/doc_classes/ResourceImporterOGGVorbis.xml b/modules/stb_vorbis/doc_classes/ResourceImporterOGGVorbis.xml new file mode 100644 index 0000000000..ce16632d6e --- /dev/null +++ b/modules/stb_vorbis/doc_classes/ResourceImporterOGGVorbis.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="ResourceImporterOGGVorbis" inherits="ResourceImporter" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/svg/config.py b/modules/svg/config.py index fb920482f5..5f133eba90 100644 --- a/modules/svg/config.py +++ b/modules/svg/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/tga/config.py b/modules/tga/config.py index fb920482f5..5f133eba90 100644 --- a/modules/tga/config.py +++ b/modules/tga/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass diff --git a/modules/theora/config.py b/modules/theora/config.py index 8eefe81288..34d34f8be2 100644 --- a/modules/theora/config.py +++ b/modules/theora/config.py @@ -1,8 +1,14 @@ - def can_build(platform): -# return True - return False - + return True def configure(env): pass + +def get_doc_classes(): + return [ + "ResourceImporterTheora", + "VideoStreamTheora", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/theora/doc_classes/ResourceImporterTheora.xml b/modules/theora/doc_classes/ResourceImporterTheora.xml new file mode 100644 index 0000000000..497c938826 --- /dev/null +++ b/modules/theora/doc_classes/ResourceImporterTheora.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="ResourceImporterTheora" inherits="ResourceImporter" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/theora/doc_classes/VideoStreamTheora.xml b/modules/theora/doc_classes/VideoStreamTheora.xml new file mode 100644 index 0000000000..8f155b786f --- /dev/null +++ b/modules/theora/doc_classes/VideoStreamTheora.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VideoStreamTheora" inherits="VideoStream" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_file"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_file"> + <return type="void"> + </return> + <argument index="0" name="file" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="file" type="String" setter="set_file" getter="get_file"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/theora/register_types.cpp b/modules/theora/register_types.cpp index ae6961b3da..c51b87b8fc 100644 --- a/modules/theora/register_types.cpp +++ b/modules/theora/register_types.cpp @@ -28,19 +28,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "register_types.h" - +#include "resource_importer_theora.h" #include "video_stream_theora.h" -static ResourceFormatLoaderVideoStreamTheora *theora_stream_loader = NULL; - void register_theora_types() { - theora_stream_loader = memnew(ResourceFormatLoaderVideoStreamTheora); - ResourceLoader::add_resource_format_loader(theora_stream_loader); +#ifdef TOOLS_ENABLED + Ref<ResourceImporterTheora> theora_import; + theora_import.instance(); + ResourceFormatImporter::get_singleton()->add_importer(theora_import); +#endif ClassDB::register_class<VideoStreamTheora>(); } void unregister_theora_types() { - - memdelete(theora_stream_loader); } diff --git a/modules/theora/resource_importer_theora.cpp b/modules/theora/resource_importer_theora.cpp new file mode 100644 index 0000000000..c25c0e7427 --- /dev/null +++ b/modules/theora/resource_importer_theora.cpp @@ -0,0 +1,89 @@ +/*************************************************************************/ +/* resource_importer_theora.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.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 "resource_importer_theora.h" + +#include "io/resource_saver.h" +#include "os/file_access.h" +#include "scene/resources/texture.h" + +String ResourceImporterTheora::get_importer_name() const { + + return "Theora"; +} + +String ResourceImporterTheora::get_visible_name() const { + + return "Theora"; +} +void ResourceImporterTheora::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("ogv"); + p_extensions->push_back("ogm"); +} + +String ResourceImporterTheora::get_save_extension() const { + return "ogvstr"; +} + +String ResourceImporterTheora::get_resource_type() const { + + return "VideoStreamTheora"; +} + +bool ResourceImporterTheora::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { + + return true; +} + +int ResourceImporterTheora::get_preset_count() const { + return 0; +} +String ResourceImporterTheora::get_preset_name(int p_idx) const { + + return String(); +} + +void ResourceImporterTheora::get_import_options(List<ImportOption> *r_options, int p_preset) const { + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true)); +} + +Error ResourceImporterTheora::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { + + VideoStreamTheora *stream = memnew(VideoStreamTheora); + stream->set_file(p_source_file); + + Ref<VideoStreamTheora> ogv_stream = Ref<VideoStreamTheora>(stream); + + return ResourceSaver::save(p_save_path + ".ogvstr", ogv_stream); +} + +ResourceImporterTheora::ResourceImporterTheora() { +} diff --git a/modules/theora/resource_importer_theora.h b/modules/theora/resource_importer_theora.h new file mode 100644 index 0000000000..8bf0ad38c4 --- /dev/null +++ b/modules/theora/resource_importer_theora.h @@ -0,0 +1,57 @@ +/*************************************************************************/ +/* resource_importer_theora.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.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 RESOURCEIMPORTEROGGTHEORA_H +#define RESOURCEIMPORTEROGGTHEORA_H + +#include "video_stream_theora.h" + +#include "core/io/resource_import.h" + +class ResourceImporterTheora : public ResourceImporter { + GDCLASS(ResourceImporterTheora, ResourceImporter) +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; + virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; + + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + + ResourceImporterTheora(); +}; + +#endif // RESOURCEIMPORTEROGGTHEORA_H diff --git a/modules/theora/video_stream_theora.cpp b/modules/theora/video_stream_theora.cpp index c75bec31df..bc8ca23d60 100644 --- a/modules/theora/video_stream_theora.cpp +++ b/modules/theora/video_stream_theora.cpp @@ -406,20 +406,19 @@ void VideoStreamPlaybackTheora::update(float p_delta) { ogg_packet op; bool no_theora = false; + bool buffer_full = false; - while (vorbis_p) { + while (vorbis_p && !audio_done && !buffer_full) { int ret; float **pcm; - bool buffer_full = false; - /* if there's pending, decoded audio, grab it */ ret = vorbis_synthesis_pcmout(&vd, &pcm); if (ret > 0) { const int AUXBUF_LEN = 4096; int to_read = ret; - int16_t aux_buffer[AUXBUF_LEN]; + float aux_buffer[AUXBUF_LEN]; while (to_read) { @@ -429,11 +428,7 @@ void VideoStreamPlaybackTheora::update(float p_delta) { for (int j = 0; j < m; j++) { for (int i = 0; i < vi.channels; i++) { - - int val = Math::fast_ftoi(pcm[i][j] * 32767.f); - if (val > 32767) val = 32767; - if (val < -32768) val = -32768; - aux_buffer[count++] = val; + aux_buffer[count++] = pcm[i][j]; } } @@ -602,10 +597,9 @@ bool VideoStreamPlaybackTheora::is_playing() const { void VideoStreamPlaybackTheora::set_paused(bool p_paused) { paused = p_paused; - //pau = !p_paused; }; -bool VideoStreamPlaybackTheora::is_paused(bool p_paused) const { +bool VideoStreamPlaybackTheora::is_paused() const { return paused; }; @@ -733,32 +727,10 @@ VideoStreamPlaybackTheora::~VideoStreamPlaybackTheora() { memdelete(file); }; -RES ResourceFormatLoaderVideoStreamTheora::load(const String &p_path, const String &p_original_path, Error *r_error) { - if (r_error) - *r_error = ERR_FILE_CANT_OPEN; - - VideoStreamTheora *stream = memnew(VideoStreamTheora); - stream->set_file(p_path); - - if (r_error) - *r_error = OK; - - return Ref<VideoStreamTheora>(stream); -} +void VideoStreamTheora::_bind_methods() { -void ResourceFormatLoaderVideoStreamTheora::get_recognized_extensions(List<String> *p_extensions) const { + ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamTheora::set_file); + ClassDB::bind_method(D_METHOD("get_file"), &VideoStreamTheora::get_file); - p_extensions->push_back("ogm"); - p_extensions->push_back("ogv"); -} -bool ResourceFormatLoaderVideoStreamTheora::handles_type(const String &p_type) const { - return (p_type == "VideoStream" || p_type == "VideoStreamTheora"); -} - -String ResourceFormatLoaderVideoStreamTheora::get_resource_type(const String &p_path) const { - - String exl = p_path.get_extension().to_lower(); - if (exl == "ogm" || exl == "ogv") - return "VideoStreamTheora"; - return ""; + ADD_PROPERTY(PropertyInfo(Variant::STRING, "file", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_file", "get_file"); } diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h index 484a1a7fb9..ec0e5aa34a 100644 --- a/modules/theora/video_stream_theora.h +++ b/modules/theora/video_stream_theora.h @@ -36,6 +36,7 @@ #include "os/thread.h" #include "ring_buffer.h" #include "scene/resources/video_stream.h" +#include "servers/audio_server.h" #include <theora/theoradec.h> #include <vorbis/codec.h> @@ -129,7 +130,7 @@ public: virtual bool is_playing() const; virtual void set_paused(bool p_paused); - virtual bool is_paused(bool p_paused) const; + virtual bool is_paused() const; virtual void set_loop(bool p_enable); virtual bool has_loop() const; @@ -161,10 +162,14 @@ public: class VideoStreamTheora : public VideoStream { GDCLASS(VideoStreamTheora, VideoStream); + RES_BASE_EXTENSION("ogvstr"); String file; int audio_track; +protected: + static void _bind_methods(); + public: Ref<VideoStreamPlayback> instance_playback() { Ref<VideoStreamPlaybackTheora> pb = memnew(VideoStreamPlaybackTheora); @@ -174,17 +179,10 @@ public: } void set_file(const String &p_file) { file = p_file; } + String get_file() { return file; } void set_audio_track(int p_track) { audio_track = p_track; } VideoStreamTheora() { audio_track = 0; } }; -class ResourceFormatLoaderVideoStreamTheora : public ResourceFormatLoader { -public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; -}; - #endif diff --git a/modules/tinyexr/config.py b/modules/tinyexr/config.py index 3e16fd725e..e12bb398ce 100644 --- a/modules/tinyexr/config.py +++ b/modules/tinyexr/config.py @@ -1,8 +1,6 @@ - def can_build(platform): return True - def configure(env): # Tools only, disabled for non-tools # TODO: Find a cleaner way to achieve that diff --git a/modules/visual_script/config.py b/modules/visual_script/config.py index 5698a37295..6b1ce41014 100644 --- a/modules/visual_script/config.py +++ b/modules/visual_script/config.py @@ -1,8 +1,57 @@ - - def can_build(platform): return True - def configure(env): pass + +def get_doc_classes(): + return [ + "VisualScriptBasicTypeConstant", + "VisualScriptBuiltinFunc", + "VisualScriptClassConstant", + "VisualScriptComment", + "VisualScriptCondition", + "VisualScriptConstant", + "VisualScriptConstructor", + "VisualScriptCustomNode", + "VisualScriptDeconstruct", + "VisualScriptEditor", + "VisualScriptEmitSignal", + "VisualScriptEngineSingleton", + "VisualScriptExpression", + "VisualScriptFunctionCall", + "VisualScriptFunctionState", + "VisualScriptFunction", + "VisualScriptGlobalConstant", + "VisualScriptIndexGet", + "VisualScriptIndexSet", + "VisualScriptInputAction", + "VisualScriptIterator", + "VisualScriptLocalVarSet", + "VisualScriptLocalVar", + "VisualScriptMathConstant", + "VisualScriptNode", + "VisualScriptOperator", + "VisualScriptPreload", + "VisualScriptPropertyGet", + "VisualScriptPropertySet", + "VisualScriptResourcePath", + "VisualScriptReturn", + "VisualScriptSceneNode", + "VisualScriptSceneTree", + "VisualScriptSelect", + "VisualScriptSelf", + "VisualScriptSequence", + "VisualScriptSubCall", + "VisualScriptSwitch", + "VisualScriptTypeCast", + "VisualScriptVariableGet", + "VisualScriptVariableSet", + "VisualScriptWhile", + "VisualScript", + "VisualScriptYieldSignal", + "VisualScriptYield", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/visual_script/doc_classes/VisualScript.xml b/modules/visual_script/doc_classes/VisualScript.xml new file mode 100644 index 0000000000..80b1ed86d7 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScript.xml @@ -0,0 +1,515 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScript" inherits="Script" category="Core" version="3.0-alpha"> + <brief_description> + A script implemented in the Visual Script programming environment. + </brief_description> + <description> + A script implemented in the Visual Script programming environment. The script extends the functionality of all objects that instance it. + [method Object.set_script] extends an existing object, if that object's class matches one of the script's base classes. + You are most likely to use this class via the Visual Script editor or when writing plugins for it. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="add_custom_signal"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Add a custom signal with the specified name to the VisualScript. + </description> + </method> + <method name="add_function"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Add a function with the specified name to the VisualScript. + </description> + </method> + <method name="add_node"> + <return type="void"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="id" type="int"> + </argument> + <argument index="2" name="node" type="VisualScriptNode"> + </argument> + <argument index="3" name="position" type="Vector2" default="Vector2( 0, 0 )"> + </argument> + <description> + Add a node to a function of the VisualScript. + </description> + </method> + <method name="add_variable"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="default_value" type="Variant" default="null"> + </argument> + <argument index="2" name="export" type="bool" default="false"> + </argument> + <description> + Add a variable to the VisualScript, optionally giving it a default value or marking it as exported. + </description> + </method> + <method name="custom_signal_add_argument"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="type" type="int" enum="Variant.Type"> + </argument> + <argument index="2" name="argname" type="String"> + </argument> + <argument index="3" name="index" type="int" default="-1"> + </argument> + <description> + Add an argument to a custom signal added with [method add_custom_signal]. + </description> + </method> + <method name="custom_signal_get_argument_count" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Get the count of a custom signal's arguments. + </description> + </method> + <method name="custom_signal_get_argument_name" qualifiers="const"> + <return type="String"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="argidx" type="int"> + </argument> + <description> + Get the name of a custom signal's argument. + </description> + </method> + <method name="custom_signal_get_argument_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="argidx" type="int"> + </argument> + <description> + Get the type of a custom signal's argument. + </description> + </method> + <method name="custom_signal_remove_argument"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="argidx" type="int"> + </argument> + <description> + Remove a specific custom signal's argument. + </description> + </method> + <method name="custom_signal_set_argument_name"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="argidx" type="int"> + </argument> + <argument index="2" name="argname" type="String"> + </argument> + <description> + Rename a custom signal's argument. + </description> + </method> + <method name="custom_signal_set_argument_type"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="argidx" type="int"> + </argument> + <argument index="2" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + Change the type of a custom signal's argument. + </description> + </method> + <method name="custom_signal_swap_argument"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="argidx" type="int"> + </argument> + <argument index="2" name="withidx" type="int"> + </argument> + <description> + Swap two of the arguments of a custom signal. + </description> + </method> + <method name="data_connect"> + <return type="void"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="from_node" type="int"> + </argument> + <argument index="2" name="from_port" type="int"> + </argument> + <argument index="3" name="to_node" type="int"> + </argument> + <argument index="4" name="to_port" type="int"> + </argument> + <description> + Connect two data ports. The value of [code]from_node[/code]'s [code]from_port[/code] would be fed into [code]to_node[/code]'s [code]to_port[/code]. + </description> + </method> + <method name="data_disconnect"> + <return type="void"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="from_node" type="int"> + </argument> + <argument index="2" name="from_port" type="int"> + </argument> + <argument index="3" name="to_node" type="int"> + </argument> + <argument index="4" name="to_port" type="int"> + </argument> + <description> + Disconnect two data ports previously connected with [method data_connect]. + </description> + </method> + <method name="get_function_node_id" qualifiers="const"> + <return type="int"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Returns the id of a function's entry point node. + </description> + </method> + <method name="get_function_scroll" qualifiers="const"> + <return type="Vector2"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Returns the position of the center of the screen for a given function. + </description> + </method> + <method name="get_node" qualifiers="const"> + <return type="VisualScriptNode"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="id" type="int"> + </argument> + <description> + Returns a node given its id and its function. + </description> + </method> + <method name="get_node_position" qualifiers="const"> + <return type="Vector2"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="id" type="int"> + </argument> + <description> + Returns a node's position in pixels. + </description> + </method> + <method name="get_variable_default_value" qualifiers="const"> + <return type="Variant"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Returns the default (initial) value of a variable. + </description> + </method> + <method name="get_variable_export" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Returns whether a variable is exported. + </description> + </method> + <method name="get_variable_info" qualifiers="const"> + <return type="Dictionary"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Returns the info for a given variable as a dictionary. The information includes its name, type, hint and usage. + </description> + </method> + <method name="has_custom_signal" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Returns whether a signal exists with the specified name. + </description> + </method> + <method name="has_data_connection" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="from_node" type="int"> + </argument> + <argument index="2" name="from_port" type="int"> + </argument> + <argument index="3" name="to_node" type="int"> + </argument> + <argument index="4" name="to_port" type="int"> + </argument> + <description> + Returns whether the specified data ports are connected. + </description> + </method> + <method name="has_function" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Returns whether a function exists with the specified name. + </description> + </method> + <method name="has_node" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="id" type="int"> + </argument> + <description> + Returns whether a node exists with the given id. + </description> + </method> + <method name="has_sequence_connection" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="from_node" type="int"> + </argument> + <argument index="2" name="from_output" type="int"> + </argument> + <argument index="3" name="to_node" type="int"> + </argument> + <description> + Returns whether the specified sequence ports are connected. + </description> + </method> + <method name="has_variable" qualifiers="const"> + <return type="bool"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Returns whether a variable exists with the specified name. + </description> + </method> + <method name="remove_custom_signal"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Remove a custom signal with the given name. + </description> + </method> + <method name="remove_function"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Remove a specific function and its nodes from the script. + </description> + </method> + <method name="remove_node"> + <return type="void"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="id" type="int"> + </argument> + <description> + Remove a specific node. + </description> + </method> + <method name="remove_variable"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + Remove a variable with the given name. + </description> + </method> + <method name="rename_custom_signal"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="new_name" type="String"> + </argument> + <description> + Change the name of a custom signal. + </description> + </method> + <method name="rename_function"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="new_name" type="String"> + </argument> + <description> + Change the name of a function. + </description> + </method> + <method name="rename_variable"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="new_name" type="String"> + </argument> + <description> + Change the name of a variable. + </description> + </method> + <method name="sequence_connect"> + <return type="void"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="from_node" type="int"> + </argument> + <argument index="2" name="from_output" type="int"> + </argument> + <argument index="3" name="to_node" type="int"> + </argument> + <description> + Connect two sequence ports. The execution will flow from of [code]from_node[/code]'s [code]from_output[/code] into [code]to_node[/code]. + Unlike [method data_connect], there isn't a [code]to_port[/code], since the target node can have only one sequence port. + </description> + </method> + <method name="sequence_disconnect"> + <return type="void"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="from_node" type="int"> + </argument> + <argument index="2" name="from_output" type="int"> + </argument> + <argument index="3" name="to_node" type="int"> + </argument> + <description> + Disconnect two sequence ports previously connected with [method sequence_connect]. + </description> + </method> + <method name="set_function_scroll"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="ofs" type="Vector2"> + </argument> + <description> + Position the center of the screen for a function. + </description> + </method> + <method name="set_instance_base_type"> + <return type="void"> + </return> + <argument index="0" name="type" type="String"> + </argument> + <description> + Set the base type of the script. + </description> + </method> + <method name="set_node_position"> + <return type="void"> + </return> + <argument index="0" name="func" type="String"> + </argument> + <argument index="1" name="id" type="int"> + </argument> + <argument index="2" name="position" type="Vector2"> + </argument> + <description> + Position a node on the screen. + </description> + </method> + <method name="set_variable_default_value"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="value" type="Variant"> + </argument> + <description> + Change the default (initial) value of a variable. + </description> + </method> + <method name="set_variable_export"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="enable" type="bool"> + </argument> + <description> + Change whether a variable is exported. + </description> + </method> + <method name="set_variable_info"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="value" type="Dictionary"> + </argument> + <description> + Set a variable's info, using the same format as [method get_variable_info]. + </description> + </method> + </methods> + <members> + <member name="data" type="Dictionary" setter="_set_data" getter="_get_data"> + </member> + </members> + <signals> + <signal name="node_ports_changed"> + <argument index="0" name="function" type="String"> + </argument> + <argument index="1" name="id" type="int"> + </argument> + <description> + Emitted when the ports of a node are changed. + </description> + </signal> + </signals> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml b/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml new file mode 100644 index 0000000000..6c028e5f28 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptBasicTypeConstant.xml @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptBasicTypeConstant" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + A Visual Script node representing a constant from the base types. + </brief_description> + <description> + A Visual Script node representing a constant from base types, such as [Vector3.AXIS_X]. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_basic_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="get_basic_type_constant" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_basic_type"> + <return type="void"> + </return> + <argument index="0" name="name" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + <method name="set_basic_type_constant"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type"> + The type to get the constant from. + </member> + <member name="constant" type="String" setter="set_basic_type_constant" getter="get_basic_type_constant"> + The name of the constant to return. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml new file mode 100644 index 0000000000..c45c8d2b64 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptBuiltinFunc.xml @@ -0,0 +1,225 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptBuiltinFunc" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + A Visual Script node used to call built-in functions. + </brief_description> + <description> + A built-in function used inside a [VisualScript]. It is usually a math function or an utility function. + See also [@GDScript], for the same functions in the GDScript language. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_func"> + <return type="int" enum="VisualScriptBuiltinFunc.BuiltinFunc"> + </return> + <description> + </description> + </method> + <method name="set_func"> + <return type="void"> + </return> + <argument index="0" name="which" type="int" enum="VisualScriptBuiltinFunc.BuiltinFunc"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="function" type="int" setter="set_func" getter="get_func" enum="VisualScriptBuiltinFunc.BuiltinFunc"> + The function to be executed. + </member> + </members> + <constants> + <constant name="MATH_SIN" value="0"> + Return the sine of the input. + </constant> + <constant name="MATH_COS" value="1"> + Return the cosine of the input. + </constant> + <constant name="MATH_TAN" value="2"> + Return the tangent of the input. + </constant> + <constant name="MATH_SINH" value="3"> + Return the hyperbolic sine of the input. + </constant> + <constant name="MATH_COSH" value="4"> + Return the hyperbolic cosine of the input. + </constant> + <constant name="MATH_TANH" value="5"> + Return the hyperbolic tangent of the input. + </constant> + <constant name="MATH_ASIN" value="6"> + Return the arc sine of the input. + </constant> + <constant name="MATH_ACOS" value="7"> + Return the arc cosine of the input. + </constant> + <constant name="MATH_ATAN" value="8"> + Return the arc tangent of the input. + </constant> + <constant name="MATH_ATAN2" value="9"> + Return the arc tangent of the input, using the signs of both parameters to determine the exact angle. + </constant> + <constant name="MATH_SQRT" value="10"> + Return the square root of the input. + </constant> + <constant name="MATH_FMOD" value="11"> + Return the remainder of one input divided by the other, using floating-point numbers. + </constant> + <constant name="MATH_FPOSMOD" value="12"> + Return the positive remainder of one input divided by the other, using floating-point numbers. + </constant> + <constant name="MATH_FLOOR" value="13"> + Return the input rounded down. + </constant> + <constant name="MATH_CEIL" value="14"> + Return the input rounded up. + </constant> + <constant name="MATH_ROUND" value="15"> + Return the input rounded to the nearest integer. + </constant> + <constant name="MATH_ABS" value="16"> + Return the absolute value of the input. + </constant> + <constant name="MATH_SIGN" value="17"> + Return the sign of the input, turning it into 1, -1, or 0. Useful to determine if the input is positive or negative. + </constant> + <constant name="MATH_POW" value="18"> + Return the input raised to a given power. + </constant> + <constant name="MATH_LOG" value="19"> + Return the natural logarithm of the input. Note that this is not the typical base-10 logarithm function calculators use. + </constant> + <constant name="MATH_EXP" value="20"> + Return [b]e[/b] raised to the power of the input. [b]e[/b] sometimes called "Euler's number" is a mathematical constant whose value is approximately 2.71828. + </constant> + <constant name="MATH_ISNAN" value="21"> + Return whether the input is NaN (Not a Number) or not. NaN is usually produced by dividing 0 by 0, though other ways exist. + </constant> + <constant name="MATH_ISINF" value="22"> + Return whether the input is an infinite floating-point number or not. Infinity is usually produced by dividing a number by 0, though other ways exist. + </constant> + <constant name="MATH_EASE" value="23"> + Easing function, based on exponent. 0 is constant, 1 is linear, 0 to 1 is ease-in, 1+ is ease out. Negative values are in-out/out in. + </constant> + <constant name="MATH_DECIMALS" value="24"> + Return the number of digit places after the decimal that the first non-zero digit occurs. + </constant> + <constant name="MATH_STEPIFY" value="25"> + Return the input snapped to a given step. + </constant> + <constant name="MATH_LERP" value="26"> + Return a number linearly interpolated between the first two inputs, based on the third input. Uses the formula [code]a + (a - b) * t[/code]. + </constant> + <constant name="MATH_INVERSE_LERP" value="27"> + </constant> + <constant name="MATH_RANGE_LERP" value="28"> + </constant> + <constant name="MATH_DECTIME" value="29"> + Return the result of 'value' decreased by 'step' * 'amount'. + </constant> + <constant name="MATH_RANDOMIZE" value="30"> + Randomize the seed (or the internal state) of the random number generator. Current implementation reseeds using a number based on time. + </constant> + <constant name="MATH_RAND" value="31"> + Return a random 32 bits integer value. To obtain a random value between 0 to N (where N is smaller than 2^32 - 1), you can use it with the remainder function. + </constant> + <constant name="MATH_RANDF" value="32"> + Return a random floating-point value between 0 and 1. To obtain a random value between 0 to N, you can use it with multiplication. + </constant> + <constant name="MATH_RANDOM" value="33"> + Return a random floating-point value between the two inputs. + </constant> + <constant name="MATH_SEED" value="34"> + Set the seed for the random number generator. + </constant> + <constant name="MATH_RANDSEED" value="35"> + Return a random value from the given seed, along with the new seed. + </constant> + <constant name="MATH_DEG2RAD" value="36"> + Convert the input from degrees to radians. + </constant> + <constant name="MATH_RAD2DEG" value="37"> + Convert the input from radians to degrees. + </constant> + <constant name="MATH_LINEAR2DB" value="38"> + Convert the input from linear volume to decibel volume. + </constant> + <constant name="MATH_DB2LINEAR" value="39"> + Convert the input from decibel volume to linear volume. + </constant> + <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_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="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="45"> + Return the lesser of the two numbers, also known as their minimum. + </constant> + <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="46"> + Return the nearest power of 2 to the input. + </constant> + <constant name="OBJ_WEAKREF" value="47"> + Create a [WeakRef] from the input. + </constant> + <constant name="FUNC_FUNCREF" value="48"> + Create a [FuncRef] from the input. + </constant> + <constant name="TYPE_CONVERT" value="49"> + Convert between types. + </constant> + <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="51"> + Checks if a type is registered in the [ClassDB]. + </constant> + <constant name="TEXT_CHAR" value="52"> + Return a character with the given ascii value. + </constant> + <constant name="TEXT_STR" value="53"> + Convert the input to a string. + </constant> + <constant name="TEXT_PRINT" value="54"> + Print the given string to the output window. + </constant> + <constant name="TEXT_PRINTERR" value="55"> + Print the given string to the standard error output. + </constant> + <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="57"> + Serialize a [Variant] to a string. + </constant> + <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="59"> + Serialize a [Variant] to a [PoolByteArray]. + </constant> + <constant name="BYTES_TO_VAR" value="60"> + Deserialize a [Variant] from a [PoolByteArray] serialized using [VAR_TO_BYTES]. + </constant> + <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="62"> + The maximum value the [member function] property can have. + </constant> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptClassConstant.xml b/modules/visual_script/doc_classes/VisualScriptClassConstant.xml new file mode 100644 index 0000000000..e6498e92ad --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptClassConstant.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptClassConstant" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Gets a constant from a given class. + </brief_description> + <description> + This node returns a constant from a given class, such as [@GlobalScope.TYPE_INT]. See the given class' documentation for available constants. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data (variant): [code]value[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_base_type"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_class_constant"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_base_type"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_class_constant"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="base_type" type="String" setter="set_base_type" getter="get_base_type"> + The constant's parent class. + </member> + <member name="constant" type="String" setter="set_class_constant" getter="get_class_constant"> + The constant to return. See the given class for its available constants. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptComment.xml b/modules/visual_script/doc_classes/VisualScriptComment.xml new file mode 100644 index 0000000000..ea4545f8ef --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptComment.xml @@ -0,0 +1,71 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptComment" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + A Visual Script node used to annotate the script. + </brief_description> + <description> + A Visual Script node used to display annotations in the script, so that code may be documented. + Comment nodes can be resized so they encompass a group of nodes. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_description" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_size" qualifiers="const"> + <return type="Vector2"> + </return> + <description> + </description> + </method> + <method name="get_title" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_description"> + <return type="void"> + </return> + <argument index="0" name="description" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_size"> + <return type="void"> + </return> + <argument index="0" name="size" type="Vector2"> + </argument> + <description> + </description> + </method> + <method name="set_title"> + <return type="void"> + </return> + <argument index="0" name="title" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="description" type="String" setter="set_description" getter="get_description"> + The text inside the comment node. + </member> + <member name="size" type="Vector2" setter="set_size" getter="get_size"> + The comment node's size (in pixels). + </member> + <member name="title" type="String" setter="set_title" getter="get_title"> + The comment node's title. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptCondition.xml b/modules/visual_script/doc_classes/VisualScriptCondition.xml new file mode 100644 index 0000000000..2a30c604a5 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptCondition.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptCondition" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + A Visual Script node which branches the flow. + </brief_description> + <description> + A Visual Script node that checks a [bool] input port. If [code]true[/code] it will exit via the “true” sequence port. If [code]false[/code] it will exit via the "false" sequence port. After exiting either, it exits via the “done” port. Sequence ports may be left disconnected. + [b]Input Ports:[/b] + - Sequence: [code]if (cond) is[/code] + - Data (boolean): [code]cond[/code] + [b]Output Ports:[/b] + - Sequence: [code]true[/code] + - Sequence: [code]false[/code] + - Sequence: [code]done[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptConstant.xml b/modules/visual_script/doc_classes/VisualScriptConstant.xml new file mode 100644 index 0000000000..51c6d19238 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptConstant.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptConstant" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Gets a contant's value. + </brief_description> + <description> + This node returns a constant's value. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data (variant): [code]get[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_constant_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="get_constant_value" qualifiers="const"> + <return type="Variant"> + </return> + <description> + </description> + </method> + <method name="set_constant_type"> + <return type="void"> + </return> + <argument index="0" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + <method name="set_constant_value"> + <return type="void"> + </return> + <argument index="0" name="value" type="Variant"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="type" type="int" setter="set_constant_type" getter="get_constant_type" enum="Variant.Type"> + The constant's type. + </member> + <member name="value" type="Variant" setter="set_constant_value" getter="get_constant_value"> + The constant's value. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptConstructor.xml b/modules/visual_script/doc_classes/VisualScriptConstructor.xml new file mode 100644 index 0000000000..91df52e893 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptConstructor.xml @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptConstructor" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + A Visual Script node which calls a base type constructor. + </brief_description> + <description> + A Visual Script node which calls a base type constructor. It can be used for type conversion as well. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_constructor" qualifiers="const"> + <return type="Dictionary"> + </return> + <description> + </description> + </method> + <method name="get_constructor_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="set_constructor"> + <return type="void"> + </return> + <argument index="0" name="constructor" type="Dictionary"> + </argument> + <description> + </description> + </method> + <method name="set_constructor_type"> + <return type="void"> + </return> + <argument index="0" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="constructor" type="Dictionary" setter="set_constructor" getter="get_constructor"> + The constructor function's method info. Has roughly the following structure: + [codeblock] + { + name = "string", + args = [{ + name = "string" + class_name = "string" + type = TYPE_* + hint = PROPERTY_HINT_* + hint_string = "string" + }] + default_args = [] # Array of variants + flags = METHOD_FLAG_* + id = 0 + return = {type = TYPE_*} + } + [/codeblock] + </member> + <member name="type" type="int" setter="set_constructor_type" getter="get_constructor_type" enum="Variant.Type"> + The type to be constructed. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptCustomNode.xml b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml new file mode 100644 index 0000000000..38c325cfb7 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptCustomNode.xml @@ -0,0 +1,165 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptCustomNode" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + A scripted Visual Script node. + </brief_description> + <description> + A custom Visual Script node which can be scripted in powerful ways. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="_get_caption" qualifiers="virtual"> + <return type="String"> + </return> + <description> + Return the node's title. + </description> + </method> + <method name="_get_category" qualifiers="virtual"> + <return type="String"> + </return> + <description> + Return the node's category. + </description> + </method> + <method name="_get_input_value_port_count" qualifiers="virtual"> + <return type="int"> + </return> + <description> + Return the count of input value ports. + </description> + </method> + <method name="_get_input_value_port_name" qualifiers="virtual"> + <return type="String"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified input port's name. + </description> + </method> + <method name="_get_input_value_port_type" qualifiers="virtual"> + <return type="int"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified input port's type. See the TYPE_* enum in [@GlobalScope]. + </description> + </method> + <method name="_get_output_sequence_port_count" qualifiers="virtual"> + <return type="int"> + </return> + <description> + Return the amount of output [b]sequence[/b] ports. + </description> + </method> + <method name="_get_output_sequence_port_text" qualifiers="virtual"> + <return type="String"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified [b]sequence[/b] output's name. + </description> + </method> + <method name="_get_output_value_port_count" qualifiers="virtual"> + <return type="int"> + </return> + <description> + Return the amount of output value ports. + </description> + </method> + <method name="_get_output_value_port_name" qualifiers="virtual"> + <return type="String"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified output's name. + </description> + </method> + <method name="_get_output_value_port_type" qualifiers="virtual"> + <return type="int"> + </return> + <argument index="0" name="idx" type="int"> + </argument> + <description> + Return the specified output's type. See the TYPE_* enum in [@GlobalScope]. + </description> + </method> + <method name="_get_text" qualifiers="virtual"> + <return type="String"> + </return> + <description> + Return the custom node's text, which is shown right next to the input [b]sequence[/b] port (if there is none, on the place that is usually taken by it). + </description> + </method> + <method name="_get_working_memory_size" qualifiers="virtual"> + <return type="int"> + </return> + <description> + Return the size of the custom node's working memory. See [method _step] for more details. + </description> + </method> + <method name="_has_input_sequence_port" qualifiers="virtual"> + <return type="bool"> + </return> + <description> + Return whether the custom node has an input [b]sequence[/b] port. + </description> + </method> + <method name="_step" qualifiers="virtual"> + <return type="Variant"> + </return> + <argument index="0" name="inputs" type="Array"> + </argument> + <argument index="1" name="outputs" type="Array"> + </argument> + <argument index="2" name="start_mode" type="int"> + </argument> + <argument index="3" name="working_mem" type="Array"> + </argument> + <description> + Execute the custom node's logic, returning the index of the output sequence port to use or a [String] when there is an error. + + The [code]inputs[/code] array contains the values of the input ports. + [code]outputs[/code] is an array whose indices should be set to the respective outputs. + The [code]start_mode[/code] is usually [code]START_MODE_BEGIN_SEQUENCE[/code], unless you have used the STEP_* constants. + [code]working_mem[/code] is an array which can be used to persist information between runs of the custom node. + + When returning, you can mask the returned value with one of the STEP_* constants. + </description> + </method> + </methods> + <constants> + <constant name="START_MODE_BEGIN_SEQUENCE" value="0"> + The start mode used the first time when [method _step] is called. + </constant> + <constant name="START_MODE_CONTINUE_SEQUENCE" value="1"> + The start mode used when [method _step] is called after coming back from a STEP_PUSH_STACK_BIT. + </constant> + <constant name="START_MODE_RESUME_YIELD" value="2"> + The start mode used when [method _step] is called after resuming from STEP_YIELD_BIT. + </constant> + <constant name="STEP_PUSH_STACK_BIT" value="16777216" enum=""> + Hint used by [method _step] to tell that control should return to it when there is no other node left to execute. + This is used by [VisualScriptCondition] to redirect the sequence to the "Done" port after the true/false branch has finished execution. + </constant> + <constant name="STEP_GO_BACK_BIT" value="33554432" enum=""> + Hint used by [method _step] to tell that control should return back, either hitting a previous STEP_PUSH_STACK_BIT or exiting the function. + </constant> + <constant name="STEP_NO_ADVANCE_BIT" value="67108864" enum=""> + </constant> + <constant name="STEP_EXIT_FUNCTION_BIT" value="134217728" enum=""> + Hint used by [method _step] to tell that control should stop and exit the function. + </constant> + <constant name="STEP_YIELD_BIT" value="268435456" enum=""> + Hint used by [method _step] to tell that the function should be yielded. + Using this requires you to have at least one working memory slot, which is used for the [VisualScriptFunctionState]. + </constant> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml b/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml new file mode 100644 index 0000000000..cbed3ba22c --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptDeconstruct.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptDeconstruct" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + A Visual Script node which deconstructs a base type instance into its parts. + </brief_description> + <description> + A Visual Script node which deconstructs a base type instance into its parts. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_deconstruct_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="set_deconstruct_type"> + <return type="void"> + </return> + <argument index="0" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="elem_cache" type="Array" setter="_set_elem_cache" getter="_get_elem_cache"> + </member> + <member name="type" type="int" setter="set_deconstruct_type" getter="get_deconstruct_type" enum="Variant.Type"> + The type to deconstruct. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptEditor.xml b/modules/visual_script/doc_classes/VisualScriptEditor.xml new file mode 100644 index 0000000000..70d52b2bd7 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptEditor.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptEditor" inherits="Object" category="Core" version="3.0.alpha.custom_build"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="add_custom_node"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="category" type="String"> + </argument> + <argument index="2" name="script" type="Script"> + </argument> + <description> + Add a custom Visual Script node to the editor. It'll be placed under "Custom Nodes" with the [code]category[/code] as the parameter. + </description> + </method> + <method name="remove_custom_node"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <argument index="1" name="category" type="String"> + </argument> + <description> + Remove a custom Visual Script node from the editor. Custom nodes already placed on scripts won't be removed. + </description> + </method> + </methods> + <signals> + <signal name="custom_nodes_updated"> + <description> + Emitted when a custom Visual Script node is added or removed. + </description> + </signal> + </signals> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml b/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml new file mode 100644 index 0000000000..669276f0d0 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptEmitSignal.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptEmitSignal" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Emits a specified signal. + </brief_description> + <description> + Emits a specified signal when it is executed. + [b]Input Ports:[/b] + - Sequence: [code]emit[/code] + [b]Output Ports:[/b] + - Sequence + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_signal" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_signal"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="signal" type="String" setter="set_signal" getter="get_signal"> + The signal to emit. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml b/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml new file mode 100644 index 0000000000..6703ff4eda --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptEngineSingleton.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptEngineSingleton" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + A Visual Script node returning a singleton from [@GlobalScope] + </brief_description> + <description> + A Visual Script node returning a singleton from [@GlobalScope] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_singleton"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_singleton"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="constant" type="String" setter="set_singleton" getter="get_singleton"> + The singleton's name. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptExpression.xml b/modules/visual_script/doc_classes/VisualScriptExpression.xml new file mode 100644 index 0000000000..fb3b6ef19d --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptExpression.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptExpression" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptFunction.xml b/modules/visual_script/doc_classes/VisualScriptFunction.xml new file mode 100644 index 0000000000..d77169679b --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptFunction.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptFunction" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml new file mode 100644 index 0000000000..7a0a7c9f55 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptFunctionCall.xml @@ -0,0 +1,199 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptFunctionCall" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_base_path" qualifiers="const"> + <return type="NodePath"> + </return> + <description> + </description> + </method> + <method name="get_base_script" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_base_type" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_basic_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="get_call_mode" qualifiers="const"> + <return type="int" enum="VisualScriptFunctionCall.CallMode"> + </return> + <description> + </description> + </method> + <method name="get_function" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_rpc_call_mode" qualifiers="const"> + <return type="int" enum="VisualScriptFunctionCall.RPCCallMode"> + </return> + <description> + </description> + </method> + <method name="get_singleton" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_use_default_args" qualifiers="const"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="get_validate" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="set_base_path"> + <return type="void"> + </return> + <argument index="0" name="base_path" type="NodePath"> + </argument> + <description> + </description> + </method> + <method name="set_base_script"> + <return type="void"> + </return> + <argument index="0" name="base_script" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_base_type"> + <return type="void"> + </return> + <argument index="0" name="base_type" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_basic_type"> + <return type="void"> + </return> + <argument index="0" name="basic_type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + <method name="set_call_mode"> + <return type="void"> + </return> + <argument index="0" name="mode" type="int" enum="VisualScriptFunctionCall.CallMode"> + </argument> + <description> + </description> + </method> + <method name="set_function"> + <return type="void"> + </return> + <argument index="0" name="function" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_rpc_call_mode"> + <return type="void"> + </return> + <argument index="0" name="mode" type="int" enum="VisualScriptFunctionCall.RPCCallMode"> + </argument> + <description> + </description> + </method> + <method name="set_singleton"> + <return type="void"> + </return> + <argument index="0" name="singleton" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_use_default_args"> + <return type="void"> + </return> + <argument index="0" name="amount" type="int"> + </argument> + <description> + </description> + </method> + <method name="set_validate"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="argument_cache" type="Dictionary" setter="_set_argument_cache" getter="_get_argument_cache"> + </member> + <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> + </member> + <member name="base_type" type="String" setter="set_base_type" getter="get_base_type"> + </member> + <member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type"> + </member> + <member name="call_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptFunctionCall.CallMode"> + </member> + <member name="function" type="String" setter="set_function" getter="get_function"> + </member> + <member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path"> + </member> + <member name="rpc_call_mode" type="int" setter="set_rpc_call_mode" getter="get_rpc_call_mode" enum="VisualScriptFunctionCall.RPCCallMode"> + </member> + <member name="singleton" type="String" setter="set_singleton" getter="get_singleton"> + </member> + <member name="use_default_args" type="int" setter="set_use_default_args" getter="get_use_default_args"> + </member> + <member name="validate" type="bool" setter="set_validate" getter="get_validate"> + </member> + </members> + <constants> + <constant name="CALL_MODE_SELF" value="0"> + </constant> + <constant name="CALL_MODE_NODE_PATH" value="1"> + </constant> + <constant name="CALL_MODE_INSTANCE" value="2"> + </constant> + <constant name="CALL_MODE_BASIC_TYPE" value="3"> + </constant> + <constant name="CALL_MODE_SINGLETON" value="4"> + </constant> + <constant name="RPC_DISABLED" value="0"> + </constant> + <constant name="RPC_RELIABLE" value="1"> + </constant> + <constant name="RPC_UNRELIABLE" value="2"> + </constant> + <constant name="RPC_RELIABLE_TO_ID" value="3"> + </constant> + <constant name="RPC_UNRELIABLE_TO_ID" value="4"> + </constant> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptFunctionState.xml b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml new file mode 100644 index 0000000000..9b30f62236 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptFunctionState.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptFunctionState" inherits="Reference" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="connect_to_signal"> + <return type="void"> + </return> + <argument index="0" name="obj" type="Object"> + </argument> + <argument index="1" name="signals" type="String"> + </argument> + <argument index="2" name="args" type="Array"> + </argument> + <description> + </description> + </method> + <method name="is_valid" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="resume"> + <return type="Variant"> + </return> + <argument index="0" name="args" type="Array" default="null"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml new file mode 100644 index 0000000000..961244fe88 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptGlobalConstant.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptGlobalConstant" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_global_constant"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="set_global_constant"> + <return type="void"> + </return> + <argument index="0" name="index" type="int"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="constant" type="int" setter="set_global_constant" getter="get_global_constant"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptIndexGet.xml b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml new file mode 100644 index 0000000000..c5229f7678 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptIndexGet.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptIndexGet" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptIndexSet.xml b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml new file mode 100644 index 0000000000..27646b4a5f --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptIndexSet.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptIndexSet" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptInputAction.xml b/modules/visual_script/doc_classes/VisualScriptInputAction.xml new file mode 100644 index 0000000000..7f6d13264e --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptInputAction.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptInputAction" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_action_mode" qualifiers="const"> + <return type="int" enum="VisualScriptInputAction.Mode"> + </return> + <description> + </description> + </method> + <method name="get_action_name" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_action_mode"> + <return type="void"> + </return> + <argument index="0" name="mode" type="int" enum="VisualScriptInputAction.Mode"> + </argument> + <description> + </description> + </method> + <method name="set_action_name"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="action" type="String" setter="set_action_name" getter="get_action_name"> + </member> + <member name="mode" type="int" setter="set_action_mode" getter="get_action_mode" enum="VisualScriptInputAction.Mode"> + </member> + </members> + <constants> + <constant name="MODE_PRESSED" value="0"> + </constant> + <constant name="MODE_RELEASED" value="1"> + </constant> + <constant name="MODE_JUST_PRESSED" value="2"> + </constant> + <constant name="MODE_JUST_RELEASED" value="3"> + </constant> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptIterator.xml b/modules/visual_script/doc_classes/VisualScriptIterator.xml new file mode 100644 index 0000000000..fc905d6c39 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptIterator.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptIterator" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Steps through items in a given input. + </brief_description> + <description> + This node steps through each item in a given input. Input can be any sequence data type, such as an [Array] or [String]. When each item has been processed, execution passed out the [code]exit[/code] Sequence port. + [b]Input Ports:[/b] + - Sequence: [code]for (elem) in (input)[/code] + - Data (variant): [code]input[/code] + [b]Output Ports:[/b] + - Sequence: [code]each[/code] + - Sequence: [code]exit[/code] + - Data (variant): [code]elem[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptLocalVar.xml b/modules/visual_script/doc_classes/VisualScriptLocalVar.xml new file mode 100644 index 0000000000..ff77dfac0d --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptLocalVar.xml @@ -0,0 +1,57 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptLocalVar" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Gets a local variable's value. + </brief_description> + <description> + Returns a local variable's value. "Var Name" must be supplied, with an optional type. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data (variant): [code]get[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_var_name" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_var_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="set_var_name"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_var_type"> + <return type="void"> + </return> + <argument index="0" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="type" type="int" setter="set_var_type" getter="get_var_type" enum="Variant.Type"> + The local variable's type. + </member> + <member name="var_name" type="String" setter="set_var_name" getter="get_var_name"> + The local variable's name. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml b/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml new file mode 100644 index 0000000000..07b01d4576 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptLocalVarSet.xml @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptLocalVarSet" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Changes a local variable's value. + </brief_description> + <description> + Changes a local variable's value to the given input. The new value is also provided on an output Data port. + [b]Input Ports:[/b] + - Sequence + - Data (variant): [code]set[/code] + [b]Output Ports:[/b] + - Sequence + - Data (variant): [code]get[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_var_name" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_var_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="set_var_name"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_var_type"> + <return type="void"> + </return> + <argument index="0" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="type" type="int" setter="set_var_type" getter="get_var_type" enum="Variant.Type"> + The local variable's type. + </member> + <member name="var_name" type="String" setter="set_var_name" getter="get_var_name"> + The local variable's name. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptMathConstant.xml b/modules/visual_script/doc_classes/VisualScriptMathConstant.xml new file mode 100644 index 0000000000..817bcb5ce2 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptMathConstant.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptMathConstant" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Commonly used mathematical constants. + </brief_description> + <description> + Provides common math constants, such as Pi or Euler's constant, on an output Data port. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data (variant): [code]get[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_math_constant"> + <return type="int" enum="VisualScriptMathConstant.MathConstant"> + </return> + <description> + </description> + </method> + <method name="set_math_constant"> + <return type="void"> + </return> + <argument index="0" name="which" type="int" enum="VisualScriptMathConstant.MathConstant"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="constant" type="int" setter="set_math_constant" getter="get_math_constant" enum="VisualScriptMathConstant.MathConstant"> + The math constant. + </member> + </members> + <constants> + <constant name="MATH_CONSTANT_ONE" value="0"> + Unity: [code]1[/code] + </constant> + <constant name="MATH_CONSTANT_PI" value="1"> + Pi: [code]3.141593[/code] + </constant> + <constant name="MATH_CONSTANT_HALF_PI" value="2"> + Pi divided by two: [code]1.570796[/code] + </constant> + <constant name="MATH_CONSTANT_TAU" value="3"> + Tau: [code]6.283185[/code] + </constant> + <constant name="MATH_CONSTANT_E" value="4"> + Natural log: [code]2.718282[/code] + </constant> + <constant name="MATH_CONSTANT_SQRT2" value="5"> + Square root of two: [code]1.414214[/code] + </constant> + <constant name="MATH_CONSTANT_INF" value="6"> + Infinity: [code]inf[/code] + </constant> + <constant name="MATH_CONSTANT_NAN" value="7"> + Not a number: [code]nan[/code] + </constant> + <constant name="MATH_CONSTANT_MAX" value="8"> + </constant> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptNode.xml b/modules/visual_script/doc_classes/VisualScriptNode.xml new file mode 100644 index 0000000000..f6f2867172 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptNode.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptNode" inherits="Resource" category="Core" version="3.0-alpha"> + <brief_description> + A node which is part of a [VisualScript]. + </brief_description> + <description> + A node which is part of a [VisualScript]. Not to be confused with [Node], which is a part of a [SceneTree]. + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_default_input_value" qualifiers="const"> + <return type="Variant"> + </return> + <argument index="0" name="port_idx" type="int"> + </argument> + <description> + Returns the default value of a given port. The default value is used when nothing is connected to the port. + </description> + </method> + <method name="get_visual_script" qualifiers="const"> + <return type="VisualScript"> + </return> + <description> + Returns the [VisualScript] instance the node is bound to. + </description> + </method> + <method name="ports_changed_notify"> + <return type="void"> + </return> + <description> + Notify that the node's ports have changed. Usually used in conjunction with [VisualScriptCustomNode] . + </description> + </method> + <method name="set_default_input_value"> + <return type="void"> + </return> + <argument index="0" name="port_idx" type="int"> + </argument> + <argument index="1" name="value" type="Variant"> + </argument> + <description> + Change the default value of a given port. + </description> + </method> + </methods> + <members> + <member name="_default_input_values" type="Array" setter="_set_default_input_values" getter="_get_default_input_values"> + </member> + </members> + <signals> + <signal name="ports_changed"> + <description> + Emitted when the available input/output ports are changed. + </description> + </signal> + </signals> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptOperator.xml b/modules/visual_script/doc_classes/VisualScriptOperator.xml new file mode 100644 index 0000000000..bf4032c09c --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptOperator.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptOperator" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + [b]Input Ports:[/b] + - Data (variant): [code]A[/code] + - Data (variant): [code]B[/code] + [b]Output Ports:[/b] + - Data (variant): [code]result[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_operator" qualifiers="const"> + <return type="int" enum="Variant.Operator"> + </return> + <description> + </description> + </method> + <method name="get_typed" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="set_operator"> + <return type="void"> + </return> + <argument index="0" name="op" type="int" enum="Variant.Operator"> + </argument> + <description> + </description> + </method> + <method name="set_typed"> + <return type="void"> + </return> + <argument index="0" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="operator" type="int" setter="set_operator" getter="get_operator" enum="Variant.Operator"> + </member> + <member name="type" type="int" setter="set_typed" getter="get_typed" enum="Variant.Type"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptPreload.xml b/modules/visual_script/doc_classes/VisualScriptPreload.xml new file mode 100644 index 0000000000..4a71e23809 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptPreload.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptPreload" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Creates a new [Resource] or loads one from the filesystem. + </brief_description> + <description> + Creates a new [Resource] or loads one from the filesystem. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data (object): [code]res[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_preload" qualifiers="const"> + <return type="Resource"> + </return> + <description> + </description> + </method> + <method name="set_preload"> + <return type="void"> + </return> + <argument index="0" name="resource" type="Resource"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="resource" type="Resource" setter="set_preload" getter="get_preload"> + The [Resource] to load. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml new file mode 100644 index 0000000000..eb5c52f4be --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptPropertyGet.xml @@ -0,0 +1,137 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptPropertyGet" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_base_path" qualifiers="const"> + <return type="NodePath"> + </return> + <description> + </description> + </method> + <method name="get_base_script" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_base_type" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_basic_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="get_call_mode" qualifiers="const"> + <return type="int" enum="VisualScriptPropertyGet.CallMode"> + </return> + <description> + </description> + </method> + <method name="get_index" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_property" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_base_path"> + <return type="void"> + </return> + <argument index="0" name="base_path" type="NodePath"> + </argument> + <description> + </description> + </method> + <method name="set_base_script"> + <return type="void"> + </return> + <argument index="0" name="base_script" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_base_type"> + <return type="void"> + </return> + <argument index="0" name="base_type" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_basic_type"> + <return type="void"> + </return> + <argument index="0" name="basic_type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + <method name="set_call_mode"> + <return type="void"> + </return> + <argument index="0" name="mode" type="int" enum="VisualScriptPropertyGet.CallMode"> + </argument> + <description> + </description> + </method> + <method name="set_index"> + <return type="void"> + </return> + <argument index="0" name="index" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_property"> + <return type="void"> + </return> + <argument index="0" name="property" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> + </member> + <member name="base_type" type="String" setter="set_base_type" getter="get_base_type"> + </member> + <member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type"> + </member> + <member name="index" type="String" setter="set_index" getter="get_index"> + </member> + <member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path"> + </member> + <member name="property" type="String" setter="set_property" getter="get_property"> + </member> + <member name="set_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptPropertyGet.CallMode"> + </member> + <member name="type_cache" type="int" setter="_set_type_cache" getter="_get_type_cache" enum="Variant.Type"> + </member> + </members> + <constants> + <constant name="CALL_MODE_SELF" value="0"> + </constant> + <constant name="CALL_MODE_NODE_PATH" value="1"> + </constant> + <constant name="CALL_MODE_INSTANCE" value="2"> + </constant> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptPropertySet.xml b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml new file mode 100644 index 0000000000..794caa2518 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptPropertySet.xml @@ -0,0 +1,177 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptPropertySet" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_assign_op" qualifiers="const"> + <return type="int" enum="VisualScriptPropertySet.AssignOp"> + </return> + <description> + </description> + </method> + <method name="get_base_path" qualifiers="const"> + <return type="NodePath"> + </return> + <description> + </description> + </method> + <method name="get_base_script" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_base_type" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_basic_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="get_call_mode" qualifiers="const"> + <return type="int" enum="VisualScriptPropertySet.CallMode"> + </return> + <description> + </description> + </method> + <method name="get_index" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_property" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_assign_op"> + <return type="void"> + </return> + <argument index="0" name="assign_op" type="int" enum="VisualScriptPropertySet.AssignOp"> + </argument> + <description> + </description> + </method> + <method name="set_base_path"> + <return type="void"> + </return> + <argument index="0" name="base_path" type="NodePath"> + </argument> + <description> + </description> + </method> + <method name="set_base_script"> + <return type="void"> + </return> + <argument index="0" name="base_script" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_base_type"> + <return type="void"> + </return> + <argument index="0" name="base_type" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_basic_type"> + <return type="void"> + </return> + <argument index="0" name="basic_type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + <method name="set_call_mode"> + <return type="void"> + </return> + <argument index="0" name="mode" type="int" enum="VisualScriptPropertySet.CallMode"> + </argument> + <description> + </description> + </method> + <method name="set_index"> + <return type="void"> + </return> + <argument index="0" name="index" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_property"> + <return type="void"> + </return> + <argument index="0" name="property" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="assign_op" type="int" setter="set_assign_op" getter="get_assign_op" enum="VisualScriptPropertySet.AssignOp"> + </member> + <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> + </member> + <member name="base_type" type="String" setter="set_base_type" getter="get_base_type"> + </member> + <member name="basic_type" type="int" setter="set_basic_type" getter="get_basic_type" enum="Variant.Type"> + </member> + <member name="index" type="String" setter="set_index" getter="get_index"> + </member> + <member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path"> + </member> + <member name="property" type="String" setter="set_property" getter="get_property"> + </member> + <member name="set_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptPropertySet.CallMode"> + </member> + <member name="type_cache" type="Dictionary" setter="_set_type_cache" getter="_get_type_cache"> + </member> + </members> + <constants> + <constant name="CALL_MODE_SELF" value="0"> + </constant> + <constant name="CALL_MODE_NODE_PATH" value="1"> + </constant> + <constant name="CALL_MODE_INSTANCE" value="2"> + </constant> + <constant name="CALL_MODE_BASIC_TYPE" value="3"> + </constant> + <constant name="ASSIGN_OP_NONE" value="0"> + </constant> + <constant name="ASSIGN_OP_ADD" value="1"> + </constant> + <constant name="ASSIGN_OP_SUB" value="2"> + </constant> + <constant name="ASSIGN_OP_MUL" value="3"> + </constant> + <constant name="ASSIGN_OP_DIV" value="4"> + </constant> + <constant name="ASSIGN_OP_MOD" value="5"> + </constant> + <constant name="ASSIGN_OP_SHIFT_LEFT" value="6"> + </constant> + <constant name="ASSIGN_OP_SHIFT_RIGHT" value="7"> + </constant> + <constant name="ASSIGN_OP_BIT_AND" value="8"> + </constant> + <constant name="ASSIGN_OP_BIT_OR" value="9"> + </constant> + <constant name="ASSIGN_OP_BIT_XOR" value="10"> + </constant> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptResourcePath.xml b/modules/visual_script/doc_classes/VisualScriptResourcePath.xml new file mode 100644 index 0000000000..274a852c3e --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptResourcePath.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptResourcePath" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_resource_path"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_resource_path"> + <return type="void"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="path" type="String" setter="set_resource_path" getter="get_resource_path"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptReturn.xml b/modules/visual_script/doc_classes/VisualScriptReturn.xml new file mode 100644 index 0000000000..4ac586a02c --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptReturn.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptReturn" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Exits a function and returns an optional value. + </brief_description> + <description> + Ends the execution of a function and returns control to the calling function. Optionally, it can return a [Variant] value. + [b]Input Ports:[/b] + - Sequence + - Data (variant): [code]result[/code] (optional) + [b]Output Ports:[/b] + none + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_return_type" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="is_return_value_enabled" qualifiers="const"> + <return type="bool"> + </return> + <description> + </description> + </method> + <method name="set_enable_return_value"> + <return type="void"> + </return> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + </description> + </method> + <method name="set_return_type"> + <return type="void"> + </return> + <argument index="0" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="return_enabled" type="bool" setter="set_enable_return_value" getter="is_return_value_enabled"> + If [code]true[/code] the [code]return[/code] input port is available. + </member> + <member name="return_type" type="int" setter="set_return_type" getter="get_return_type" enum="Variant.Type"> + The return value's data type. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptSceneNode.xml b/modules/visual_script/doc_classes/VisualScriptSceneNode.xml new file mode 100644 index 0000000000..e8fdb69c6a --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptSceneNode.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptSceneNode" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Node reference. + </brief_description> + <description> + A direct reference to a node. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data: [code]node[/code] (obj) + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_node_path"> + <return type="NodePath"> + </return> + <description> + </description> + </method> + <method name="set_node_path"> + <return type="void"> + </return> + <argument index="0" name="path" type="NodePath"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="node_path" type="NodePath" setter="set_node_path" getter="get_node_path"> + The node's path in the scene tree. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptSceneTree.xml b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml new file mode 100644 index 0000000000..e74c330623 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptSceneTree.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptSceneTree" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptSelect.xml b/modules/visual_script/doc_classes/VisualScriptSelect.xml new file mode 100644 index 0000000000..6a62e364f3 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptSelect.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptSelect" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Chooses between two input values. + </brief_description> + <description> + Chooses between two input values based on a Boolean condition. + [b]Input Ports:[/b] + - Data (boolean): [code]cond[/code] + - Data (variant): [code]a[/code] + - Data (variant): [code]b[/code] + [b]Output Ports:[/b] + - Data (variant): [code]out[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_typed" qualifiers="const"> + <return type="int" enum="Variant.Type"> + </return> + <description> + </description> + </method> + <method name="set_typed"> + <return type="void"> + </return> + <argument index="0" name="type" type="int" enum="Variant.Type"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="type" type="int" setter="set_typed" getter="get_typed" enum="Variant.Type"> + The input variables' type. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptSelf.xml b/modules/visual_script/doc_classes/VisualScriptSelf.xml new file mode 100644 index 0000000000..f39a02bf84 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptSelf.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptSelf" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Outputs a reference to the current instance. + </brief_description> + <description> + Provides a reference to the node running the visual script. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data (object): [code]instance[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptSequence.xml b/modules/visual_script/doc_classes/VisualScriptSequence.xml new file mode 100644 index 0000000000..51238070d5 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptSequence.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptSequence" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Executes a series of Sequence ports. + </brief_description> + <description> + Steps through a series of one or more output Sequence ports. The [code]current[/code] data port outputs the currently executing item. + [b]Input Ports:[/b] + - Sequence: [code]in order[/code] + [b]Output Ports:[/b] + - Sequence: [code]1[/code] + - Sequence: [code]2 - n[/code] (optional) + - Data (int): [code]current[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_steps" qualifiers="const"> + <return type="int"> + </return> + <description> + </description> + </method> + <method name="set_steps"> + <return type="void"> + </return> + <argument index="0" name="steps" type="int"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="steps" type="int" setter="set_steps" getter="get_steps"> + The number of steps in the sequence. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptSubCall.xml b/modules/visual_script/doc_classes/VisualScriptSubCall.xml new file mode 100644 index 0000000000..381095f49b --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptSubCall.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptSubCall" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="_subcall" qualifiers="virtual"> + <return type="Variant"> + </return> + <argument index="0" name="arguments" type="Variant"> + </argument> + <description> + </description> + </method> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptSwitch.xml b/modules/visual_script/doc_classes/VisualScriptSwitch.xml new file mode 100644 index 0000000000..3c8a79f686 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptSwitch.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptSwitch" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Branches program flow based on a given input's value. + </brief_description> + <description> + Branches the flow based on an input's value. Use "Case Count" in the Inspector to set the number of branches and each comparison's optional type. + [b]Input Ports:[/b] + - Sequence: [code]'input' is[/code] + - Data (variant): [code]=[/code] + - Data (variant): [code]=[/code] (optional) + - Data (variant): [code]input[/code] + [b]Output Ports:[/b] + - Sequence + - Sequence (optional) + - Sequence: [code]done[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptTypeCast.xml b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml new file mode 100644 index 0000000000..417c0a5159 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptTypeCast.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptTypeCast" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_base_script" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_base_type" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_base_script"> + <return type="void"> + </return> + <argument index="0" name="path" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_base_type"> + <return type="void"> + </return> + <argument index="0" name="type" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="base_script" type="String" setter="set_base_script" getter="get_base_script"> + </member> + <member name="base_type" type="String" setter="set_base_type" getter="get_base_type"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptVariableGet.xml b/modules/visual_script/doc_classes/VisualScriptVariableGet.xml new file mode 100644 index 0000000000..1cad4480a6 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptVariableGet.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptVariableGet" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Gets a variable's value. + </brief_description> + <description> + Returns a variable's value. "Var Name" must be supplied, with an optional type. + [b]Input Ports:[/b] + none + [b]Output Ports:[/b] + - Data (variant): [code]value[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_variable" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_variable"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="var_name" type="String" setter="set_variable" getter="get_variable"> + The variable's name. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptVariableSet.xml b/modules/visual_script/doc_classes/VisualScriptVariableSet.xml new file mode 100644 index 0000000000..fa3befa21d --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptVariableSet.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptVariableSet" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Changes a variable's value. + </brief_description> + <description> + Changes a variable's value to the given input. + [b]Input Ports:[/b] + - Sequence + - Data (variant): [code]set[/code] + [b]Output Ports:[/b] + - Sequence + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_variable" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_variable"> + <return type="void"> + </return> + <argument index="0" name="name" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="var_name" type="String" setter="set_variable" getter="get_variable"> + The variable's name. + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptWhile.xml b/modules/visual_script/doc_classes/VisualScriptWhile.xml new file mode 100644 index 0000000000..f948660997 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptWhile.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptWhile" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + Conditional loop. + </brief_description> + <description> + Loops while a condition is [code]true[/code]. Execution continues out the [code]exit[/code] Sequence port when the loop terminates. + [b]Input Ports:[/b] + - Sequence: [code]while(cond)[/code] + - Data (bool): [code]cond[/code] + [b]Output Ports:[/b] + - Sequence: [code]repeat[/code] + - Sequence: [code]exit[/code] + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptYield.xml b/modules/visual_script/doc_classes/VisualScriptYield.xml new file mode 100644 index 0000000000..5474ee8b78 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptYield.xml @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptYield" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_wait_time"> + <return type="float"> + </return> + <description> + </description> + </method> + <method name="get_yield_mode"> + <return type="int" enum="VisualScriptYield.YieldMode"> + </return> + <description> + </description> + </method> + <method name="set_wait_time"> + <return type="void"> + </return> + <argument index="0" name="sec" type="float"> + </argument> + <description> + </description> + </method> + <method name="set_yield_mode"> + <return type="void"> + </return> + <argument index="0" name="mode" type="int" enum="VisualScriptYield.YieldMode"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="mode" type="int" setter="set_yield_mode" getter="get_yield_mode" enum="VisualScriptYield.YieldMode"> + </member> + <member name="wait_time" type="float" setter="set_wait_time" getter="get_wait_time"> + </member> + </members> + <constants> + <constant name="YIELD_FRAME" value="1"> + </constant> + <constant name="YIELD_PHYSICS_FRAME" value="2"> + </constant> + <constant name="YIELD_WAIT" value="3"> + </constant> + </constants> +</class> diff --git a/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml new file mode 100644 index 0000000000..a3b6982075 --- /dev/null +++ b/modules/visual_script/doc_classes/VisualScriptYieldSignal.xml @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VisualScriptYieldSignal" inherits="VisualScriptNode" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_base_path" qualifiers="const"> + <return type="NodePath"> + </return> + <description> + </description> + </method> + <method name="get_base_type" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="get_call_mode" qualifiers="const"> + <return type="int" enum="VisualScriptYieldSignal.CallMode"> + </return> + <description> + </description> + </method> + <method name="get_signal" qualifiers="const"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_base_path"> + <return type="void"> + </return> + <argument index="0" name="base_path" type="NodePath"> + </argument> + <description> + </description> + </method> + <method name="set_base_type"> + <return type="void"> + </return> + <argument index="0" name="base_type" type="String"> + </argument> + <description> + </description> + </method> + <method name="set_call_mode"> + <return type="void"> + </return> + <argument index="0" name="mode" type="int" enum="VisualScriptYieldSignal.CallMode"> + </argument> + <description> + </description> + </method> + <method name="set_signal"> + <return type="void"> + </return> + <argument index="0" name="signal" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="base_type" type="String" setter="set_base_type" getter="get_base_type"> + </member> + <member name="call_mode" type="int" setter="set_call_mode" getter="get_call_mode" enum="VisualScriptYieldSignal.CallMode"> + </member> + <member name="node_path" type="NodePath" setter="set_base_path" getter="get_base_path"> + </member> + <member name="signal" type="String" setter="set_signal" getter="get_signal"> + </member> + </members> + <constants> + <constant name="CALL_MODE_SELF" value="0"> + </constant> + <constant name="CALL_MODE_NODE_PATH" value="1"> + </constant> + <constant name="CALL_MODE_INSTANCE" value="2"> + </constant> + </constants> +</class> diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp index c50ba17c35..b6ce10381d 100644 --- a/modules/visual_script/register_types.cpp +++ b/modules/visual_script/register_types.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "register_types.h" +#include "core/engine.h" #include "io/resource_loader.h" #include "visual_script.h" #include "visual_script_builtin_funcs.h" @@ -40,6 +41,9 @@ #include "visual_script_yield_nodes.h" VisualScriptLanguage *visual_script_language = NULL; +#ifdef TOOLS_ENABLED +static _VisualScriptEditor *vs_editor_singleton = NULL; +#endif void register_visual_script_types() { @@ -107,6 +111,10 @@ void register_visual_script_types() { register_visual_script_expression_node(); #ifdef TOOLS_ENABLED + ClassDB::register_class<_VisualScriptEditor>(); + vs_editor_singleton = memnew(_VisualScriptEditor); + Engine::get_singleton()->add_singleton(Engine::Singleton("VisualScriptEditor", _VisualScriptEditor::get_singleton())); + VisualScriptEditor::register_editor(); #endif } @@ -119,6 +127,9 @@ void unregister_visual_script_types() { #ifdef TOOLS_ENABLED VisualScriptEditor::free_clipboard(); + if (vs_editor_singleton) { + memdelete(vs_editor_singleton); + } #endif if (visual_script_language) memdelete(visual_script_language); diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 765fe4c2f2..0834bc81d9 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -2644,6 +2644,11 @@ void VisualScriptLanguage::add_register_func(const String &p_name, VisualScriptN register_funcs[p_name] = p_func; } +void VisualScriptLanguage::remove_register_func(const String &p_name) { + ERR_FAIL_COND(!register_funcs.has(p_name)); + register_funcs.erase(p_name); +} + Ref<VisualScriptNode> VisualScriptLanguage::create_node_from_name(const String &p_name) { ERR_FAIL_COND_V(!register_funcs.has(p_name), Ref<VisualScriptNode>()); diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index 0f60b103c9..3e31876941 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -600,6 +600,7 @@ public: virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max); void add_register_func(const String &p_name, VisualScriptNodeRegisterFunc p_func); + void remove_register_func(const String &p_name); Ref<VisualScriptNode> create_node_from_name(const String &p_name); void get_registered_node_names(List<String> *r_names); 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 15e20effc0..2318149ca5 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "visual_script_editor.h" +#include "core/script_language.h" #include "editor/editor_node.h" #include "editor/editor_resource_preview.h" #include "os/input.h" @@ -348,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; @@ -385,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; @@ -1388,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 @@ -1397,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 @@ -1406,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 @@ -3258,6 +3259,8 @@ void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_member_rmb_selected", &VisualScriptEditor::_member_rmb_selected); ClassDB::bind_method("_member_option", &VisualScriptEditor::_member_option); + + ClassDB::bind_method("_update_available_nodes", &VisualScriptEditor::_update_available_nodes); } VisualScriptEditor::VisualScriptEditor() { @@ -3442,6 +3445,8 @@ VisualScriptEditor::VisualScriptEditor() { members->connect("item_rmb_selected", this, "_member_rmb_selected"); members->set_allow_rmb_select(true); member_popup->connect("id_pressed", this, "_member_option"); + + _VisualScriptEditor::get_singleton()->connect("custom_nodes_updated", this, "_update_available_nodes"); } VisualScriptEditor::~VisualScriptEditor() { @@ -3485,4 +3490,42 @@ void VisualScriptEditor::register_editor() { EditorNode::add_plugin_init_callback(register_editor_callback); } +Ref<VisualScriptNode> _VisualScriptEditor::create_node_custom(const String &p_name) { + + Ref<VisualScriptCustomNode> node; + node.instance(); + node->set_script(singleton->custom_nodes[p_name]); + return node; +} + +_VisualScriptEditor *_VisualScriptEditor::singleton = NULL; +Map<String, RefPtr> _VisualScriptEditor::custom_nodes; + +_VisualScriptEditor::_VisualScriptEditor() { + singleton = this; +} + +_VisualScriptEditor::~_VisualScriptEditor() { + custom_nodes.clear(); +} + +void _VisualScriptEditor::add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script) { + String node_name = "custom/" + p_category + "/" + p_name; + custom_nodes.insert(node_name, p_script.get_ref_ptr()); + VisualScriptLanguage::singleton->add_register_func(node_name, &_VisualScriptEditor::create_node_custom); + emit_signal("custom_nodes_updated"); +} + +void _VisualScriptEditor::remove_custom_node(const String &p_name, const String &p_category) { + String node_name = "custom/" + p_category + "/" + p_name; + custom_nodes.erase(node_name); + VisualScriptLanguage::singleton->remove_register_func(node_name); + emit_signal("custom_nodes_updated"); +} + +void _VisualScriptEditor::_bind_methods() { + ClassDB::bind_method(D_METHOD("add_custom_node", "name", "category", "script"), &_VisualScriptEditor::add_custom_node); + ClassDB::bind_method(D_METHOD("remove_custom_node", "name", "category"), &_VisualScriptEditor::remove_custom_node); + ADD_SIGNAL(MethodInfo("custom_nodes_updated")); +} #endif diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index db54d10300..3d037e82ea 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -278,6 +278,29 @@ public: VisualScriptEditor(); ~VisualScriptEditor(); }; + +// Singleton +class _VisualScriptEditor : public Object { + GDCLASS(_VisualScriptEditor, Object); + + friend class VisualScriptLanguage; + +protected: + static void _bind_methods(); + static _VisualScriptEditor *singleton; + + static Map<String, RefPtr> custom_nodes; + static Ref<VisualScriptNode> create_node_custom(const String &p_name); + +public: + static _VisualScriptEditor *get_singleton() { return singleton; } + + void add_custom_node(const String &p_name, const String &p_category, const Ref<Script> &p_script); + void remove_custom_node(const String &p_name, const String &p_category); + + _VisualScriptEditor(); + ~_VisualScriptEditor(); +}; #endif #endif // VISUALSCRIPT_EDITOR_H diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index a5dc6ffc13..cbe4438cdf 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -29,9 +29,9 @@ /*************************************************************************/ #include "visual_script_func_nodes.h" +#include "engine.h" #include "io/resource_loader.h" #include "os/os.h" -#include "project_settings.h" #include "scene/main/node.h" #include "scene/main/scene_tree.h" #include "visual_script_nodes.h" @@ -344,7 +344,7 @@ void VisualScriptFunctionCall::set_singleton(const StringName &p_type) { return; singleton = p_type; - Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); + Object *obj = Engine::get_singleton()->get_singleton_object(singleton); if (obj) { base_type = obj->get_class(); } @@ -380,7 +380,7 @@ void VisualScriptFunctionCall::_update_method_cache() { } else if (call_mode == CALL_MODE_SINGLETON) { - Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); + Object *obj = Engine::get_singleton()->get_singleton_object(singleton); if (obj) { type = obj->get_class(); script = obj->get_script(); @@ -565,11 +565,11 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const if (call_mode != CALL_MODE_SINGLETON) { property.usage = 0; } else { - List<ProjectSettings::Singleton> names; - ProjectSettings::get_singleton()->get_singletons(&names); + List<Engine::Singleton> names; + Engine::get_singleton()->get_singletons(&names); property.hint = PROPERTY_HINT_ENUM; String sl; - for (List<ProjectSettings::Singleton>::Element *E = names.front(); E; E = E->next()) { + for (List<Engine::Singleton>::Element *E = names.front(); E; E = E->next()) { if (sl != String()) sl += ","; sl += E->get().name; @@ -603,7 +603,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const property.hint_string = itos(get_visual_script()->get_instance_id()); } else if (call_mode == CALL_MODE_SINGLETON) { - Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); + Object *obj = Engine::get_singleton()->get_singleton_object(singleton); if (obj) { property.hint = PROPERTY_HINT_METHOD_OF_INSTANCE; property.hint_string = itos(obj->get_instance_id()); @@ -879,7 +879,7 @@ public: } break; case VisualScriptFunctionCall::CALL_MODE_SINGLETON: { - Object *object = ProjectSettings::get_singleton()->get_singleton_object(singleton); + Object *object = Engine::get_singleton()->get_singleton_object(singleton); if (!object) { r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD; r_error_str = "Invalid singleton name: '" + String(singleton) + "'"; diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index 3863fa7e1c..05ff629d1b 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "visual_script_nodes.h" +#include "engine.h" #include "global_constants.h" #include "os/input.h" #include "os/os.h" @@ -1976,13 +1977,13 @@ public: VisualScriptNodeInstance *VisualScriptEngineSingleton::instance(VisualScriptInstance *p_instance) { VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton); - instance->singleton = ProjectSettings::get_singleton()->get_singleton_object(singleton); + instance->singleton = Engine::get_singleton()->get_singleton_object(singleton); return instance; } VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output_type(TypeGuess *p_inputs, int p_output) const { - Object *obj = ProjectSettings::get_singleton()->get_singleton_object(singleton); + Object *obj = Engine::get_singleton()->get_singleton_object(singleton); TypeGuess tg; tg.type = Variant::OBJECT; if (obj) { @@ -2000,11 +2001,11 @@ void VisualScriptEngineSingleton::_bind_methods() { String cc; - List<ProjectSettings::Singleton> singletons; + List<Engine::Singleton> singletons; - ProjectSettings::get_singleton()->get_singletons(&singletons); + Engine::get_singleton()->get_singletons(&singletons); - for (List<ProjectSettings::Singleton>::Element *E = singletons.front(); E; E = E->next()) { + for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { if (E->get().name == "VS" || E->get().name == "PS" || E->get().name == "PS2D" || E->get().name == "AS" || E->get().name == "TS" || E->get().name == "SS" || E->get().name == "SS2D") continue; //skip these, too simple named diff --git a/modules/vorbis/SCsub b/modules/vorbis/SCsub index 9d2d0feb92..55a112585b 100644 --- a/modules/vorbis/SCsub +++ b/modules/vorbis/SCsub @@ -5,6 +5,8 @@ Import('env_modules') env_vorbis = env_modules.Clone() +stub = True + # Thirdparty source files if env['builtin_libvorbis']: thirdparty_dir = "#thirdparty/libvorbis/" @@ -45,5 +47,9 @@ if env['builtin_libvorbis']: if env['builtin_libogg']: env_vorbis.Append(CPPPATH=["#thirdparty/libogg"]) -# Godot source files -env_vorbis.add_source_files(env.modules_sources, "*.cpp") +if not stub: + # Module files + env_vorbis.add_source_files(env.modules_sources, "*.cpp") +else: + # Module files + env_vorbis.add_source_files(env.modules_sources, "stub/register_types.cpp") diff --git a/modules/vorbis/audio_stream_ogg_vorbis.cpp b/modules/vorbis/audio_stream_ogg_vorbis.cpp index 6235799fc2..9fb6fa8197 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.cpp +++ b/modules/vorbis/audio_stream_ogg_vorbis.cpp @@ -106,8 +106,6 @@ int AudioStreamPlaybackOGGVorbis::mix(int16_t *p_buffer, int p_frames) { break; } -//printf("to mix %i - mix me %i bytes\n",to_mix,to_mix*stream_channels*sizeof(int16_t)); - #ifdef BIG_ENDIAN_ENABLED long ret = ov_read(&vf, (char *)p_buffer, todo * stream_channels * sizeof(int16_t), 1, 2, 1, ¤t_section); #else @@ -359,7 +357,7 @@ void AudioStreamPlaybackOGGVorbis::set_paused(bool p_paused) { paused = p_paused; } -bool AudioStreamPlaybackOGGVorbis::is_paused(bool p_paused) const { +bool AudioStreamPlaybackOGGVorbis::is_paused() const { return paused; } diff --git a/modules/vorbis/audio_stream_ogg_vorbis.h b/modules/vorbis/audio_stream_ogg_vorbis.h index 79eadec56e..5000d03fd4 100644 --- a/modules/vorbis/audio_stream_ogg_vorbis.h +++ b/modules/vorbis/audio_stream_ogg_vorbis.h @@ -85,7 +85,7 @@ public: virtual void set_loop_restart_time(float p_time) { loop_restart_time = p_time; } virtual void set_paused(bool p_paused); - virtual bool is_paused(bool p_paused) const; + virtual bool is_paused() const; virtual void set_loop(bool p_enable); virtual bool has_loop() const; diff --git a/modules/vorbis/config.py b/modules/vorbis/config.py index ef5daca05c..5f133eba90 100644 --- a/modules/vorbis/config.py +++ b/modules/vorbis/config.py @@ -1,8 +1,5 @@ - def can_build(platform): -# return True - return False - + return True def configure(env): pass diff --git a/modules/vorbis/stub/register_types.cpp b/modules/vorbis/stub/register_types.cpp new file mode 100644 index 0000000000..b93d890436 --- /dev/null +++ b/modules/vorbis/stub/register_types.cpp @@ -0,0 +1,36 @@ +/*************************************************************************/ +/* register_types.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.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 "register_types.h" + +// Dummy module as libvorbis is needed by other modules (theora ...) + +void register_vorbis_types() {} + +void unregister_vorbis_types() {} diff --git a/modules/vorbis/stub/register_types.h b/modules/vorbis/stub/register_types.h new file mode 100644 index 0000000000..e7cde7a66c --- /dev/null +++ b/modules/vorbis/stub/register_types.h @@ -0,0 +1,31 @@ +/*************************************************************************/ +/* register_types.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.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. */ +/*************************************************************************/ +void register_vorbis_types(); +void unregister_vorbis_types(); diff --git a/modules/webm/config.py b/modules/webm/config.py index ef5daca05c..dcae4447d5 100644 --- a/modules/webm/config.py +++ b/modules/webm/config.py @@ -1,8 +1,14 @@ - def can_build(platform): -# return True - return False - + return platform != 'iphone' def configure(env): pass + +def get_doc_classes(): + return [ + "ResourceImporterWebm", + "VideoStreamWebm", + ] + +def get_doc_path(): + return "doc_classes" diff --git a/modules/webm/doc_classes/ResourceImporterWebm.xml b/modules/webm/doc_classes/ResourceImporterWebm.xml new file mode 100644 index 0000000000..dcba351e37 --- /dev/null +++ b/modules/webm/doc_classes/ResourceImporterWebm.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="ResourceImporterWebm" inherits="ResourceImporter" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + </methods> + <constants> + </constants> +</class> diff --git a/modules/webm/doc_classes/VideoStreamWebm.xml b/modules/webm/doc_classes/VideoStreamWebm.xml new file mode 100644 index 0000000000..9a430f6b0d --- /dev/null +++ b/modules/webm/doc_classes/VideoStreamWebm.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<class name="VideoStreamWebm" inherits="VideoStream" category="Core" version="3.0-alpha"> + <brief_description> + </brief_description> + <description> + </description> + <tutorials> + </tutorials> + <demos> + </demos> + <methods> + <method name="get_file"> + <return type="String"> + </return> + <description> + </description> + </method> + <method name="set_file"> + <return type="void"> + </return> + <argument index="0" name="file" type="String"> + </argument> + <description> + </description> + </method> + </methods> + <members> + <member name="file" type="String" setter="set_file" getter="get_file"> + </member> + </members> + <constants> + </constants> +</class> diff --git a/modules/webm/libvpx/SCsub b/modules/webm/libvpx/SCsub index fd8d762a5e..73ba17d184 100644 --- a/modules/webm/libvpx/SCsub +++ b/modules/webm/libvpx/SCsub @@ -298,7 +298,7 @@ if webm_cpu_x86: if not yasm_found: webm_cpu_x86 = False - print "YASM is necessary for WebM SIMD optimizations." + print("YASM is necessary for WebM SIMD optimizations.") webm_simd_optimizations = False @@ -345,7 +345,7 @@ if webm_cpu_arm: webm_simd_optimizations = True if webm_simd_optimizations == False: - print "WebM SIMD optimizations are disabled. Check if your CPU architecture, CPU bits or platform are supported!" + print("WebM SIMD optimizations are disabled. Check if your CPU architecture, CPU bits or platform are supported!") env_libvpx.add_source_files(env.modules_sources, libvpx_sources) diff --git a/modules/webm/register_types.cpp b/modules/webm/register_types.cpp index 892d1b8420..669c9997f1 100644 --- a/modules/webm/register_types.cpp +++ b/modules/webm/register_types.cpp @@ -28,19 +28,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "register_types.h" - +#include "resource_importer_webm.h" #include "video_stream_webm.h" -static ResourceFormatLoaderVideoStreamWebm *webm_stream_loader = NULL; - void register_webm_types() { - webm_stream_loader = memnew(ResourceFormatLoaderVideoStreamWebm); - ResourceLoader::add_resource_format_loader(webm_stream_loader); +#ifdef TOOLS_ENABLED + Ref<ResourceImporterWebm> webm_import; + webm_import.instance(); + ResourceFormatImporter::get_singleton()->add_importer(webm_import); +#endif ClassDB::register_class<VideoStreamWebm>(); } void unregister_webm_types() { - - memdelete(webm_stream_loader); } diff --git a/modules/webm/resource_importer_webm.cpp b/modules/webm/resource_importer_webm.cpp new file mode 100644 index 0000000000..5db3d4df2e --- /dev/null +++ b/modules/webm/resource_importer_webm.cpp @@ -0,0 +1,95 @@ +/*************************************************************************/ +/* resource_importer_webm.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.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 "resource_importer_webm.h" + +#include "io/resource_saver.h" +#include "os/file_access.h" +#include "scene/resources/texture.h" +#include "video_stream_webm.h" + +String ResourceImporterWebm::get_importer_name() const { + + return "Webm"; +} + +String ResourceImporterWebm::get_visible_name() const { + + return "Webm"; +} +void ResourceImporterWebm::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("webm"); +} + +String ResourceImporterWebm::get_save_extension() const { + return "webmstr"; +} + +String ResourceImporterWebm::get_resource_type() const { + + return "VideoStreamWebm"; +} + +bool ResourceImporterWebm::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { + + return true; +} + +int ResourceImporterWebm::get_preset_count() const { + return 0; +} +String ResourceImporterWebm::get_preset_name(int p_idx) const { + + return String(); +} + +void ResourceImporterWebm::get_import_options(List<ImportOption> *r_options, int p_preset) const { + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "loop"), true)); +} + +Error ResourceImporterWebm::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) { + + FileAccess *f = FileAccess::open(p_source_file, FileAccess::READ); + if (!f) { + ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + } + memdelete(f); + + VideoStreamWebm *stream = memnew(VideoStreamWebm); + stream->set_file(p_source_file); + + Ref<VideoStreamWebm> webm_stream = Ref<VideoStreamWebm>(stream); + + return ResourceSaver::save(p_save_path + ".webmstr", webm_stream); +} + +ResourceImporterWebm::ResourceImporterWebm() { +} diff --git a/modules/webm/resource_importer_webm.h b/modules/webm/resource_importer_webm.h new file mode 100644 index 0000000000..4cedd1598d --- /dev/null +++ b/modules/webm/resource_importer_webm.h @@ -0,0 +1,55 @@ +/*************************************************************************/ +/* resource_importer_webm.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* http://www.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 RESOURCEIMPORTERWEBM_H +#define RESOURCEIMPORTERWEBM_H + +#include "io/resource_import.h" + +class ResourceImporterWebm : public ResourceImporter { + GDCLASS(ResourceImporterWebm, ResourceImporter) +public: + virtual String get_importer_name() const; + virtual String get_visible_name() const; + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual String get_save_extension() const; + virtual String get_resource_type() const; + + virtual int get_preset_count() const; + virtual String get_preset_name(int p_idx) const; + + virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const; + virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const; + + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL); + + ResourceImporterWebm(); +}; + +#endif // RESOURCEIMPORTERWEBM_H diff --git a/modules/webm/video_stream_webm.cpp b/modules/webm/video_stream_webm.cpp index 2ec6b27471..0fc9df5b58 100644 --- a/modules/webm/video_stream_webm.cpp +++ b/modules/webm/video_stream_webm.cpp @@ -35,10 +35,13 @@ #include "mkvparser/mkvparser.h" #include "os/file_access.h" +#include "os/os.h" #include "project_settings.h" #include "thirdparty/misc/yuv2rgb.h" +#include "servers/audio_server.h" + #include <string.h> class MkvReader : public mkvparser::IMkvReader { @@ -47,6 +50,8 @@ public: MkvReader(const String &p_file) { file = FileAccess::open(p_file, FileAccess::READ); + + ERR_EXPLAIN("Failed loading resource: '" + p_file + "';"); ERR_FAIL_COND(!file); } ~MkvReader() { @@ -113,14 +118,14 @@ bool VideoStreamPlaybackWebm::open_file(const String &p_file) { webm = memnew(WebMDemuxer(new MkvReader(file_name), 0, audio_track)); if (webm->isOpen()) { - video = memnew(VPXDecoder(*webm, 8)); //TODO: Detect CPU threads + video = memnew(VPXDecoder(*webm, OS::get_singleton()->get_processor_count())); if (video->isOpen()) { audio = memnew(OpusVorbisDecoder(*webm)); if (audio->isOpen()) { audio_frame = memnew(WebMFrame); - pcm = (int16_t *)memalloc(sizeof(int16_t) * audio->getBufferSamples() * webm->getChannels()); + pcm = (float *)memalloc(sizeof(float) * audio->getBufferSamples() * webm->getChannels()); } else { memdelete(audio); @@ -183,7 +188,7 @@ void VideoStreamPlaybackWebm::set_paused(bool p_paused) { paused = p_paused; } -bool VideoStreamPlaybackWebm::is_paused(bool p_paused) const { +bool VideoStreamPlaybackWebm::is_paused() const { return paused; } @@ -222,11 +227,18 @@ Ref<Texture> VideoStreamPlaybackWebm::get_texture() { return texture; } + void VideoStreamPlaybackWebm::update(float p_delta) { if ((!playing || paused) || !video) return; + time += p_delta; + + if (time < video_pos) { + return; + } + bool audio_buffer_full = false; if (samples_offset > -1) { @@ -245,13 +257,15 @@ void VideoStreamPlaybackWebm::update(float p_delta) { } const bool hasAudio = (audio && mix_callback); - while ((hasAudio && (!audio_buffer_full || !has_enough_video_frames())) || (!hasAudio && video_frames_pos == 0)) { + while ((hasAudio && !audio_buffer_full && !has_enough_video_frames()) || + (!hasAudio && video_frames_pos == 0)) { - if (hasAudio && !audio_buffer_full && audio_frame->isValid() && audio->getPCMS16(*audio_frame, pcm, num_decoded_samples) && num_decoded_samples > 0) { + if (hasAudio && !audio_buffer_full && audio_frame->isValid() && + audio->getPCMF(*audio_frame, pcm, num_decoded_samples) && num_decoded_samples > 0) { const int mixed = mix_callback(mix_udata, pcm, num_decoded_samples); - if (mixed != num_decoded_samples) { + if (mixed != num_decoded_samples) { samples_offset = mixed; audio_buffer_full = true; } @@ -273,72 +287,61 @@ void VideoStreamPlaybackWebm::update(float p_delta) { ++video_frames_pos; }; - const double video_delay = video->getFramesDelay() * video_frame_delay; - - bool want_this_frame = false; - while (video_frames_pos > 0 && !want_this_frame) { + bool video_frame_done = false; + while (video_frames_pos > 0 && !video_frame_done) { WebMFrame *video_frame = video_frames[0]; - if (video_frame->time <= time + video_delay) { - if (video->decode(*video_frame)) { + // It seems VPXDecoder::decode has to be executed even though we might skip this frame + if (video->decode(*video_frame)) { - VPXDecoder::IMAGE_ERROR err; - VPXDecoder::Image image; + VPXDecoder::IMAGE_ERROR err; + VPXDecoder::Image image; - while ((err = video->getImage(image)) != VPXDecoder::NO_FRAME) { + if (should_process(*video_frame)) { - want_this_frame = (time - video_frame->time <= video_frame_delay); + if ((err = video->getImage(image)) != VPXDecoder::NO_FRAME) { - if (want_this_frame) { + if (err == VPXDecoder::NO_ERROR && image.w == webm->getWidth() && image.h == webm->getHeight()) { - if (err == VPXDecoder::NO_ERROR && image.w == webm->getWidth() && image.h == webm->getHeight()) { + PoolVector<uint8_t>::Write w = frame_data.write(); + bool converted = false; - PoolVector<uint8_t>::Write w = frame_data.write(); - bool converted = false; + if (image.chromaShiftW == 1 && image.chromaShiftH == 1) { - if (image.chromaShiftW == 1 && image.chromaShiftH == 1) { + yuv420_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0); + // libyuv::I420ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); + converted = true; + } else if (image.chromaShiftW == 1 && image.chromaShiftH == 0) { - yuv420_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0); - // libyuv::I420ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); - converted = true; - } else if (image.chromaShiftW == 1 && image.chromaShiftH == 0) { + yuv422_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0); + // libyuv::I422ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); + converted = true; + } else if (image.chromaShiftW == 0 && image.chromaShiftH == 0) { - yuv422_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0); - // libyuv::I422ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); - converted = true; - } else if (image.chromaShiftW == 0 && image.chromaShiftH == 0) { + yuv444_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0); + // libyuv::I444ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); + converted = true; + } else if (image.chromaShiftW == 2 && image.chromaShiftH == 0) { - yuv444_2_rgb8888(w.ptr(), image.planes[0], image.planes[2], image.planes[1], image.w, image.h, image.linesize[0], image.linesize[1], image.w << 2, 0); - // libyuv::I444ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); - converted = true; - } else if (image.chromaShiftW == 2 && image.chromaShiftH == 0) { - - // libyuv::I411ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); - // converted = true; - } - - if (converted) - texture->set_data(Image(image.w, image.h, 0, Image::FORMAT_RGBA8, frame_data)); //Zero copy send to visual server + // libyuv::I411ToARGB(image.planes[0], image.linesize[0], image.planes[2], image.linesize[2], image.planes[1], image.linesize[1], w.ptr(), image.w << 2, image.w, image.h); + // converted = true; } - break; + if (converted) { + Ref<Image> img = memnew(Image(image.w, image.h, 0, Image::FORMAT_RGBA8, frame_data)); + texture->set_data(img); //Zero copy send to visual server + video_frame_done = true; + } } } } - - video_frame_delay = video_frame->time - video_pos; - video_pos = video_frame->time; - - memmove(video_frames, video_frames + 1, (--video_frames_pos) * sizeof(void *)); - video_frames[video_frames_pos] = video_frame; - } else { - - break; } - } - time += p_delta; + video_pos = video_frame->time; + memmove(video_frames, video_frames + 1, (--video_frames_pos) * sizeof(void *)); + video_frames[video_frames_pos] = video_frame; + } if (video_frames_pos == 0 && webm->isEOS()) stop(); @@ -372,6 +375,11 @@ inline bool VideoStreamPlaybackWebm::has_enough_video_frames() const { return false; } +bool VideoStreamPlaybackWebm::should_process(WebMFrame &video_frame) { + const double audio_delay = AudioServer::get_singleton()->get_output_delay(); + return video_frame.time >= time + audio_delay + delay_compensation; +} + void VideoStreamPlaybackWebm::delete_pointers() { if (pcm) @@ -395,34 +403,6 @@ void VideoStreamPlaybackWebm::delete_pointers() { /**/ -RES ResourceFormatLoaderVideoStreamWebm::load(const String &p_path, const String &p_original_path, Error *r_error) { - - Ref<VideoStreamWebm> stream = memnew(VideoStreamWebm); - stream->set_file(p_path); - if (r_error) - *r_error = OK; - return stream; -} - -void ResourceFormatLoaderVideoStreamWebm::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("webm"); -} -bool ResourceFormatLoaderVideoStreamWebm::handles_type(const String &p_type) const { - - return (p_type == "VideoStream" || p_type == "VideoStreamWebm"); -} - -String ResourceFormatLoaderVideoStreamWebm::get_resource_type(const String &p_path) const { - - const String exl = p_path.get_extension().to_lower(); - if (exl == "webm") - return "VideoStreamWebm"; - return ""; -} - -/**/ - VideoStreamWebm::VideoStreamWebm() : audio_track(0) {} @@ -439,6 +419,19 @@ void VideoStreamWebm::set_file(const String &p_file) { file = p_file; } +String VideoStreamWebm::get_file() { + + return file; +} + +void VideoStreamWebm::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_file", "file"), &VideoStreamWebm::set_file); + ClassDB::bind_method(D_METHOD("get_file"), &VideoStreamWebm::get_file); + + ADD_PROPERTY(PropertyInfo(Variant::STRING, "file", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_file", "get_file"); +} + void VideoStreamWebm::set_audio_track(int p_track) { audio_track = p_track; diff --git a/modules/webm/video_stream_webm.h b/modules/webm/video_stream_webm.h index fc0720967a..f7dd16a38f 100644 --- a/modules/webm/video_stream_webm.h +++ b/modules/webm/video_stream_webm.h @@ -60,7 +60,7 @@ class VideoStreamPlaybackWebm : public VideoStreamPlayback { PoolVector<uint8_t> frame_data; Ref<ImageTexture> texture; - int16_t *pcm; + float *pcm; public: VideoStreamPlaybackWebm(); @@ -74,7 +74,7 @@ public: virtual bool is_playing() const; virtual void set_paused(bool p_paused); - virtual bool is_paused(bool p_paused) const; + virtual bool is_paused() const; virtual void set_loop(bool p_enable); virtual bool has_loop() const; @@ -95,6 +95,7 @@ public: private: inline bool has_enough_video_frames() const; + bool should_process(WebMFrame &video_frame); void delete_pointers(); }; @@ -103,27 +104,21 @@ private: class VideoStreamWebm : public VideoStream { - GDCLASS(VideoStreamWebm, VideoStream) + GDCLASS(VideoStreamWebm, VideoStream); + RES_BASE_EXTENSION("webmstr"); String file; int audio_track; +protected: + static void _bind_methods(); + public: VideoStreamWebm(); virtual Ref<VideoStreamPlayback> instance_playback(); virtual void set_file(const String &p_file); + String get_file(); virtual void set_audio_track(int p_track); }; - -/**/ - -class ResourceFormatLoaderVideoStreamWebm : public ResourceFormatLoader { - -public: - virtual RES load(const String &p_path, const String &p_original_path, Error *r_error); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; -}; diff --git a/modules/webp/config.py b/modules/webp/config.py index fb920482f5..5f133eba90 100644 --- a/modules/webp/config.py +++ b/modules/webp/config.py @@ -1,7 +1,5 @@ - def can_build(platform): return True - def configure(env): pass |