diff options
Diffstat (limited to 'modules')
147 files changed, 6121 insertions, 3137 deletions
diff --git a/modules/assimp/editor_scene_importer_assimp.h b/modules/assimp/editor_scene_importer_assimp.h index ab00a6c3aa..7be80c4ad0 100644 --- a/modules/assimp/editor_scene_importer_assimp.h +++ b/modules/assimp/editor_scene_importer_assimp.h @@ -136,9 +136,9 @@ public: Assimp::DefaultLogger::kill(); } - virtual void get_extensions(List<String> *r_extensions) const; - virtual uint32_t get_import_flags() const; - virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr); + virtual void get_extensions(List<String> *r_extensions) const override; + virtual uint32_t get_import_flags() const override; + virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = nullptr) override; Ref<Image> load_image(ImportState &state, const aiScene *p_scene, String p_path); static void RegenerateBoneStack(ImportState &state); diff --git a/modules/bullet/area_bullet.cpp b/modules/bullet/area_bullet.cpp index 79d8e252f0..edbd9565b8 100644 --- a/modules/bullet/area_bullet.cpp +++ b/modules/bullet/area_bullet.cpp @@ -164,7 +164,7 @@ void AreaBullet::main_shape_changed() { btGhost->setCollisionShape(get_main_shape()); } -void AreaBullet::reload_body() { +void AreaBullet::do_reload_body() { if (space) { space->remove_area(this); space->add_area(this); @@ -174,16 +174,19 @@ void AreaBullet::reload_body() { void AreaBullet::set_space(SpaceBullet *p_space) { // Clear the old space if there is one if (space) { + clear_overlaps(false); isScratched = false; // Remove this object form the physics world + space->unregister_collision_object(this); space->remove_area(this); } space = p_space; if (space) { - space->add_area(this); + space->register_collision_object(this); + reload_body(); } } diff --git a/modules/bullet/area_bullet.h b/modules/bullet/area_bullet.h index c0bcc858fe..12272092f7 100644 --- a/modules/bullet/area_bullet.h +++ b/modules/bullet/area_bullet.h @@ -140,7 +140,7 @@ public: _FORCE_INLINE_ int get_spOv_priority() { return spOv_priority; } virtual void main_shape_changed(); - virtual void reload_body(); + virtual void do_reload_body(); virtual void set_space(SpaceBullet *p_space); virtual void dispatch_callbacks(); diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index f397c53344..8f64c11867 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -561,14 +561,14 @@ void BulletPhysicsServer3D::body_clear_shapes(RID p_body) { } void BulletPhysicsServer3D::body_attach_object_instance_id(RID p_body, ObjectID p_id) { - CollisionObjectBullet *body = get_collisin_object(p_body); + CollisionObjectBullet *body = get_collision_object(p_body); ERR_FAIL_COND(!body); body->set_instance_id(p_id); } ObjectID BulletPhysicsServer3D::body_get_object_instance_id(RID p_body) const { - CollisionObjectBullet *body = get_collisin_object(p_body); + CollisionObjectBullet *body = get_collision_object(p_body); ERR_FAIL_COND_V(!body, ObjectID()); return body->get_instance_id(); @@ -1557,6 +1557,13 @@ void BulletPhysicsServer3D::sync() { } void BulletPhysicsServer3D::flush_queries() { + if (!active) { + return; + } + + for (int i = 0; i < active_spaces_count; ++i) { + active_spaces[i]->flush_queries(); + } } void BulletPhysicsServer3D::finish() { @@ -1567,7 +1574,17 @@ int BulletPhysicsServer3D::get_process_info(ProcessInfo p_info) { return 0; } -CollisionObjectBullet *BulletPhysicsServer3D::get_collisin_object(RID p_object) const { +SpaceBullet *BulletPhysicsServer3D::get_space(RID p_rid) const { + ERR_FAIL_COND_V_MSG(space_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); + return space_owner.getornull(p_rid); +} + +ShapeBullet *BulletPhysicsServer3D::get_shape(RID p_rid) const { + ERR_FAIL_COND_V_MSG(shape_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); + return shape_owner.getornull(p_rid); +} + +CollisionObjectBullet *BulletPhysicsServer3D::get_collision_object(RID p_object) const { if (rigid_body_owner.owns(p_object)) { return rigid_body_owner.getornull(p_object); } @@ -1577,15 +1594,20 @@ CollisionObjectBullet *BulletPhysicsServer3D::get_collisin_object(RID p_object) if (soft_body_owner.owns(p_object)) { return soft_body_owner.getornull(p_object); } - return nullptr; + ERR_FAIL_V_MSG(nullptr, "The RID is no valid."); } -RigidCollisionObjectBullet *BulletPhysicsServer3D::get_rigid_collisin_object(RID p_object) const { +RigidCollisionObjectBullet *BulletPhysicsServer3D::get_rigid_collision_object(RID p_object) const { if (rigid_body_owner.owns(p_object)) { return rigid_body_owner.getornull(p_object); } if (area_owner.owns(p_object)) { return area_owner.getornull(p_object); } - return nullptr; + ERR_FAIL_V_MSG(nullptr, "The RID is no valid."); +} + +JointBullet *BulletPhysicsServer3D::get_joint(RID p_rid) const { + ERR_FAIL_COND_V_MSG(joint_owner.owns(p_rid) == false, nullptr, "The RID is not valid."); + return joint_owner.getornull(p_rid); } diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index 8e8b33a4b8..6078babaf8 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -88,35 +88,35 @@ public: } /* SHAPE API */ - virtual RID shape_create(ShapeType p_shape); - virtual void shape_set_data(RID p_shape, const Variant &p_data); - virtual ShapeType shape_get_type(RID p_shape) const; - virtual Variant shape_get_data(RID p_shape) const; + virtual RID shape_create(ShapeType p_shape) override; + virtual void shape_set_data(RID p_shape, const Variant &p_data) override; + virtual ShapeType shape_get_type(RID p_shape) const override; + virtual Variant shape_get_data(RID p_shape) const override; - virtual void shape_set_margin(RID p_shape, real_t p_margin); - virtual real_t shape_get_margin(RID p_shape) const; + virtual void shape_set_margin(RID p_shape, real_t p_margin) override; + virtual real_t shape_get_margin(RID p_shape) const override; /// Not supported - virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias); + virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) override; /// Not supported - virtual real_t shape_get_custom_solver_bias(RID p_shape) const; + virtual real_t shape_get_custom_solver_bias(RID p_shape) const override; /* SPACE API */ - virtual RID space_create(); - virtual void space_set_active(RID p_space, bool p_active); - virtual bool space_is_active(RID p_space) const; + virtual RID space_create() override; + virtual void space_set_active(RID p_space, bool p_active) override; + virtual bool space_is_active(RID p_space) const override; /// Not supported - virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value); + virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) override; /// Not supported - virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const; + virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const override; - virtual PhysicsDirectSpaceState3D *space_get_direct_state(RID p_space); + virtual PhysicsDirectSpaceState3D *space_get_direct_state(RID p_space) override; - virtual void space_set_debug_contacts(RID p_space, int p_max_contacts); - virtual Vector<Vector3> space_get_contacts(RID p_space) const; - virtual int space_get_contact_count(RID p_space) const; + virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) override; + virtual Vector<Vector3> space_get_contacts(RID p_space) const override; + virtual int space_get_contact_count(RID p_space) const override; /* AREA API */ @@ -125,265 +125,265 @@ public: /// The API area_set_param is a bit hacky, and allow Godot to set some parameters on Bullet's world, a different use print a warning to console. /// All other APIs returns a warning message if used - virtual RID area_create(); + virtual RID area_create() override; - virtual void area_set_space(RID p_area, RID p_space); + virtual void area_set_space(RID p_area, RID p_space) override; - virtual RID area_get_space(RID p_area) const; + virtual RID area_get_space(RID p_area) const override; - virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode); - virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const; + virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) override; + virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const override; - virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false); - virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape); - virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform); - virtual int area_get_shape_count(RID p_area) const; - virtual RID area_get_shape(RID p_area, int p_shape_idx) const; - virtual Transform area_get_shape_transform(RID p_area, int p_shape_idx) const; - virtual void area_remove_shape(RID p_area, int p_shape_idx); - virtual void area_clear_shapes(RID p_area); - virtual void area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled); - virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id); - virtual ObjectID area_get_object_instance_id(RID p_area) const; + virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false) override; + virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) override; + virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) override; + virtual int area_get_shape_count(RID p_area) const override; + virtual RID area_get_shape(RID p_area, int p_shape_idx) const override; + virtual Transform area_get_shape_transform(RID p_area, int p_shape_idx) const override; + virtual void area_remove_shape(RID p_area, int p_shape_idx) override; + virtual void area_clear_shapes(RID p_area) override; + virtual void area_set_shape_disabled(RID p_area, int p_shape_idx, bool p_disabled) override; + virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) override; + virtual ObjectID area_get_object_instance_id(RID p_area) const override; /// If you pass as p_area the SpaceBullet you can set some parameters as specified below /// AREA_PARAM_GRAVITY /// AREA_PARAM_GRAVITY_VECTOR /// Otherwise you can set area parameters - virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value); - virtual Variant area_get_param(RID p_area, AreaParameter p_param) const; + virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) override; + virtual Variant area_get_param(RID p_area, AreaParameter p_param) const override; - virtual void area_set_transform(RID p_area, const Transform &p_transform); - virtual Transform area_get_transform(RID p_area) const; + virtual void area_set_transform(RID p_area, const Transform &p_transform) override; + virtual Transform area_get_transform(RID p_area) const override; - virtual void area_set_collision_mask(RID p_area, uint32_t p_mask); - virtual void area_set_collision_layer(RID p_area, uint32_t p_layer); + virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) override; + virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) override; - virtual void area_set_monitorable(RID p_area, bool p_monitorable); - virtual void area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method); - virtual void area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method); - virtual void area_set_ray_pickable(RID p_area, bool p_enable); - virtual bool area_is_ray_pickable(RID p_area) const; + virtual void area_set_monitorable(RID p_area, bool p_monitorable) override; + virtual void area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) override; + virtual void area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) override; + virtual void area_set_ray_pickable(RID p_area, bool p_enable) override; + virtual bool area_is_ray_pickable(RID p_area) const override; /* RIGID BODY API */ - virtual RID body_create(BodyMode p_mode = BODY_MODE_RIGID, bool p_init_sleeping = false); + virtual RID body_create(BodyMode p_mode = BODY_MODE_RIGID, bool p_init_sleeping = false) override; - virtual void body_set_space(RID p_body, RID p_space); - virtual RID body_get_space(RID p_body) const; + virtual void body_set_space(RID p_body, RID p_space) override; + virtual RID body_get_space(RID p_body) const override; - virtual void body_set_mode(RID p_body, BodyMode p_mode); - virtual BodyMode body_get_mode(RID p_body) const; + virtual void body_set_mode(RID p_body, BodyMode p_mode) override; + virtual BodyMode body_get_mode(RID p_body) const override; - virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false); + virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform(), bool p_disabled = false) override; // Not supported, Please remove and add new shape - virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape); - virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform); + virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) override; + virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) override; - virtual int body_get_shape_count(RID p_body) const; - virtual RID body_get_shape(RID p_body, int p_shape_idx) const; - virtual Transform body_get_shape_transform(RID p_body, int p_shape_idx) const; + virtual int body_get_shape_count(RID p_body) const override; + virtual RID body_get_shape(RID p_body, int p_shape_idx) const override; + virtual Transform body_get_shape_transform(RID p_body, int p_shape_idx) const override; - virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled); + virtual void body_set_shape_disabled(RID p_body, int p_shape_idx, bool p_disabled) override; - virtual void body_remove_shape(RID p_body, int p_shape_idx); - virtual void body_clear_shapes(RID p_body); + virtual void body_remove_shape(RID p_body, int p_shape_idx) override; + virtual void body_clear_shapes(RID p_body) override; // Used for Rigid and Soft Bodies - virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id); - virtual ObjectID body_get_object_instance_id(RID p_body) const; + virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) override; + virtual ObjectID body_get_object_instance_id(RID p_body) const override; - virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable); - virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const; + virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) override; + virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const override; - virtual void body_set_collision_layer(RID p_body, uint32_t p_layer); - virtual uint32_t body_get_collision_layer(RID p_body) const; + virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) override; + virtual uint32_t body_get_collision_layer(RID p_body) const override; - virtual void body_set_collision_mask(RID p_body, uint32_t p_mask); - virtual uint32_t body_get_collision_mask(RID p_body) const; + virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) override; + virtual uint32_t body_get_collision_mask(RID p_body) const override; /// This is not supported by physics server - virtual void body_set_user_flags(RID p_body, uint32_t p_flags); + virtual void body_set_user_flags(RID p_body, uint32_t p_flags) override; /// This is not supported by physics server - virtual uint32_t body_get_user_flags(RID p_body) const; + virtual uint32_t body_get_user_flags(RID p_body) const override; - virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value); - virtual float body_get_param(RID p_body, BodyParameter p_param) const; + virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value) override; + virtual float body_get_param(RID p_body, BodyParameter p_param) const override; - virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin); - virtual real_t body_get_kinematic_safe_margin(RID p_body) const; + virtual void body_set_kinematic_safe_margin(RID p_body, real_t p_margin) override; + virtual real_t body_get_kinematic_safe_margin(RID p_body) const override; - virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant); - virtual Variant body_get_state(RID p_body, BodyState p_state) const; + virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override; + virtual Variant body_get_state(RID p_body, BodyState p_state) const override; - virtual void body_set_applied_force(RID p_body, const Vector3 &p_force); - virtual Vector3 body_get_applied_force(RID p_body) const; + virtual void body_set_applied_force(RID p_body, const Vector3 &p_force) override; + virtual Vector3 body_get_applied_force(RID p_body) const override; - virtual void body_set_applied_torque(RID p_body, const Vector3 &p_torque); - virtual Vector3 body_get_applied_torque(RID p_body) const; + virtual void body_set_applied_torque(RID p_body, const Vector3 &p_torque) override; + virtual Vector3 body_get_applied_torque(RID p_body) const override; - virtual void body_add_central_force(RID p_body, const Vector3 &p_force); - virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()); - virtual void body_add_torque(RID p_body, const Vector3 &p_torque); + virtual void body_add_central_force(RID p_body, const Vector3 &p_force) override; + virtual void body_add_force(RID p_body, const Vector3 &p_force, const Vector3 &p_position = Vector3()) override; + virtual void body_add_torque(RID p_body, const Vector3 &p_torque) override; - virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse); - virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3()); - virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse); - virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity); + virtual void body_apply_central_impulse(RID p_body, const Vector3 &p_impulse) override; + virtual void body_apply_impulse(RID p_body, const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) override; + virtual void body_apply_torque_impulse(RID p_body, const Vector3 &p_impulse) override; + virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) override; - virtual void body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock); - virtual bool body_is_axis_locked(RID p_body, BodyAxis p_axis) const; + virtual void body_set_axis_lock(RID p_body, BodyAxis p_axis, bool p_lock) override; + virtual bool body_is_axis_locked(RID p_body, BodyAxis p_axis) const override; - virtual void body_add_collision_exception(RID p_body, RID p_body_b); - virtual void body_remove_collision_exception(RID p_body, RID p_body_b); - virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions); + virtual void body_add_collision_exception(RID p_body, RID p_body_b) override; + virtual void body_remove_collision_exception(RID p_body, RID p_body_b) override; + virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override; - virtual void body_set_max_contacts_reported(RID p_body, int p_contacts); - virtual int body_get_max_contacts_reported(RID p_body) const; + virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) override; + virtual int body_get_max_contacts_reported(RID p_body) const override; - virtual void body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold); - virtual float body_get_contacts_reported_depth_threshold(RID p_body) const; + virtual void body_set_contacts_reported_depth_threshold(RID p_body, float p_threshold) override; + virtual float body_get_contacts_reported_depth_threshold(RID p_body) const override; - virtual void body_set_omit_force_integration(RID p_body, bool p_omit); - virtual bool body_is_omitting_force_integration(RID p_body) const; + virtual void body_set_omit_force_integration(RID p_body, bool p_omit) override; + virtual bool body_is_omitting_force_integration(RID p_body) const override; - virtual void body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata = Variant()); + virtual void body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata = Variant()) override; - virtual void body_set_ray_pickable(RID p_body, bool p_enable); - virtual bool body_is_ray_pickable(RID p_body) const; + virtual void body_set_ray_pickable(RID p_body, bool p_enable) override; + virtual bool body_is_ray_pickable(RID p_body) const override; // this function only works on physics process, errors and returns null otherwise - virtual PhysicsDirectBodyState3D *body_get_direct_state(RID p_body); + virtual PhysicsDirectBodyState3D *body_get_direct_state(RID p_body) override; - virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true); - virtual int body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001); + virtual bool body_test_motion(RID p_body, const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia, MotionResult *r_result = nullptr, bool p_exclude_raycast_shapes = true) override; + virtual int body_test_ray_separation(RID p_body, const Transform &p_transform, bool p_infinite_inertia, Vector3 &r_recover_motion, SeparationResult *r_results, int p_result_max, float p_margin = 0.001) override; /* SOFT BODY API */ - virtual RID soft_body_create(bool p_init_sleeping = false); + virtual RID soft_body_create(bool p_init_sleeping = false) override; - virtual void soft_body_update_rendering_server(RID p_body, class SoftBodyRenderingServerHandler *p_rendering_server_handler); + virtual void soft_body_update_rendering_server(RID p_body, class SoftBodyRenderingServerHandler *p_rendering_server_handler) override; - virtual void soft_body_set_space(RID p_body, RID p_space); - virtual RID soft_body_get_space(RID p_body) const; + virtual void soft_body_set_space(RID p_body, RID p_space) override; + virtual RID soft_body_get_space(RID p_body) const override; - virtual void soft_body_set_mesh(RID p_body, const REF &p_mesh); + virtual void soft_body_set_mesh(RID p_body, const REF &p_mesh) override; - virtual void soft_body_set_collision_layer(RID p_body, uint32_t p_layer); - virtual uint32_t soft_body_get_collision_layer(RID p_body) const; + virtual void soft_body_set_collision_layer(RID p_body, uint32_t p_layer) override; + virtual uint32_t soft_body_get_collision_layer(RID p_body) const override; - virtual void soft_body_set_collision_mask(RID p_body, uint32_t p_mask); - virtual uint32_t soft_body_get_collision_mask(RID p_body) const; + virtual void soft_body_set_collision_mask(RID p_body, uint32_t p_mask) override; + virtual uint32_t soft_body_get_collision_mask(RID p_body) const override; - virtual void soft_body_add_collision_exception(RID p_body, RID p_body_b); - virtual void soft_body_remove_collision_exception(RID p_body, RID p_body_b); - virtual void soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions); + virtual void soft_body_add_collision_exception(RID p_body, RID p_body_b) override; + virtual void soft_body_remove_collision_exception(RID p_body, RID p_body_b) override; + virtual void soft_body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) override; - virtual void soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant); - virtual Variant soft_body_get_state(RID p_body, BodyState p_state) const; + virtual void soft_body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) override; + virtual Variant soft_body_get_state(RID p_body, BodyState p_state) const override; /// Special function. This function has bad performance - virtual void soft_body_set_transform(RID p_body, const Transform &p_transform); - virtual Vector3 soft_body_get_vertex_position(RID p_body, int vertex_index) const; + virtual void soft_body_set_transform(RID p_body, const Transform &p_transform) override; + virtual Vector3 soft_body_get_vertex_position(RID p_body, int vertex_index) const override; - virtual void soft_body_set_ray_pickable(RID p_body, bool p_enable); - virtual bool soft_body_is_ray_pickable(RID p_body) const; + virtual void soft_body_set_ray_pickable(RID p_body, bool p_enable) override; + virtual bool soft_body_is_ray_pickable(RID p_body) const override; - virtual void soft_body_set_simulation_precision(RID p_body, int p_simulation_precision); - virtual int soft_body_get_simulation_precision(RID p_body); + virtual void soft_body_set_simulation_precision(RID p_body, int p_simulation_precision) override; + virtual int soft_body_get_simulation_precision(RID p_body) override; - virtual void soft_body_set_total_mass(RID p_body, real_t p_total_mass); - virtual real_t soft_body_get_total_mass(RID p_body); + virtual void soft_body_set_total_mass(RID p_body, real_t p_total_mass) override; + virtual real_t soft_body_get_total_mass(RID p_body) override; - virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness); - virtual real_t soft_body_get_linear_stiffness(RID p_body); + virtual void soft_body_set_linear_stiffness(RID p_body, real_t p_stiffness) override; + virtual real_t soft_body_get_linear_stiffness(RID p_body) override; - virtual void soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness); - virtual real_t soft_body_get_areaAngular_stiffness(RID p_body); + virtual void soft_body_set_areaAngular_stiffness(RID p_body, real_t p_stiffness) override; + virtual real_t soft_body_get_areaAngular_stiffness(RID p_body) override; - virtual void soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness); - virtual real_t soft_body_get_volume_stiffness(RID p_body); + virtual void soft_body_set_volume_stiffness(RID p_body, real_t p_stiffness) override; + virtual real_t soft_body_get_volume_stiffness(RID p_body) override; - virtual void soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient); - virtual real_t soft_body_get_pressure_coefficient(RID p_body); + virtual void soft_body_set_pressure_coefficient(RID p_body, real_t p_pressure_coefficient) override; + virtual real_t soft_body_get_pressure_coefficient(RID p_body) override; - virtual void soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient); - virtual real_t soft_body_get_pose_matching_coefficient(RID p_body); + virtual void soft_body_set_pose_matching_coefficient(RID p_body, real_t p_pose_matching_coefficient) override; + virtual real_t soft_body_get_pose_matching_coefficient(RID p_body) override; - virtual void soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient); - virtual real_t soft_body_get_damping_coefficient(RID p_body); + virtual void soft_body_set_damping_coefficient(RID p_body, real_t p_damping_coefficient) override; + virtual real_t soft_body_get_damping_coefficient(RID p_body) override; - virtual void soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient); - virtual real_t soft_body_get_drag_coefficient(RID p_body); + virtual void soft_body_set_drag_coefficient(RID p_body, real_t p_drag_coefficient) override; + virtual real_t soft_body_get_drag_coefficient(RID p_body) override; - virtual void soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position); - virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index); + virtual void soft_body_move_point(RID p_body, int p_point_index, const Vector3 &p_global_position) override; + virtual Vector3 soft_body_get_point_global_position(RID p_body, int p_point_index) override; - virtual Vector3 soft_body_get_point_offset(RID p_body, int p_point_index) const; + virtual Vector3 soft_body_get_point_offset(RID p_body, int p_point_index) const override; - virtual void soft_body_remove_all_pinned_points(RID p_body); - virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin); - virtual bool soft_body_is_point_pinned(RID p_body, int p_point_index); + virtual void soft_body_remove_all_pinned_points(RID p_body) override; + virtual void soft_body_pin_point(RID p_body, int p_point_index, bool p_pin) override; + virtual bool soft_body_is_point_pinned(RID p_body, int p_point_index) override; /* JOINT API */ - virtual JointType joint_get_type(RID p_joint) const; + virtual JointType joint_get_type(RID p_joint) const override; - virtual void joint_set_solver_priority(RID p_joint, int p_priority); - virtual int joint_get_solver_priority(RID p_joint) const; + virtual void joint_set_solver_priority(RID p_joint, int p_priority) override; + virtual int joint_get_solver_priority(RID p_joint) const override; - virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable); - virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const; + virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) override; + virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const override; - virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B); + virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) override; - virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value); - virtual float pin_joint_get_param(RID p_joint, PinJointParam p_param) const; + virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) override; + virtual float pin_joint_get_param(RID p_joint, PinJointParam p_param) const override; - virtual void pin_joint_set_local_a(RID p_joint, const Vector3 &p_A); - virtual Vector3 pin_joint_get_local_a(RID p_joint) const; + virtual void pin_joint_set_local_a(RID p_joint, const Vector3 &p_A) override; + virtual Vector3 pin_joint_get_local_a(RID p_joint) const override; - virtual void pin_joint_set_local_b(RID p_joint, const Vector3 &p_B); - virtual Vector3 pin_joint_get_local_b(RID p_joint) const; + virtual void pin_joint_set_local_b(RID p_joint, const Vector3 &p_B) override; + virtual Vector3 pin_joint_get_local_b(RID p_joint) const override; - virtual RID joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B); - virtual RID joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B); + virtual RID joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) override; + virtual RID joint_create_hinge_simple(RID p_body_A, const Vector3 &p_pivot_A, const Vector3 &p_axis_A, RID p_body_B, const Vector3 &p_pivot_B, const Vector3 &p_axis_B) override; - virtual void hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value); - virtual float hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const; + virtual void hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) override; + virtual float hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const override; - virtual void hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value); - virtual bool hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const; + virtual void hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) override; + virtual bool hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const override; /// Reference frame is A - virtual RID joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B); + virtual RID joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) override; - virtual void slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value); - virtual float slider_joint_get_param(RID p_joint, SliderJointParam p_param) const; + virtual void slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) override; + virtual float slider_joint_get_param(RID p_joint, SliderJointParam p_param) const override; /// Reference frame is A - virtual RID joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B); + virtual RID joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) override; - virtual void cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value); - virtual float cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const; + virtual void cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) override; + virtual float cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const override; /// Reference frame is A - virtual RID joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B); + virtual RID joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) override; - virtual void generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value); - virtual float generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param); + virtual void generic_6dof_joint_set_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param, float p_value) override; + virtual float generic_6dof_joint_get_param(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisParam p_param) override; - virtual void generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable); - virtual bool generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag); + virtual void generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag, bool p_enable) override; + virtual bool generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis p_axis, G6DOFJointAxisFlag p_flag) override; - virtual void generic_6dof_joint_set_precision(RID p_joint, int precision); - virtual int generic_6dof_joint_get_precision(RID p_joint); + virtual void generic_6dof_joint_set_precision(RID p_joint, int precision) override; + virtual int generic_6dof_joint_get_precision(RID p_joint) override; /* MISC */ - virtual void free(RID p_rid); + virtual void free(RID p_rid) override; - virtual void set_active(bool p_active) { + virtual void set_active(bool p_active) override { active = p_active; } @@ -395,21 +395,21 @@ public: return active; } - virtual void init(); - virtual void step(float p_deltaTime); - virtual void sync(); - virtual void flush_queries(); - virtual void finish(); + virtual void init() override; + virtual void step(float p_deltaTime) override; + virtual void sync() override; + virtual void flush_queries() override; + virtual void finish() override; - virtual bool is_flushing_queries() const { return false; } + virtual bool is_flushing_queries() const override { return false; } - virtual int get_process_info(ProcessInfo p_info); + virtual int get_process_info(ProcessInfo p_info) override; - CollisionObjectBullet *get_collisin_object(RID p_object) const; - RigidCollisionObjectBullet *get_rigid_collisin_object(RID p_object) const; - - /// Internal APIs -public: + SpaceBullet *get_space(RID p_rid) const; + ShapeBullet *get_shape(RID p_rid) const; + CollisionObjectBullet *get_collision_object(RID p_object) const; + RigidCollisionObjectBullet *get_rigid_collision_object(RID p_object) const; + JointBullet *get_joint(RID p_rid) const; }; #endif diff --git a/modules/bullet/collision_object_bullet.cpp b/modules/bullet/collision_object_bullet.cpp index a3158a15e5..dd208965bd 100644 --- a/modules/bullet/collision_object_bullet.cpp +++ b/modules/bullet/collision_object_bullet.cpp @@ -79,7 +79,7 @@ btTransform CollisionObjectBullet::ShapeWrapper::get_adjusted_transform() const } void CollisionObjectBullet::ShapeWrapper::claim_bt_shape(const btVector3 &body_scale) { - if (!bt_shape) { + if (bt_shape == nullptr) { if (active) { bt_shape = shape->create_bt_shape(scale * body_scale); } else { @@ -88,6 +88,13 @@ void CollisionObjectBullet::ShapeWrapper::claim_bt_shape(const btVector3 &body_s } } +void CollisionObjectBullet::ShapeWrapper::release_bt_shape() { + if (bt_shape != nullptr) { + shape->destroy_bt_shape(bt_shape); + bt_shape = nullptr; + } +} + CollisionObjectBullet::CollisionObjectBullet(Type p_type) : RIDBullet(), type(p_type) {} @@ -158,6 +165,13 @@ bool CollisionObjectBullet::has_collision_exception(const CollisionObjectBullet return !bt_collision_object->checkCollideWith(p_otherCollisionObject->bt_collision_object); } +void CollisionObjectBullet::prepare_object_for_dispatch() { + if (need_body_reload) { + do_reload_body(); + need_body_reload = false; + } +} + void CollisionObjectBullet::set_collision_enabled(bool p_enabled) { collisionsEnabled = p_enabled; if (collisionsEnabled) { @@ -319,16 +333,28 @@ bool RigidCollisionObjectBullet::is_shape_disabled(int p_index) { return !shapes[p_index].active; } +void RigidCollisionObjectBullet::prepare_object_for_dispatch() { + if (need_shape_reload) { + do_reload_shapes(); + need_shape_reload = false; + } + CollisionObjectBullet::prepare_object_for_dispatch(); +} + void RigidCollisionObjectBullet::shape_changed(int p_shape_index) { ShapeWrapper &shp = shapes.write[p_shape_index]; if (shp.bt_shape == mainShape) { mainShape = nullptr; } - bulletdelete(shp.bt_shape); + shp.release_bt_shape(); reload_shapes(); } void RigidCollisionObjectBullet::reload_shapes() { + need_shape_reload = true; +} + +void RigidCollisionObjectBullet::do_reload_shapes() { if (mainShape && mainShape->isCompound()) { // Destroy compound bulletdelete(mainShape); @@ -336,41 +362,39 @@ void RigidCollisionObjectBullet::reload_shapes() { mainShape = nullptr; - ShapeWrapper *shpWrapper; const int shape_count = shapes.size(); + ShapeWrapper *shapes_ptr = shapes.ptrw(); - // Reset shape if required + // Reset all shapes if required if (force_shape_reset) { for (int i(0); i < shape_count; ++i) { - shpWrapper = &shapes.write[i]; - bulletdelete(shpWrapper->bt_shape); + shapes_ptr[i].release_bt_shape(); } force_shape_reset = false; } const btVector3 body_scale(get_bt_body_scale()); - // Try to optimize by not using compound if (1 == shape_count) { - shpWrapper = &shapes.write[0]; - btTransform transform = shpWrapper->get_adjusted_transform(); + // Is it possible to optimize by not using compound? + btTransform transform = shapes_ptr[0].get_adjusted_transform(); if (transform.getOrigin().isZero() && transform.getBasis() == transform.getBasis().getIdentity()) { - shpWrapper->claim_bt_shape(body_scale); - mainShape = shpWrapper->bt_shape; + shapes_ptr[0].claim_bt_shape(body_scale); + mainShape = shapes_ptr[0].bt_shape; main_shape_changed(); + // Nothing more to do return; } } - // Optimization not possible use a compound shape + // Optimization not possible use a compound shape. btCompoundShape *compoundShape = bulletnew(btCompoundShape(enableDynamicAabbTree, shape_count)); for (int i(0); i < shape_count; ++i) { - shpWrapper = &shapes.write[i]; - shpWrapper->claim_bt_shape(body_scale); - btTransform scaled_shape_transform(shpWrapper->get_adjusted_transform()); + shapes_ptr[i].claim_bt_shape(body_scale); + btTransform scaled_shape_transform(shapes_ptr[i].get_adjusted_transform()); scaled_shape_transform.getOrigin() *= body_scale; - compoundShape->addChildShape(scaled_shape_transform, shpWrapper->bt_shape); + compoundShape->addChildShape(scaled_shape_transform, shapes_ptr[i].bt_shape); } compoundShape->recalculateLocalAabb(); @@ -389,5 +413,5 @@ void RigidCollisionObjectBullet::internal_shape_destroy(int p_index, bool p_perm if (shp.bt_shape == mainShape) { mainShape = nullptr; } - bulletdelete(shp.bt_shape); + shp.release_bt_shape(); } diff --git a/modules/bullet/collision_object_bullet.h b/modules/bullet/collision_object_bullet.h index f1423a69e4..ac74661f24 100644 --- a/modules/bullet/collision_object_bullet.h +++ b/modules/bullet/collision_object_bullet.h @@ -70,11 +70,12 @@ public: struct ShapeWrapper { ShapeBullet *shape = nullptr; - btCollisionShape *bt_shape = nullptr; btTransform transform; btVector3 scale; bool active = true; + btCollisionShape *bt_shape = nullptr; + public: ShapeWrapper() {} ShapeWrapper(ShapeBullet *p_shape, const btTransform &p_transform, bool p_active) : @@ -107,6 +108,7 @@ public: btTransform get_adjusted_transform() const; void claim_bt_shape(const btVector3 &body_scale); + void release_bt_shape(); }; protected: @@ -124,6 +126,8 @@ protected: VSet<RID> exceptions; + bool need_body_reload = true; + /// This array is used to know all areas where this Object is overlapped in /// New area is added when overlap with new area (AreaBullet::addOverlap), then is removed when it exit (CollisionObjectBullet::onExitArea) /// This array is used mainly to know which area hold the pointer of this object @@ -131,6 +135,9 @@ protected: bool isTransformChanged = false; public: + bool is_in_world = false; + +public: CollisionObjectBullet(Type p_type); virtual ~CollisionObjectBullet(); @@ -183,13 +190,21 @@ public: return collisionLayer & p_other->collisionMask || p_other->collisionLayer & collisionMask; } - virtual void reload_body() = 0; + bool need_reload_body() const { + return need_body_reload; + } + + void reload_body() { + need_body_reload = true; + } + virtual void do_reload_body() = 0; virtual void set_space(SpaceBullet *p_space) = 0; _FORCE_INLINE_ SpaceBullet *get_space() const { return space; } virtual void on_collision_checker_start() = 0; virtual void on_collision_checker_end() = 0; + virtual void prepare_object_for_dispatch(); virtual void dispatch_callbacks() = 0; void set_collision_enabled(bool p_enabled); @@ -215,6 +230,7 @@ class RigidCollisionObjectBullet : public CollisionObjectBullet, public ShapeOwn protected: btCollisionShape *mainShape = nullptr; Vector<ShapeWrapper> shapes; + bool need_shape_reload = true; public: RigidCollisionObjectBullet(Type p_type) : @@ -246,8 +262,12 @@ public: void set_shape_disabled(int p_index, bool p_disabled); bool is_shape_disabled(int p_index); + virtual void prepare_object_for_dispatch(); + virtual void shape_changed(int p_shape_index); - virtual void reload_shapes(); + void reload_shapes(); + bool need_reload_shapes() const { return need_shape_reload; } + virtual void do_reload_shapes(); virtual void main_shape_changed() = 0; virtual void body_scale_changed(); diff --git a/modules/bullet/godot_result_callbacks.cpp b/modules/bullet/godot_result_callbacks.cpp index f82648d6ff..e1f950dad1 100644 --- a/modules/bullet/godot_result_callbacks.cpp +++ b/modules/bullet/godot_result_callbacks.cpp @@ -57,7 +57,7 @@ bool GodotFilterCallback::needBroadphaseCollision(btBroadphaseProxy *proxy0, btB bool GodotClosestRayResultCallback::needsCollision(btBroadphaseProxy *proxy0) const { const bool needs = GodotFilterCallback::test_collision_filters(m_collisionFilterGroup, m_collisionFilterMask, proxy0->m_collisionFilterGroup, proxy0->m_collisionFilterMask); - if (needs) { + if (m_pickRay || needs) { btCollisionObject *btObj = static_cast<btCollisionObject *>(proxy0->m_clientObject); CollisionObjectBullet *gObj = static_cast<CollisionObjectBullet *>(btObj->getUserPointer()); diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 6cfbe18a64..717c99c738 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -237,7 +237,7 @@ void RigidBodyBullet::KinematicUtilities::copyAllOwnerShapes() { case PhysicsServer3D::SHAPE_CYLINDER: case PhysicsServer3D::SHAPE_CONVEX_POLYGON: case PhysicsServer3D::SHAPE_RAY: { - shapes.write[i].shape = static_cast<btConvexShape *>(shape_wrapper->shape->create_bt_shape(owner_scale * shape_wrapper->scale, safe_margin)); + shapes.write[i].shape = static_cast<btConvexShape *>(shape_wrapper->shape->internal_create_bt_shape(owner_scale * shape_wrapper->scale, safe_margin)); } break; default: WARN_PRINT("This shape is not supported for kinematic collision."); @@ -307,7 +307,7 @@ void RigidBodyBullet::main_shape_changed() { set_continuous_collision_detection(is_continuous_collision_detection_enabled()); // Reset } -void RigidBodyBullet::reload_body() { +void RigidBodyBullet::do_reload_body() { if (space) { space->remove_rigid_body(this); if (get_main_shape()) { @@ -320,18 +320,21 @@ void RigidBodyBullet::set_space(SpaceBullet *p_space) { // Clear the old space if there is one if (space) { can_integrate_forces = false; + isScratchedSpaceOverrideModificator = false; // Remove all eventual constraints assert_no_constraints(); // Remove this object form the physics world + space->unregister_collision_object(this); space->remove_rigid_body(this); } space = p_space; if (space) { - space->add_rigid_body(this); + space->register_collision_object(this); + reload_body(); } } @@ -803,8 +806,8 @@ const btTransform &RigidBodyBullet::get_transform__bullet() const { } } -void RigidBodyBullet::reload_shapes() { - RigidCollisionObjectBullet::reload_shapes(); +void RigidBodyBullet::do_reload_shapes() { + RigidCollisionObjectBullet::do_reload_shapes(); const btScalar invMass = btBody->getInvMass(); const btScalar mass = invMass == 0 ? 0 : 1 / invMass; diff --git a/modules/bullet/rigid_body_bullet.h b/modules/bullet/rigid_body_bullet.h index ddc9d2916a..eb62d0d39e 100644 --- a/modules/bullet/rigid_body_bullet.h +++ b/modules/bullet/rigid_body_bullet.h @@ -88,57 +88,57 @@ private: BulletPhysicsDirectBodyState3D() {} public: - virtual Vector3 get_total_gravity() const; - virtual float get_total_angular_damp() const; - virtual float get_total_linear_damp() const; + virtual Vector3 get_total_gravity() const override; + virtual float get_total_angular_damp() const override; + virtual float get_total_linear_damp() const override; - virtual Vector3 get_center_of_mass() const; - virtual Basis get_principal_inertia_axes() const; + virtual Vector3 get_center_of_mass() const override; + virtual Basis get_principal_inertia_axes() const override; // get the mass - virtual float get_inverse_mass() const; + virtual float get_inverse_mass() const override; // get density of this body space - virtual Vector3 get_inverse_inertia() const; + virtual Vector3 get_inverse_inertia() const override; // get density of this body space - virtual Basis get_inverse_inertia_tensor() const; + virtual Basis get_inverse_inertia_tensor() const override; - virtual void set_linear_velocity(const Vector3 &p_velocity); - virtual Vector3 get_linear_velocity() const; + virtual void set_linear_velocity(const Vector3 &p_velocity) override; + virtual Vector3 get_linear_velocity() const override; - virtual void set_angular_velocity(const Vector3 &p_velocity); - virtual Vector3 get_angular_velocity() const; + virtual void set_angular_velocity(const Vector3 &p_velocity) override; + virtual Vector3 get_angular_velocity() const override; - virtual void set_transform(const Transform &p_transform); - virtual Transform get_transform() const; + virtual void set_transform(const Transform &p_transform) override; + virtual Transform get_transform() const override; - virtual void add_central_force(const Vector3 &p_force); - virtual void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()); - virtual void add_torque(const Vector3 &p_torque); - virtual void apply_central_impulse(const Vector3 &p_impulse); - virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()); - virtual void apply_torque_impulse(const Vector3 &p_impulse); + virtual void add_central_force(const Vector3 &p_force) override; + virtual void add_force(const Vector3 &p_force, const Vector3 &p_position = Vector3()) override; + virtual void add_torque(const Vector3 &p_torque) override; + virtual void apply_central_impulse(const Vector3 &p_impulse) override; + virtual void apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position = Vector3()) override; + virtual void apply_torque_impulse(const Vector3 &p_impulse) override; - virtual void set_sleep_state(bool p_sleep); - virtual bool is_sleeping() const; + virtual void set_sleep_state(bool p_sleep) override; + virtual bool is_sleeping() const override; - virtual int get_contact_count() const; + virtual int get_contact_count() const override; - virtual Vector3 get_contact_local_position(int p_contact_idx) const; - virtual Vector3 get_contact_local_normal(int p_contact_idx) const; - virtual float get_contact_impulse(int p_contact_idx) const; - virtual int get_contact_local_shape(int p_contact_idx) const; + virtual Vector3 get_contact_local_position(int p_contact_idx) const override; + virtual Vector3 get_contact_local_normal(int p_contact_idx) const override; + virtual float get_contact_impulse(int p_contact_idx) const override; + virtual int get_contact_local_shape(int p_contact_idx) const override; - virtual RID get_contact_collider(int p_contact_idx) const; - virtual Vector3 get_contact_collider_position(int p_contact_idx) const; - virtual ObjectID get_contact_collider_id(int p_contact_idx) const; - virtual int get_contact_collider_shape(int p_contact_idx) const; - virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const; + virtual RID get_contact_collider(int p_contact_idx) const override; + virtual Vector3 get_contact_collider_position(int p_contact_idx) const override; + virtual ObjectID get_contact_collider_id(int p_contact_idx) const override; + virtual int get_contact_collider_shape(int p_contact_idx) const override; + virtual Vector3 get_contact_collider_velocity_at_position(int p_contact_idx) const override; - virtual real_t get_step() const { return deltaTime; } - virtual void integrate_forces() { + virtual real_t get_step() const override { return deltaTime; } + virtual void integrate_forces() override { // Skip the execution of this function } - virtual PhysicsDirectSpaceState3D *get_space_state(); + virtual PhysicsDirectSpaceState3D *get_space_state() override; }; class RigidBodyBullet : public RigidCollisionObjectBullet { @@ -236,7 +236,7 @@ public: _FORCE_INLINE_ btRigidBody *get_bt_rigid_body() { return btBody; } virtual void main_shape_changed(); - virtual void reload_body(); + virtual void do_reload_body(); virtual void set_space(SpaceBullet *p_space); virtual void dispatch_callbacks(); @@ -315,7 +315,7 @@ public: virtual void set_transform__bullet(const btTransform &p_global_transform); virtual const btTransform &get_transform__bullet() const; - virtual void reload_shapes(); + virtual void do_reload_shapes(); virtual void on_enter_area(AreaBullet *p_area); virtual void on_exit_area(AreaBullet *p_area); diff --git a/modules/bullet/shape_bullet.cpp b/modules/bullet/shape_bullet.cpp index d53f1e7d17..f4550c2024 100644 --- a/modules/bullet/shape_bullet.cpp +++ b/modules/bullet/shape_bullet.cpp @@ -46,9 +46,15 @@ @author AndreaCatania */ -ShapeBullet::ShapeBullet() {} +ShapeBullet::ShapeBullet() { +} -ShapeBullet::~ShapeBullet() {} +ShapeBullet::~ShapeBullet() { + if (default_shape != nullptr) { + bulletdelete(default_shape); + default_shape = nullptr; + } +} btCollisionShape *ShapeBullet::create_bt_shape(const Vector3 &p_implicit_scale, real_t p_extra_edge) { btVector3 s; @@ -56,6 +62,22 @@ btCollisionShape *ShapeBullet::create_bt_shape(const Vector3 &p_implicit_scale, return create_bt_shape(s, p_extra_edge); } +btCollisionShape *ShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { + if (p_extra_edge == 0.0 && (p_implicit_scale - btVector3(1, 1, 1)).length2() <= CMP_EPSILON) { + return default_shape; + } + + return internal_create_bt_shape(p_implicit_scale, p_extra_edge); +} + +void ShapeBullet::destroy_bt_shape(btCollisionShape *p_shape) const { + if (p_shape != default_shape && p_shape != old_default_shape) { + if (likely(p_shape != nullptr)) { + bulletdelete(p_shape); + } + } +} + btCollisionShape *ShapeBullet::prepare(btCollisionShape *p_btShape) const { p_btShape->setUserPointer(const_cast<ShapeBullet *>(this)); p_btShape->setMargin(margin); @@ -63,10 +85,21 @@ btCollisionShape *ShapeBullet::prepare(btCollisionShape *p_btShape) const { } void ShapeBullet::notifyShapeChanged() { + // Store the old shape ptr so to not lose the reference pointer. + old_default_shape = default_shape; + // Create the new default shape with the new data. + default_shape = internal_create_bt_shape(btVector3(1, 1, 1)); + for (Map<ShapeOwnerBullet *, int>::Element *E = owners.front(); E; E = E->next()) { ShapeOwnerBullet *owner = static_cast<ShapeOwnerBullet *>(E->key()); owner->shape_changed(owner->find_shape(this)); } + + if (old_default_shape) { + // At this point now one has the old default shape; just delete it. + bulletdelete(old_default_shape); + old_default_shape = nullptr; + } } void ShapeBullet::add_owner(ShapeOwnerBullet *p_owner) { @@ -186,7 +219,7 @@ void PlaneShapeBullet::setup(const Plane &p_plane) { notifyShapeChanged(); } -btCollisionShape *PlaneShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *PlaneShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btVector3 btPlaneNormal; G_TO_B(plane.normal, btPlaneNormal); return prepare(PlaneShapeBullet::create_shape_plane(btPlaneNormal, plane.d)); @@ -214,7 +247,7 @@ void SphereShapeBullet::setup(real_t p_radius) { notifyShapeChanged(); } -btCollisionShape *SphereShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *SphereShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { return prepare(ShapeBullet::create_shape_sphere(radius * p_implicit_scale[0] + p_extra_edge)); } @@ -241,7 +274,7 @@ void BoxShapeBullet::setup(const Vector3 &p_half_extents) { notifyShapeChanged(); } -btCollisionShape *BoxShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *BoxShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { return prepare(ShapeBullet::create_shape_box((half_extents * p_implicit_scale) + btVector3(p_extra_edge, p_extra_edge, p_extra_edge))); } @@ -274,7 +307,7 @@ void CapsuleShapeBullet::setup(real_t p_height, real_t p_radius) { notifyShapeChanged(); } -btCollisionShape *CapsuleShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *CapsuleShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { return prepare(ShapeBullet::create_shape_capsule(radius * p_implicit_scale[0] + p_extra_edge, height * p_implicit_scale[1] + p_extra_edge)); } @@ -307,7 +340,7 @@ void CylinderShapeBullet::setup(real_t p_height, real_t p_radius) { notifyShapeChanged(); } -btCollisionShape *CylinderShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { +btCollisionShape *CylinderShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin) { return prepare(ShapeBullet::create_shape_cylinder(radius * p_implicit_scale[0] + p_margin, height * p_implicit_scale[1] + p_margin)); } @@ -349,7 +382,7 @@ void ConvexPolygonShapeBullet::setup(const Vector<Vector3> &p_vertices) { notifyShapeChanged(); } -btCollisionShape *ConvexPolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *ConvexPolygonShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { if (!vertices.size()) { // This is necessary since 0 vertices return prepare(ShapeBullet::create_shape_empty()); @@ -431,7 +464,7 @@ void ConcavePolygonShapeBullet::setup(Vector<Vector3> p_faces) { notifyShapeChanged(); } -btCollisionShape *ConcavePolygonShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *ConcavePolygonShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btCollisionShape *cs = ShapeBullet::create_shape_concave(meshShape); if (!cs) { // This is necessary since if 0 faces the creation of concave return null @@ -555,7 +588,7 @@ void HeightMapShapeBullet::setup(Vector<real_t> &p_heights, int p_width, int p_d notifyShapeChanged(); } -btCollisionShape *HeightMapShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *HeightMapShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { btCollisionShape *cs(ShapeBullet::create_shape_height_field(heights, width, depth, min_height, max_height)); cs->setLocalScaling(p_implicit_scale); prepare(cs); @@ -588,6 +621,6 @@ void RayShapeBullet::setup(real_t p_length, bool p_slips_on_slope) { notifyShapeChanged(); } -btCollisionShape *RayShapeBullet::create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { +btCollisionShape *RayShapeBullet::internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge) { return prepare(ShapeBullet::create_shape_ray(length * p_implicit_scale[1] + p_extra_edge, slips_on_slope)); } diff --git a/modules/bullet/shape_bullet.h b/modules/bullet/shape_bullet.h index a35a1d8a18..6ca4d36a23 100644 --- a/modules/bullet/shape_bullet.h +++ b/modules/bullet/shape_bullet.h @@ -53,6 +53,10 @@ class ShapeBullet : public RIDBullet { Map<ShapeOwnerBullet *, int> owners; real_t margin = 0.04; + // Contains the default shape. + btCollisionShape *default_shape = nullptr; + btCollisionShape *old_default_shape = nullptr; + protected: /// return self btCollisionShape *prepare(btCollisionShape *p_btShape) const; @@ -63,7 +67,11 @@ public: virtual ~ShapeBullet(); btCollisionShape *create_bt_shape(const Vector3 &p_implicit_scale, real_t p_extra_edge = 0); - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0) = 0; + btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + + void destroy_bt_shape(btCollisionShape *p_shape) const; + + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0) = 0; void add_owner(ShapeOwnerBullet *p_owner); void remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody = false); @@ -102,7 +110,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Plane &p_plane); @@ -118,7 +126,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_radius); @@ -134,7 +142,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Vector3 &p_half_extents); @@ -152,7 +160,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_height, real_t p_radius); @@ -170,7 +178,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0); private: void setup(real_t p_height, real_t p_radius); @@ -186,7 +194,7 @@ public: void get_vertices(Vector<Vector3> &out_vertices); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(const Vector<Vector3> &p_vertices); @@ -204,7 +212,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(Vector<Vector3> p_faces); @@ -223,7 +231,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(Vector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height); @@ -239,7 +247,7 @@ public: virtual void set_data(const Variant &p_data); virtual Variant get_data() const; virtual PhysicsServer3D::ShapeType get_type() const; - virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); + virtual btCollisionShape *internal_create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0); private: void setup(real_t p_length, bool p_slips_on_slope); diff --git a/modules/bullet/soft_body_bullet.cpp b/modules/bullet/soft_body_bullet.cpp index 6794d6c313..3fccd3d8a2 100644 --- a/modules/bullet/soft_body_bullet.cpp +++ b/modules/bullet/soft_body_bullet.cpp @@ -41,7 +41,7 @@ SoftBodyBullet::SoftBodyBullet() : SoftBodyBullet::~SoftBodyBullet() { } -void SoftBodyBullet::reload_body() { +void SoftBodyBullet::do_reload_body() { if (space) { space->remove_soft_body(this); space->add_soft_body(this); @@ -51,13 +51,15 @@ void SoftBodyBullet::reload_body() { void SoftBodyBullet::set_space(SpaceBullet *p_space) { if (space) { isScratched = false; + space->unregister_collision_object(this); space->remove_soft_body(this); } space = p_space; if (space) { - space->add_soft_body(this); + space->register_collision_object(this); + reload_body(); } } diff --git a/modules/bullet/soft_body_bullet.h b/modules/bullet/soft_body_bullet.h index da8a2412ed..ba968f4271 100644 --- a/modules/bullet/soft_body_bullet.h +++ b/modules/bullet/soft_body_bullet.h @@ -87,7 +87,7 @@ public: SoftBodyBullet(); ~SoftBodyBullet(); - virtual void reload_body(); + virtual void do_reload_body(); virtual void set_space(SpaceBullet *p_space); virtual void dispatch_callbacks() {} diff --git a/modules/bullet/space_bullet.cpp b/modules/bullet/space_bullet.cpp index cfe8cd5322..9dc307c629 100644 --- a/modules/bullet/space_bullet.cpp +++ b/modules/bullet/space_bullet.cpp @@ -127,7 +127,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { - bulletdelete(btShape); + shape->destroy_bt_shape(btShape); ERR_PRINT("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return 0; } @@ -147,7 +147,7 @@ int BulletPhysicsDirectSpaceState::intersect_shape(const RID &p_shape, const Tra btQuery.m_closestDistanceThreshold = 0; space->dynamicsWorld->contactTest(&collision_object, btQuery); - bulletdelete(btConvex); + shape->destroy_bt_shape(btShape); return btQuery.m_count; } @@ -158,16 +158,12 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf btVector3 bt_motion; G_TO_B(p_motion, bt_motion); - if (bt_motion.fuzzyZero()) { - return false; - } - ShapeBullet *shape = space->get_physics_server()->get_shape_owner()->getornull(p_shape); ERR_FAIL_COND_V(!shape, false); btCollisionShape *btShape = shape->create_bt_shape(p_xform.basis.get_scale(), p_margin); if (!btShape->isConvex()) { - bulletdelete(btShape); + shape->destroy_bt_shape(btShape); ERR_PRINT("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return false; } @@ -180,6 +176,10 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf btTransform bt_xform_to(bt_xform_from); bt_xform_to.getOrigin() += bt_motion; + if ((bt_xform_to.getOrigin() - bt_xform_from.getOrigin()).fuzzyZero()) { + return false; + } + GodotClosestConvexResultCallback btResult(bt_xform_from.getOrigin(), bt_xform_to.getOrigin(), &p_exclude, p_collide_with_bodies, p_collide_with_areas); btResult.m_collisionFilterGroup = 0; btResult.m_collisionFilterMask = p_collision_mask; @@ -206,7 +206,7 @@ bool BulletPhysicsDirectSpaceState::cast_motion(const RID &p_shape, const Transf r_closest_unsafe = 1.0f; } - bulletdelete(bt_convex_shape); + shape->destroy_bt_shape(btShape); return true; // Mean success } @@ -221,7 +221,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { - bulletdelete(btShape); + shape->destroy_bt_shape(btShape); ERR_PRINT("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return false; } @@ -242,7 +242,7 @@ bool BulletPhysicsDirectSpaceState::collide_shape(RID p_shape, const Transform & space->dynamicsWorld->contactTest(&collision_object, btQuery); r_result_count = btQuery.m_count; - bulletdelete(btConvex); + shape->destroy_bt_shape(btShape); return btQuery.m_count; } @@ -253,7 +253,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh btCollisionShape *btShape = shape->create_bt_shape(p_shape_xform.basis.get_scale_abs(), p_margin); if (!btShape->isConvex()) { - bulletdelete(btShape); + shape->destroy_bt_shape(btShape); ERR_PRINT("The shape is not a convex shape, then is not supported: shape type: " + itos(shape->get_type())); return false; } @@ -273,7 +273,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh btQuery.m_closestDistanceThreshold = 0; space->dynamicsWorld->contactTest(&collision_object, btQuery); - bulletdelete(btConvex); + shape->destroy_bt_shape(btShape); if (btQuery.m_collided) { if (btCollisionObject::CO_RIGID_BODY == btQuery.m_rest_info_collision_object->getInternalType()) { @@ -286,7 +286,7 @@ bool BulletPhysicsDirectSpaceState::rest_info(RID p_shape, const Transform &p_sh } Vector3 BulletPhysicsDirectSpaceState::get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const { - RigidCollisionObjectBullet *rigid_object = space->get_physics_server()->get_rigid_collisin_object(p_object); + RigidCollisionObjectBullet *rigid_object = space->get_physics_server()->get_rigid_collision_object(p_object); ERR_FAIL_COND_V(!rigid_object, Vector3()); btVector3 out_closest_point(0, 0, 0); @@ -349,9 +349,11 @@ SpaceBullet::~SpaceBullet() { } void SpaceBullet::flush_queries() { - const btCollisionObjectArray &colObjArray = dynamicsWorld->getCollisionObjectArray(); - for (int i = colObjArray.size() - 1; 0 <= i; --i) { - static_cast<CollisionObjectBullet *>(colObjArray[i]->getUserPointer())->dispatch_callbacks(); + const int size = collision_objects.size(); + CollisionObjectBullet **objects = collision_objects.ptrw(); + for (int i = 0; i < size; i += 1) { + objects[i]->prepare_object_for_dispatch(); + objects[i]->dispatch_callbacks(); } } @@ -448,16 +450,30 @@ real_t SpaceBullet::get_param(PhysicsServer3D::SpaceParameter p_param) { } void SpaceBullet::add_area(AreaBullet *p_area) { +#ifdef TOOLS_ENABLED + // This never happen, and there is no way for the user to trigger it. + // If in future a bug is introduced into this bullet integration and this + // function is called twice, the crash will notify the developer that will + // fix it even before do the eventual PR. + CRASH_COND(p_area->is_in_world); +#endif areas.push_back(p_area); dynamicsWorld->addCollisionObject(p_area->get_bt_ghost(), p_area->get_collision_layer(), p_area->get_collision_mask()); + p_area->is_in_world = true; } void SpaceBullet::remove_area(AreaBullet *p_area) { - areas.erase(p_area); - dynamicsWorld->removeCollisionObject(p_area->get_bt_ghost()); + if (p_area->is_in_world) { + areas.erase(p_area); + dynamicsWorld->removeCollisionObject(p_area->get_bt_ghost()); + p_area->is_in_world = false; + } } void SpaceBullet::reload_collision_filters(AreaBullet *p_area) { + if (p_area->is_in_world == false) { + return; + } btGhostObject *ghost_object = p_area->get_bt_ghost(); btBroadphaseProxy *ghost_proxy = ghost_object->getBroadphaseHandle(); @@ -467,24 +483,46 @@ void SpaceBullet::reload_collision_filters(AreaBullet *p_area) { dynamicsWorld->refreshBroadphaseProxy(ghost_object); } +void SpaceBullet::register_collision_object(CollisionObjectBullet *p_object) { + collision_objects.push_back(p_object); +} + +void SpaceBullet::unregister_collision_object(CollisionObjectBullet *p_object) { + collision_objects.erase(p_object); +} + void SpaceBullet::add_rigid_body(RigidBodyBullet *p_body) { +#ifdef TOOLS_ENABLED + // This never happen, and there is no way for the user to trigger it. + // If in future a bug is introduced into this bullet integration and this + // function is called twice, the crash will notify the developer that will + // fix it even before do the eventual PR. + CRASH_COND(p_body->is_in_world); +#endif if (p_body->is_static()) { dynamicsWorld->addCollisionObject(p_body->get_bt_rigid_body(), p_body->get_collision_layer(), p_body->get_collision_mask()); } else { dynamicsWorld->addRigidBody(p_body->get_bt_rigid_body(), p_body->get_collision_layer(), p_body->get_collision_mask()); p_body->scratch_space_override_modificator(); } + p_body->is_in_world = true; } void SpaceBullet::remove_rigid_body(RigidBodyBullet *p_body) { - if (p_body->is_static()) { - dynamicsWorld->removeCollisionObject(p_body->get_bt_rigid_body()); - } else { - dynamicsWorld->removeRigidBody(p_body->get_bt_rigid_body()); + if (p_body->is_in_world) { + if (p_body->is_static()) { + dynamicsWorld->removeCollisionObject(p_body->get_bt_rigid_body()); + } else { + dynamicsWorld->removeRigidBody(p_body->get_bt_rigid_body()); + } + p_body->is_in_world = false; } } void SpaceBullet::reload_collision_filters(RigidBodyBullet *p_body) { + if (p_body->is_in_world == false) { + return; + } btRigidBody *rigid_body = p_body->get_bt_rigid_body(); btBroadphaseProxy *body_proxy = rigid_body->getBroadphaseProxy(); @@ -541,10 +579,6 @@ void SpaceBullet::remove_all_collision_objects() { } } -void onBulletPreTickCallback(btDynamicsWorld *p_dynamicsWorld, btScalar timeStep) { - static_cast<SpaceBullet *>(p_dynamicsWorld->getWorldUserInfo())->flush_queries(); -} - void onBulletTickCallback(btDynamicsWorld *p_dynamicsWorld, btScalar timeStep) { const btCollisionObjectArray &colObjArray = p_dynamicsWorld->getCollisionObjectArray(); @@ -612,7 +646,6 @@ void SpaceBullet::create_empty_world(bool p_create_soft_world) { dynamicsWorld->setWorldUserInfo(this); - dynamicsWorld->setInternalTickCallback(onBulletPreTickCallback, this, true); dynamicsWorld->setInternalTickCallback(onBulletTickCallback, this, false); dynamicsWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(ghostPairCallback); // Setup ghost check dynamicsWorld->getPairCache()->setOverlapFilterCallback(godotFilterCallback); @@ -949,7 +982,7 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f motionVec->end(); #endif - for (int shIndex = 0; shIndex < shape_count && !motion.fuzzyZero(); ++shIndex) { + for (int shIndex = 0; shIndex < shape_count; ++shIndex) { if (p_body->is_shape_disabled(shIndex)) { continue; } @@ -971,6 +1004,11 @@ bool SpaceBullet::test_body_motion(RigidBodyBullet *p_body, const Transform &p_f btTransform shape_world_to(shape_world_from); shape_world_to.getOrigin() += motion; + if ((shape_world_to.getOrigin() - shape_world_from.getOrigin()).fuzzyZero()) { + motion = btVector3(0, 0, 0); + break; + } + GodotKinClosestConvexResultCallback btResult(shape_world_from.getOrigin(), shape_world_to.getOrigin(), p_body, p_infinite_inertia); btResult.m_collisionFilterGroup = p_body->get_collision_layer(); btResult.m_collisionFilterMask = p_body->get_collision_mask(); diff --git a/modules/bullet/space_bullet.h b/modules/bullet/space_bullet.h index 5ff421ef52..aa9a70594e 100644 --- a/modules/bullet/space_bullet.h +++ b/modules/bullet/space_bullet.h @@ -76,14 +76,14 @@ private: public: BulletPhysicsDirectSpaceState(SpaceBullet *p_space); - virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false); - virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = nullptr); + virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override; + virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false) override; + virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override; + virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &r_closest_safe, float &r_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = nullptr) override; /// Returns the list of contacts pairs in this order: Local contact, other body contact - virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false); - virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const; + virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override; + virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = 0xFFFFFFFF, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override; + virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const override; }; class SpaceBullet : public RIDBullet { @@ -110,6 +110,7 @@ class SpaceBullet : public RIDBullet { real_t linear_damp = 0.0; real_t angular_damp = 0.0; + Vector<CollisionObjectBullet *> collision_objects; Vector<AreaBullet *> areas; Vector<Vector3> contactDebug; @@ -124,9 +125,12 @@ public: real_t get_delta_time() { return delta_time; } void step(real_t p_delta_time); - _FORCE_INLINE_ btBroadphaseInterface *get_broadphase() { return broadphase; } - _FORCE_INLINE_ btCollisionDispatcher *get_dispatcher() { return dispatcher; } - _FORCE_INLINE_ btSoftBodyWorldInfo *get_soft_body_world_info() { return soft_body_world_info; } + _FORCE_INLINE_ btBroadphaseInterface *get_broadphase() const { return broadphase; } + _FORCE_INLINE_ btDefaultCollisionConfiguration *get_collision_configuration() const { return collisionConfiguration; } + _FORCE_INLINE_ btCollisionDispatcher *get_dispatcher() const { return dispatcher; } + _FORCE_INLINE_ btConstraintSolver *get_solver() const { return solver; } + _FORCE_INLINE_ btDiscreteDynamicsWorld *get_dynamic_world() const { return dynamicsWorld; } + _FORCE_INLINE_ btSoftBodyWorldInfo *get_soft_body_world_info() const { return soft_body_world_info; } _FORCE_INLINE_ bool is_using_soft_world() { return soft_body_world_info; } /// Used to set some parameters to Bullet world @@ -147,6 +151,9 @@ public: void remove_area(AreaBullet *p_area); void reload_collision_filters(AreaBullet *p_area); + void register_collision_object(CollisionObjectBullet *p_object); + void unregister_collision_object(CollisionObjectBullet *p_object); + void add_rigid_body(RigidBodyBullet *p_body); void remove_rigid_body(RigidBodyBullet *p_body); void reload_collision_filters(RigidBodyBullet *p_body); diff --git a/modules/csg/csg_gizmos.h b/modules/csg/csg_gizmos.h index 48a414d9c7..83ee847caf 100644 --- a/modules/csg/csg_gizmos.h +++ b/modules/csg/csg_gizmos.h @@ -39,16 +39,16 @@ class CSGShape3DGizmoPlugin : public EditorNode3DGizmoPlugin { GDCLASS(CSGShape3DGizmoPlugin, EditorNode3DGizmoPlugin); public: - bool has_gizmo(Node3D *p_spatial); - String get_name() const; - int get_priority() const; - bool is_selectable_when_hidden() const; - void redraw(EditorNode3DGizmo *p_gizmo); - - String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const; - Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const; - void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point); - void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel); + bool has_gizmo(Node3D *p_spatial) override; + String get_name() const override; + int get_priority() const override; + bool is_selectable_when_hidden() const override; + void redraw(EditorNode3DGizmo *p_gizmo) override; + + String get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const override; + Variant get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const override; + void set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) override; + void commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) override; CSGShape3DGizmoPlugin(); }; diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h index 7e95d685c5..d93693f145 100644 --- a/modules/csg/csg_shape.h +++ b/modules/csg/csg_shape.h @@ -114,7 +114,7 @@ protected: friend class CSGCombiner3D; CSGBrush *_get_brush(); - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; public: Array get_meshes() const; @@ -124,8 +124,8 @@ public: virtual Vector<Vector3> get_brush_faces(); - virtual AABB get_aabb() const; - virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; + virtual AABB get_aabb() const override; + virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const override; void set_use_collision(bool p_enable); bool is_using_collision() const; @@ -159,7 +159,7 @@ class CSGCombiner3D : public CSGShape3D { GDCLASS(CSGCombiner3D, CSGShape3D); private: - virtual CSGBrush *_build_brush(); + virtual CSGBrush *_build_brush() override; public: CSGCombiner3D(); @@ -185,7 +185,7 @@ public: class CSGMesh3D : public CSGPrimitive3D { GDCLASS(CSGMesh3D, CSGPrimitive3D); - virtual CSGBrush *_build_brush(); + virtual CSGBrush *_build_brush() override; Ref<Mesh> mesh; Ref<Material> material; @@ -205,7 +205,7 @@ public: class CSGSphere3D : public CSGPrimitive3D { GDCLASS(CSGSphere3D, CSGPrimitive3D); - virtual CSGBrush *_build_brush(); + virtual CSGBrush *_build_brush() override; Ref<Material> material; bool smooth_faces; @@ -237,7 +237,7 @@ public: class CSGBox3D : public CSGPrimitive3D { GDCLASS(CSGBox3D, CSGPrimitive3D); - virtual CSGBrush *_build_brush(); + virtual CSGBrush *_build_brush() override; Ref<Material> material; float width; @@ -265,7 +265,7 @@ public: class CSGCylinder3D : public CSGPrimitive3D { GDCLASS(CSGCylinder3D, CSGPrimitive3D); - virtual CSGBrush *_build_brush(); + virtual CSGBrush *_build_brush() override; Ref<Material> material; float radius; @@ -301,7 +301,7 @@ public: class CSGTorus3D : public CSGPrimitive3D { GDCLASS(CSGTorus3D, CSGPrimitive3D); - virtual CSGBrush *_build_brush(); + virtual CSGBrush *_build_brush() override; Ref<Material> material; float inner_radius; @@ -352,7 +352,7 @@ public: }; private: - virtual CSGBrush *_build_brush(); + virtual CSGBrush *_build_brush() override; Vector<Vector2> polygon; Ref<Material> material; @@ -383,7 +383,7 @@ private: protected: static void _bind_methods(); - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; void _notification(int p_what); public: diff --git a/modules/denoise/lightmap_denoiser.h b/modules/denoise/lightmap_denoiser.h index 5b6e257df8..d01bbd10a5 100644 --- a/modules/denoise/lightmap_denoiser.h +++ b/modules/denoise/lightmap_denoiser.h @@ -45,7 +45,7 @@ protected: public: static LightmapDenoiser *create_oidn_denoiser(); - Ref<Image> denoise_image(const Ref<Image> &p_image); + Ref<Image> denoise_image(const Ref<Image> &p_image) override; static void make_default_denoiser(); diff --git a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml index 860da32a22..c908af7479 100644 --- a/modules/enet/doc_classes/NetworkedMultiplayerENet.xml +++ b/modules/enet/doc_classes/NetworkedMultiplayerENet.xml @@ -128,7 +128,7 @@ Enforce ordered packets when using [constant NetworkedMultiplayerPeer.TRANSFER_MODE_UNRELIABLE] (thus behaving similarly to [constant NetworkedMultiplayerPeer.TRANSFER_MODE_UNRELIABLE_ORDERED]). This is the only way to use ordering with the RPC system. </member> <member name="channel_count" type="int" setter="set_channel_count" getter="get_channel_count" default="3"> - The number of channels to be used by ENet. Channels are used to separate different kinds of data. In reliable or ordered mode, for example, the packet delivery order is ensured on a per channel basis. + The number of channels to be used by ENet. Channels are used to separate different kinds of data. In reliable or ordered mode, for example, the packet delivery order is ensured on a per-channel basis. This is done to combat latency and reduces ordering restrictions on packets. The delivery status of a packet in one channel won't stall the delivery of other packets in another channel. </member> <member name="compression_mode" type="int" setter="set_compression_mode" getter="get_compression_mode" enum="NetworkedMultiplayerENet.CompressionMode" default="0"> The compression method used for network packets. These have different tradeoffs of compression speed versus bandwidth, you may need to test which one works best for your use case if you use compression at all. @@ -141,7 +141,7 @@ Enable or disable the server feature that notifies clients of other peers' connection/disconnection, and relays messages between them. When this option is [code]false[/code], clients won't be automatically notified of other peers and won't be able to send them packets through the server. </member> <member name="transfer_channel" type="int" setter="set_transfer_channel" getter="get_transfer_channel" default="-1"> - Set the default channel to be used to transfer data. By default, this value is [code]-1[/code] which means that ENet will only use 2 channels, one for reliable and one for unreliable packets. Channel [code]0[/code] is reserved, and cannot be used. Setting this member to any value between [code]0[/code] and [member channel_count] (excluded) will force ENet to use that channel for sending data. + Set the default channel to be used to transfer data. By default, this value is [code]-1[/code] which means that ENet will only use 2 channels: one for reliable packets, and one for unreliable packets. The channel [code]0[/code] is reserved and cannot be used. Setting this member to any value between [code]0[/code] and [member channel_count] (excluded) will force ENet to use that channel for sending data. See [member channel_count] for more information about ENet channels. </member> <member name="transfer_mode" type="int" setter="set_transfer_mode" getter="get_transfer_mode" override="true" enum="NetworkedMultiplayerPeer.TransferMode" default="2" /> <member name="use_dtls" type="bool" setter="set_dtls_enabled" getter="is_dtls_enabled" default="false"> diff --git a/modules/enet/networked_multiplayer_enet.cpp b/modules/enet/networked_multiplayer_enet.cpp index 4e7698b67c..ed3924f2d2 100644 --- a/modules/enet/networked_multiplayer_enet.cpp +++ b/modules/enet/networked_multiplayer_enet.cpp @@ -640,6 +640,9 @@ int NetworkedMultiplayerENet::get_unique_id() const { void NetworkedMultiplayerENet::set_refuse_new_connections(bool p_enable) { refuse_connections = p_enable; +#ifdef GODOT_ENET + enet_host_refuse_new_connections(host, p_enable); +#endif } bool NetworkedMultiplayerENet::is_refusing_new_connections() const { diff --git a/modules/enet/networked_multiplayer_enet.h b/modules/enet/networked_multiplayer_enet.h index b2ed951327..722c7001fd 100644 --- a/modules/enet/networked_multiplayer_enet.h +++ b/modules/enet/networked_multiplayer_enet.h @@ -119,11 +119,11 @@ protected: static void _bind_methods(); public: - virtual void set_transfer_mode(TransferMode p_mode); - virtual TransferMode get_transfer_mode() const; - virtual void set_target_peer(int p_peer); + virtual void set_transfer_mode(TransferMode p_mode) override; + virtual TransferMode get_transfer_mode() const override; + virtual void set_target_peer(int p_peer) override; - virtual int get_packet_peer() const; + virtual int get_packet_peer() const override; virtual IP_Address get_peer_address(int p_peer_id) const; virtual int get_peer_port(int p_peer_id) const; @@ -135,22 +135,22 @@ public: void disconnect_peer(int p_peer, bool now = false); - virtual void poll(); + virtual void poll() override; - virtual bool is_server() const; + virtual bool is_server() const override; - virtual int get_available_packet_count() const; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const; + virtual int get_max_packet_size() const override; - virtual ConnectionStatus get_connection_status() const; + virtual ConnectionStatus get_connection_status() const override; - virtual void set_refuse_new_connections(bool p_enable); - virtual bool is_refusing_new_connections() const; + virtual void set_refuse_new_connections(bool p_enable) override; + virtual bool is_refusing_new_connections() const override; - virtual int get_unique_id() const; + virtual int get_unique_id() const override; void set_compression_mode(CompressionMode p_mode); CompressionMode get_compression_mode() const; diff --git a/modules/gdnative/gdnative/aabb.cpp b/modules/gdnative/gdnative/aabb.cpp index 7f22c7dfe3..d5970e8004 100644 --- a/modules/gdnative/gdnative/aabb.cpp +++ b/modules/gdnative/gdnative/aabb.cpp @@ -81,6 +81,13 @@ godot_string GDAPI godot_aabb_as_string(const godot_aabb *p_self) { return ret; } +godot_aabb GDAPI godot_aabb_abs(const godot_aabb *p_self) { + godot_aabb dest; + const AABB *self = (const AABB *)p_self; + *((AABB *)&dest) = self->abs(); + return dest; +} + godot_real GDAPI godot_aabb_get_area(const godot_aabb *p_self) { const AABB *self = (const AABB *)p_self; return self->get_area(); diff --git a/modules/gdnative/gdnative/packed_arrays.cpp b/modules/gdnative/gdnative/packed_arrays.cpp index fc71d50289..de93c1d9b3 100644 --- a/modules/gdnative/gdnative/packed_arrays.cpp +++ b/modules/gdnative/gdnative/packed_arrays.cpp @@ -104,6 +104,16 @@ godot_error GDAPI godot_packed_byte_array_insert(godot_packed_byte_array *p_self return (godot_error)self->insert(p_idx, p_data); } +godot_bool GDAPI godot_packed_byte_array_has(godot_packed_byte_array *p_self, const uint8_t p_value) { + Vector<uint8_t> *self = (Vector<uint8_t> *)p_self; + return (godot_bool)self->has(p_value); +} + +void GDAPI godot_packed_byte_array_sort(godot_packed_byte_array *p_self) { + Vector<uint8_t> *self = (Vector<uint8_t> *)p_self; + self->sort(); +} + void GDAPI godot_packed_byte_array_invert(godot_packed_byte_array *p_self) { Vector<uint8_t> *self = (Vector<uint8_t> *)p_self; self->invert(); @@ -198,6 +208,16 @@ godot_error GDAPI godot_packed_int32_array_insert(godot_packed_int32_array *p_se return (godot_error)self->insert(p_idx, p_data); } +godot_bool GDAPI godot_packed_int32_array_has(godot_packed_int32_array *p_self, const int32_t p_value) { + Vector<int32_t> *self = (Vector<int32_t> *)p_self; + return (godot_bool)self->has(p_value); +} + +void GDAPI godot_packed_int32_array_sort(godot_packed_int32_array *p_self) { + Vector<int32_t> *self = (Vector<int32_t> *)p_self; + self->sort(); +} + void GDAPI godot_packed_int32_array_invert(godot_packed_int32_array *p_self) { Vector<int32_t> *self = (Vector<int32_t> *)p_self; self->invert(); @@ -292,6 +312,16 @@ godot_error GDAPI godot_packed_int64_array_insert(godot_packed_int64_array *p_se return (godot_error)self->insert(p_idx, p_data); } +godot_bool GDAPI godot_packed_int64_array_has(godot_packed_int64_array *p_self, const int64_t p_value) { + Vector<int64_t> *self = (Vector<int64_t> *)p_self; + return (godot_bool)self->has(p_value); +} + +void GDAPI godot_packed_int64_array_sort(godot_packed_int64_array *p_self) { + Vector<int64_t> *self = (Vector<int64_t> *)p_self; + self->sort(); +} + void GDAPI godot_packed_int64_array_invert(godot_packed_int64_array *p_self) { Vector<int64_t> *self = (Vector<int64_t> *)p_self; self->invert(); @@ -386,6 +416,16 @@ godot_error GDAPI godot_packed_float32_array_insert(godot_packed_float32_array * return (godot_error)self->insert(p_idx, p_data); } +godot_bool GDAPI godot_packed_float32_array_has(godot_packed_float32_array *p_self, const float p_value) { + Vector<float> *self = (Vector<float> *)p_self; + return (godot_bool)self->has(p_value); +} + +void GDAPI godot_packed_float32_array_sort(godot_packed_float32_array *p_self) { + Vector<float> *self = (Vector<float> *)p_self; + self->sort(); +} + void GDAPI godot_packed_float32_array_invert(godot_packed_float32_array *p_self) { Vector<float> *self = (Vector<float> *)p_self; self->invert(); @@ -480,6 +520,16 @@ godot_error GDAPI godot_packed_float64_array_insert(godot_packed_float64_array * return (godot_error)self->insert(p_idx, p_data); } +godot_bool GDAPI godot_packed_float64_array_has(godot_packed_float64_array *p_self, const double p_value) { + Vector<double> *self = (Vector<double> *)p_self; + return (godot_bool)self->has(p_value); +} + +void GDAPI godot_packed_float64_array_sort(godot_packed_float64_array *p_self) { + Vector<double> *self = (Vector<double> *)p_self; + self->sort(); +} + void GDAPI godot_packed_float64_array_invert(godot_packed_float64_array *p_self) { Vector<double> *self = (Vector<double> *)p_self; self->invert(); @@ -576,6 +626,17 @@ godot_error GDAPI godot_packed_string_array_insert(godot_packed_string_array *p_ return (godot_error)self->insert(p_idx, s); } +godot_bool GDAPI godot_packed_string_array_has(godot_packed_string_array *p_self, const godot_string *p_value) { + Vector<String> *self = (Vector<String> *)p_self; + String &s = *(String *)p_value; + return (godot_bool)self->has(s); +} + +void GDAPI godot_packed_string_array_sort(godot_packed_string_array *p_self) { + Vector<String> *self = (Vector<String> *)p_self; + self->sort(); +} + void GDAPI godot_packed_string_array_invert(godot_packed_string_array *p_self) { Vector<String> *self = (Vector<String> *)p_self; self->invert(); @@ -678,6 +739,17 @@ godot_error GDAPI godot_packed_vector2_array_insert(godot_packed_vector2_array * return (godot_error)self->insert(p_idx, s); } +godot_bool GDAPI godot_packed_vector2_array_has(godot_packed_vector2_array *p_self, const godot_vector2 *p_value) { + Vector<Vector2> *self = (Vector<Vector2> *)p_self; + Vector2 &v = *(Vector2 *)p_value; + return (godot_bool)self->has(v); +} + +void GDAPI godot_packed_vector2_array_sort(godot_packed_vector2_array *p_self) { + Vector<Vector2> *self = (Vector<Vector2> *)p_self; + self->sort(); +} + void GDAPI godot_packed_vector2_array_invert(godot_packed_vector2_array *p_self) { Vector<Vector2> *self = (Vector<Vector2> *)p_self; self->invert(); @@ -779,6 +851,17 @@ godot_error GDAPI godot_packed_vector3_array_insert(godot_packed_vector3_array * return (godot_error)self->insert(p_idx, s); } +godot_bool GDAPI godot_packed_vector3_array_has(godot_packed_vector3_array *p_self, const godot_vector3 *p_value) { + Vector<Vector3> *self = (Vector<Vector3> *)p_self; + Vector3 &v = *(Vector3 *)p_value; + return (godot_bool)self->has(v); +} + +void GDAPI godot_packed_vector3_array_sort(godot_packed_vector3_array *p_self) { + Vector<Vector3> *self = (Vector<Vector3> *)p_self; + self->sort(); +} + void GDAPI godot_packed_vector3_array_invert(godot_packed_vector3_array *p_self) { Vector<Vector3> *self = (Vector<Vector3> *)p_self; self->invert(); @@ -880,6 +963,17 @@ godot_error GDAPI godot_packed_color_array_insert(godot_packed_color_array *p_se return (godot_error)self->insert(p_idx, s); } +godot_bool GDAPI godot_packed_color_array_has(godot_packed_color_array *p_self, const godot_color *p_value) { + Vector<Color> *self = (Vector<Color> *)p_self; + Color &c = *(Color *)p_value; + return (godot_bool)self->has(c); +} + +void GDAPI godot_packed_color_array_sort(godot_packed_color_array *p_self) { + Vector<Color> *self = (Vector<Color> *)p_self; + self->sort(); +} + void GDAPI godot_packed_color_array_invert(godot_packed_color_array *p_self) { Vector<Color> *self = (Vector<Color> *)p_self; self->invert(); diff --git a/modules/gdnative/gdnative/plane.cpp b/modules/gdnative/gdnative/plane.cpp index 663937f906..d4ed8d00f4 100644 --- a/modules/gdnative/gdnative/plane.cpp +++ b/modules/gdnative/gdnative/plane.cpp @@ -79,13 +79,6 @@ godot_vector3 GDAPI godot_plane_center(const godot_plane *p_self) { return dest; } -godot_vector3 GDAPI godot_plane_get_any_point(const godot_plane *p_self) { - godot_vector3 dest; - const Plane *self = (const Plane *)p_self; - *((Vector3 *)&dest) = self->get_any_point(); - return dest; -} - godot_bool GDAPI godot_plane_is_point_over(const godot_plane *p_self, const godot_vector3 *p_point) { const Plane *self = (const Plane *)p_self; const Vector3 *point = (const Vector3 *)p_point; diff --git a/modules/gdnative/gdnative/string.cpp b/modules/gdnative/gdnative/string.cpp index f89f647aca..8b0c7474e8 100644 --- a/modules/gdnative/gdnative/string.cpp +++ b/modules/gdnative/gdnative/string.cpp @@ -277,13 +277,6 @@ godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string return self->findn(*what, p_from); } -godot_int GDAPI godot_string_find_last(const godot_string *p_self, godot_string p_what) { - const String *self = (const String *)p_self; - String *what = (String *)&p_what; - - return self->find_last(*what); -} - godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values) { const String *self = (const String *)p_self; const Variant *values = (const Variant *)p_values; diff --git a/modules/gdnative/gdnative_api.json b/modules/gdnative/gdnative_api.json index ccd8d2041c..9852928d22 100644 --- a/modules/gdnative/gdnative_api.json +++ b/modules/gdnative/gdnative_api.json @@ -54,6 +54,13 @@ ] }, { + "name": "godot_aabb_abs", + "return_type": "godot_aabb", + "arguments": [ + ["const godot_aabb *", "p_self"] + ] + }, + { "name": "godot_aabb_get_area", "return_type": "godot_real", "arguments": [ @@ -918,42 +925,42 @@ ["const godot_variant **", "p_arguments"], ["godot_int", "p_argcount"] ] - }, + }, { "name": "godot_callable_is_null", "return_type": "godot_bool", "arguments": [ ["const godot_callable *", "p_self"] ] - }, + }, { "name": "godot_callable_is_custom", "return_type": "godot_bool", "arguments": [ ["const godot_callable *", "p_self"] ] - }, + }, { "name": "godot_callable_is_standard", "return_type": "godot_bool", "arguments": [ ["const godot_callable *", "p_self"] ] - }, + }, { "name": "godot_callable_get_object", "return_type": "godot_object *", "arguments": [ ["const godot_callable *", "p_self"] ] - }, + }, { "name": "godot_callable_get_object_id", "return_type": "uint64_t", "arguments": [ ["const godot_callable *", "p_self"] ] - }, + }, { "name": "godot_callable_get_method", "return_type": "godot_string_name", @@ -1093,14 +1100,14 @@ "arguments": [ ["const godot_signal *", "p_self"] ] - }, + }, { "name": "godot_signal_as_string", "return_type": "godot_string", "arguments": [ ["const godot_signal *", "p_self"] ] - }, + }, { "name": "godot_signal_operator_equal", "return_type": "godot_bool", @@ -1108,7 +1115,7 @@ ["const godot_signal *", "p_self"], ["const godot_signal *", "p_other"] ] - }, + }, { "name": "godot_signal_operator_less", "return_type": "godot_bool", @@ -1671,6 +1678,21 @@ ] }, { + "name": "godot_packed_byte_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_byte_array *", "p_self"], + ["const uint8_t", "p_value"] + ] + }, + { + "name": "godot_packed_byte_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_byte_array *", "p_self"] + ] + }, + { "name": "godot_packed_byte_array_invert", "return_type": "void", "arguments": [ @@ -1802,6 +1824,21 @@ ] }, { + "name": "godot_packed_int32_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_int32_array *", "p_self"], + ["const int32_t", "p_value"] + ] + }, + { + "name": "godot_packed_int32_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_int32_array *", "p_self"] + ] + }, + { "name": "godot_packed_int32_array_invert", "return_type": "void", "arguments": [ @@ -1933,6 +1970,21 @@ ] }, { + "name": "godot_packed_int64_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_int64_array *", "p_self"], + ["const int64_t", "p_value"] + ] + }, + { + "name": "godot_packed_int64_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_int64_array *", "p_self"] + ] + }, + { "name": "godot_packed_int64_array_invert", "return_type": "void", "arguments": [ @@ -2064,6 +2116,21 @@ ] }, { + "name": "godot_packed_float32_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_float32_array *", "p_self"], + ["const float", "p_value"] + ] + }, + { + "name": "godot_packed_float32_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_float32_array *", "p_self"] + ] + }, + { "name": "godot_packed_float32_array_invert", "return_type": "void", "arguments": [ @@ -2195,6 +2262,21 @@ ] }, { + "name": "godot_packed_float64_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_float64_array *", "p_self"], + ["const double", "p_value"] + ] + }, + { + "name": "godot_packed_float64_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_float64_array *", "p_self"] + ] + }, + { "name": "godot_packed_float64_array_invert", "return_type": "void", "arguments": [ @@ -2326,6 +2408,21 @@ ] }, { + "name": "godot_packed_string_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_string_array *", "p_self"], + ["const godot_string *", "p_value"] + ] + }, + { + "name": "godot_packed_string_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_string_array *", "p_self"] + ] + }, + { "name": "godot_packed_string_array_invert", "return_type": "void", "arguments": [ @@ -2457,6 +2554,21 @@ ] }, { + "name": "godot_packed_vector2_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_vector2_array *", "p_self"], + ["const godot_vector2 *", "p_value"] + ] + }, + { + "name": "godot_packed_vector2_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_vector2_array *", "p_self"] + ] + }, + { "name": "godot_packed_vector2_array_invert", "return_type": "void", "arguments": [ @@ -2588,6 +2700,21 @@ ] }, { + "name": "godot_packed_vector3_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_vector3_array *", "p_self"], + ["const godot_vector3 *", "p_value"] + ] + }, + { + "name": "godot_packed_vector3_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_vector3_array *", "p_self"] + ] + }, + { "name": "godot_packed_vector3_array_invert", "return_type": "void", "arguments": [ @@ -2719,6 +2846,21 @@ ] }, { + "name": "godot_packed_color_array_has", + "return_type": "godot_bool", + "arguments": [ + ["godot_packed_color_array *", "p_self"], + ["const godot_color *", "p_value"] + ] + }, + { + "name": "godot_packed_color_array_sort", + "return_type": "void", + "arguments": [ + ["godot_packed_color_array *", "p_self"] + ] + }, + { "name": "godot_packed_color_array_invert", "return_type": "void", "arguments": [ @@ -2748,7 +2890,7 @@ ["godot_packed_color_array *", "p_self"], ["const godot_int", "p_size"] ] - }, + }, { "name": "godot_packed_color_array_ptr", "return_type": "const godot_color *", @@ -2846,13 +2988,6 @@ ] }, { - "name": "godot_plane_get_any_point", - "return_type": "godot_vector3", - "arguments": [ - ["const godot_plane *", "p_self"] - ] - }, - { "name": "godot_plane_is_point_over", "return_type": "godot_bool", "arguments": [ @@ -3825,14 +3960,6 @@ ] }, { - "name": "godot_string_find_last", - "return_type": "godot_int", - "arguments": [ - ["const godot_string *", "p_self"], - ["godot_string", "p_what"] - ] - }, - { "name": "godot_string_format", "return_type": "godot_string", "arguments": [ @@ -5471,7 +5598,7 @@ ["godot_variant *", "r_dest"], ["const godot_packed_int64_array *", "p_pia"] ] - }, + }, { "name": "godot_variant_new_packed_float32_array", "return_type": "void", diff --git a/modules/gdnative/gdnative_library_editor_plugin.cpp b/modules/gdnative/gdnative_library_editor_plugin.cpp index 1d4d188f23..fdd755845f 100644 --- a/modules/gdnative/gdnative_library_editor_plugin.cpp +++ b/modules/gdnative/gdnative_library_editor_plugin.cpp @@ -146,7 +146,7 @@ void GDNativeLibraryEditor::_on_item_button(Object *item, int column, int id) { } file_dialog->set_file_mode(mode); - file_dialog->popup_centered_ratio(); + file_dialog->popup_file_dialog(); } else if (id == BUTTON_CLEAR_LIBRARY) { _set_target_value(section, target, ""); diff --git a/modules/gdnative/gdnative_library_editor_plugin.h b/modules/gdnative/gdnative_library_editor_plugin.h index 5fdb860ca3..180ab7707c 100644 --- a/modules/gdnative/gdnative_library_editor_plugin.h +++ b/modules/gdnative/gdnative_library_editor_plugin.h @@ -100,11 +100,11 @@ class GDNativeLibraryEditorPlugin : public EditorPlugin { Button *button; public: - virtual String get_name() const { return "GDNativeLibrary"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_node); - virtual bool handles(Object *p_node) const; - virtual void make_visible(bool p_visible); + virtual String get_name() const override { return "GDNativeLibrary"; } + bool has_main_screen() const override { return false; } + virtual void edit(Object *p_node) override; + virtual bool handles(Object *p_node) const override; + virtual void make_visible(bool p_visible) override; GDNativeLibraryEditorPlugin(EditorNode *p_node); }; diff --git a/modules/gdnative/include/gdnative/aabb.h b/modules/gdnative/include/gdnative/aabb.h index 9f41e9d4c6..c776297944 100644 --- a/modules/gdnative/include/gdnative/aabb.h +++ b/modules/gdnative/include/gdnative/aabb.h @@ -69,6 +69,8 @@ void GDAPI godot_aabb_set_size(const godot_aabb *p_self, const godot_vector3 *p_ godot_string GDAPI godot_aabb_as_string(const godot_aabb *p_self); +godot_aabb GDAPI godot_aabb_abs(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); diff --git a/modules/gdnative/include/gdnative/packed_arrays.h b/modules/gdnative/include/gdnative/packed_arrays.h index 87d467a5b8..6a1727d76f 100644 --- a/modules/gdnative/include/gdnative/packed_arrays.h +++ b/modules/gdnative/include/gdnative/packed_arrays.h @@ -167,6 +167,10 @@ void GDAPI godot_packed_byte_array_append_array(godot_packed_byte_array *p_self, godot_error GDAPI godot_packed_byte_array_insert(godot_packed_byte_array *p_self, const godot_int p_idx, const uint8_t p_data); +godot_bool GDAPI godot_packed_byte_array_has(godot_packed_byte_array *p_self, const uint8_t p_value); + +void GDAPI godot_packed_byte_array_sort(godot_packed_byte_array *p_self); + void GDAPI godot_packed_byte_array_invert(godot_packed_byte_array *p_self); void GDAPI godot_packed_byte_array_push_back(godot_packed_byte_array *p_self, const uint8_t p_data); @@ -199,6 +203,10 @@ void GDAPI godot_packed_int32_array_append_array(godot_packed_int32_array *p_sel godot_error GDAPI godot_packed_int32_array_insert(godot_packed_int32_array *p_self, const godot_int p_idx, const int32_t p_data); +godot_bool GDAPI godot_packed_int32_array_has(godot_packed_int32_array *p_self, const int32_t p_value); + +void GDAPI godot_packed_int32_array_sort(godot_packed_int32_array *p_self); + void GDAPI godot_packed_int32_array_invert(godot_packed_int32_array *p_self); void GDAPI godot_packed_int32_array_push_back(godot_packed_int32_array *p_self, const int32_t p_data); @@ -231,6 +239,10 @@ void GDAPI godot_packed_int64_array_append_array(godot_packed_int64_array *p_sel godot_error GDAPI godot_packed_int64_array_insert(godot_packed_int64_array *p_self, const godot_int p_idx, const int64_t p_data); +godot_bool GDAPI godot_packed_int64_array_has(godot_packed_int64_array *p_self, const int64_t p_value); + +void GDAPI godot_packed_int64_array_sort(godot_packed_int64_array *p_self); + void GDAPI godot_packed_int64_array_invert(godot_packed_int64_array *p_self); void GDAPI godot_packed_int64_array_push_back(godot_packed_int64_array *p_self, const int64_t p_data); @@ -263,6 +275,10 @@ void GDAPI godot_packed_float32_array_append_array(godot_packed_float32_array *p godot_error GDAPI godot_packed_float32_array_insert(godot_packed_float32_array *p_self, const godot_int p_idx, const float p_data); +godot_bool GDAPI godot_packed_float32_array_has(godot_packed_float32_array *p_self, const float p_value); + +void GDAPI godot_packed_float32_array_sort(godot_packed_float32_array *p_self); + void GDAPI godot_packed_float32_array_invert(godot_packed_float32_array *p_self); void GDAPI godot_packed_float32_array_push_back(godot_packed_float32_array *p_self, const float p_data); @@ -295,6 +311,10 @@ void GDAPI godot_packed_float64_array_append_array(godot_packed_float64_array *p godot_error GDAPI godot_packed_float64_array_insert(godot_packed_float64_array *p_self, const godot_int p_idx, const double p_data); +godot_bool GDAPI godot_packed_float64_array_has(godot_packed_float64_array *p_self, const double p_value); + +void GDAPI godot_packed_float64_array_sort(godot_packed_float64_array *p_self); + void GDAPI godot_packed_float64_array_invert(godot_packed_float64_array *p_self); void GDAPI godot_packed_float64_array_push_back(godot_packed_float64_array *p_self, const double p_data); @@ -327,6 +347,10 @@ void GDAPI godot_packed_string_array_append_array(godot_packed_string_array *p_s godot_error GDAPI godot_packed_string_array_insert(godot_packed_string_array *p_self, const godot_int p_idx, const godot_string *p_data); +godot_bool GDAPI godot_packed_string_array_has(godot_packed_string_array *p_self, const godot_string *p_value); + +void GDAPI godot_packed_string_array_sort(godot_packed_string_array *p_self); + void GDAPI godot_packed_string_array_invert(godot_packed_string_array *p_self); void GDAPI godot_packed_string_array_push_back(godot_packed_string_array *p_self, const godot_string *p_data); @@ -359,6 +383,10 @@ void GDAPI godot_packed_vector2_array_append_array(godot_packed_vector2_array *p godot_error GDAPI godot_packed_vector2_array_insert(godot_packed_vector2_array *p_self, const godot_int p_idx, const godot_vector2 *p_data); +godot_bool GDAPI godot_packed_vector2_array_has(godot_packed_vector2_array *p_self, const godot_vector2 *p_value); + +void GDAPI godot_packed_vector2_array_sort(godot_packed_vector2_array *p_self); + void GDAPI godot_packed_vector2_array_invert(godot_packed_vector2_array *p_self); void GDAPI godot_packed_vector2_array_push_back(godot_packed_vector2_array *p_self, const godot_vector2 *p_data); @@ -391,6 +419,10 @@ void GDAPI godot_packed_vector3_array_append_array(godot_packed_vector3_array *p godot_error GDAPI godot_packed_vector3_array_insert(godot_packed_vector3_array *p_self, const godot_int p_idx, const godot_vector3 *p_data); +godot_bool GDAPI godot_packed_vector3_array_has(godot_packed_vector3_array *p_self, const godot_vector3 *p_value); + +void GDAPI godot_packed_vector3_array_sort(godot_packed_vector3_array *p_self); + void GDAPI godot_packed_vector3_array_invert(godot_packed_vector3_array *p_self); void GDAPI godot_packed_vector3_array_push_back(godot_packed_vector3_array *p_self, const godot_vector3 *p_data); @@ -423,6 +455,10 @@ void GDAPI godot_packed_color_array_append_array(godot_packed_color_array *p_sel godot_error GDAPI godot_packed_color_array_insert(godot_packed_color_array *p_self, const godot_int p_idx, const godot_color *p_data); +godot_bool GDAPI godot_packed_color_array_has(godot_packed_color_array *p_self, const godot_color *p_value); + +void GDAPI godot_packed_color_array_sort(godot_packed_color_array *p_self); + void GDAPI godot_packed_color_array_invert(godot_packed_color_array *p_self); void GDAPI godot_packed_color_array_push_back(godot_packed_color_array *p_self, const godot_color *p_data); diff --git a/modules/gdnative/include/gdnative/plane.h b/modules/gdnative/include/gdnative/plane.h index b759a8cc1a..9843056489 100644 --- a/modules/gdnative/include/gdnative/plane.h +++ b/modules/gdnative/include/gdnative/plane.h @@ -68,8 +68,6 @@ godot_plane GDAPI godot_plane_normalized(const godot_plane *p_self); godot_vector3 GDAPI godot_plane_center(const godot_plane *p_self); -godot_vector3 GDAPI godot_plane_get_any_point(const godot_plane *p_self); - godot_bool GDAPI godot_plane_is_point_over(const godot_plane *p_self, const godot_vector3 *p_point); godot_real GDAPI godot_plane_distance_to(const godot_plane *p_self, const godot_vector3 *p_point); diff --git a/modules/gdnative/include/gdnative/string.h b/modules/gdnative/include/gdnative/string.h index 608978db76..dfd4fcab89 100644 --- a/modules/gdnative/include/gdnative/string.h +++ b/modules/gdnative/include/gdnative/string.h @@ -111,7 +111,6 @@ godot_int GDAPI godot_string_findmk_from(const godot_string *p_self, const godot godot_int GDAPI godot_string_findmk_from_in_place(const godot_string *p_self, const godot_array *p_keys, godot_int p_from, godot_int *r_key); godot_int GDAPI godot_string_findn(const godot_string *p_self, godot_string p_what); godot_int GDAPI godot_string_findn_from(const godot_string *p_self, godot_string p_what, godot_int p_from); -godot_int GDAPI godot_string_find_last(const godot_string *p_self, godot_string p_what); godot_string GDAPI godot_string_format(const godot_string *p_self, const godot_variant *p_values); godot_string GDAPI godot_string_format_with_custom_placeholder(const godot_string *p_self, const godot_variant *p_values, const char *p_placeholder); godot_string GDAPI godot_string_hex_encode_buffer(const uint8_t *p_buffer, godot_int p_len); diff --git a/modules/gdnative/nativescript/api_generator.cpp b/modules/gdnative/nativescript/api_generator.cpp index 62f2ec5024..019fa0d1f8 100644 --- a/modules/gdnative/nativescript/api_generator.cpp +++ b/modules/gdnative/nativescript/api_generator.cpp @@ -139,7 +139,7 @@ static String get_type_name(const PropertyInfo &info) { } /* - * Some comparison helper functions we need + * Some comparison helper functions we need */ struct MethodInfoComparator { @@ -214,7 +214,7 @@ List<ClassAPI> generate_c_api_classes() { { List<StringName> inheriters; ClassDB::get_inheriters_from_class("Reference", &inheriters); - bool is_reference = !!inheriters.find(class_name); + bool is_reference = !!inheriters.find(class_name) || class_name == "Reference"; // @Unclear class_api.is_reference = !class_api.is_singleton && is_reference; } @@ -452,6 +452,7 @@ static List<String> generate_c_api_json(const List<ClassAPI> &p_api) { source.push_back("\t\t\t\t\t{\n"); source.push_back("\t\t\t\t\t\t\"name\": \"" + e->get().argument_names[i] + "\",\n"); source.push_back("\t\t\t\t\t\t\"type\": \"" + e->get().argument_types[i] + "\",\n"); + source.push_back(String("\t\t\t\t\t\t\"has_default_value\": ") + (e->get().default_arguments.has(i) ? "true" : "false") + ",\n"); source.push_back("\t\t\t\t\t\t\"default_value\": \"" + (e->get().default_arguments.has(i) ? (String)e->get().default_arguments[i] : "") + "\"\n"); source.push_back(String("\t\t\t\t\t}") + ((i < e->get().argument_names.size() - 1) ? "," : "") + "\n"); } diff --git a/modules/gdnative/nativescript/nativescript.h b/modules/gdnative/nativescript/nativescript.h index fabf4bb87e..e709ce2337 100644 --- a/modules/gdnative/nativescript/nativescript.h +++ b/modules/gdnative/nativescript/nativescript.h @@ -99,7 +99,7 @@ class NativeScript : public Script { #ifdef TOOLS_ENABLED Set<PlaceHolderScriptInstance *> placeholders; void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); - virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; #endif friend class NativeScriptInstance; @@ -125,7 +125,7 @@ protected: public: inline NativeScriptDesc *get_script_desc() const; - bool inherits_script(const Ref<Script> &p_script) const; + bool inherits_script(const Ref<Script> &p_script) const override; void set_class_name(String p_class_name); String get_class_name() const; @@ -138,48 +138,48 @@ public: void set_script_class_icon_path(String p_icon_path); String get_script_class_icon_path() const; - virtual bool can_instance() const; + virtual bool can_instance() const override; - virtual Ref<Script> get_base_script() const; //for script inheritance + virtual Ref<Script> get_base_script() const override; //for script inheritance - virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so - virtual ScriptInstance *instance_create(Object *p_this); - virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this); - virtual bool instance_has(const Object *p_this) const; + virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so + virtual ScriptInstance *instance_create(Object *p_this) override; + virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override; + virtual bool instance_has(const Object *p_this) const override; - virtual bool has_source_code() const; - virtual String get_source_code() const; - virtual void set_source_code(const String &p_code); - virtual Error reload(bool p_keep_state = false); + virtual bool has_source_code() const override; + virtual String get_source_code() const override; + virtual void set_source_code(const String &p_code) override; + virtual Error reload(bool p_keep_state = false) override; - virtual bool has_method(const StringName &p_method) const; - virtual MethodInfo get_method_info(const StringName &p_method) const; + virtual bool has_method(const StringName &p_method) const override; + virtual MethodInfo get_method_info(const StringName &p_method) const override; - virtual bool is_tool() const; - virtual bool is_valid() const; + virtual bool is_tool() const override; + virtual bool is_valid() const override; - virtual ScriptLanguage *get_language() const; + virtual ScriptLanguage *get_language() const override; - virtual bool has_script_signal(const StringName &p_signal) const; - virtual void get_script_signal_list(List<MethodInfo> *r_signals) const; + virtual bool has_script_signal(const StringName &p_signal) const override; + virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override; - virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const; + virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const override; - virtual void update_exports(); //editor tool - virtual void get_script_method_list(List<MethodInfo> *p_list) const; - virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + virtual void update_exports() override; //editor tool + virtual void get_script_method_list(List<MethodInfo> *p_list) const override; + virtual void get_script_property_list(List<PropertyInfo> *p_list) const override; - virtual Vector<ScriptNetData> get_rpc_methods() const; - virtual uint16_t get_rpc_method_id(const StringName &p_method) const; - virtual StringName get_rpc_method(uint16_t p_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(uint16_t p_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const; + virtual Vector<ScriptNetData> get_rpc_methods() const override; + virtual uint16_t get_rpc_method_id(const StringName &p_method) const override; + virtual StringName get_rpc_method(uint16_t p_id) const override; + virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(uint16_t p_id) const override; + virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const override; - virtual Vector<ScriptNetData> get_rset_properties() const; - virtual uint16_t get_rset_property_id(const StringName &p_variable) const; - virtual StringName get_rset_property(uint16_t p_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(uint16_t p_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const; + virtual Vector<ScriptNetData> get_rset_properties() const override; + virtual uint16_t get_rset_property_id(const StringName &p_variable) const override; + virtual StringName get_rset_property(uint16_t p_id) const override; + virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(uint16_t p_id) const override; + virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const override; String get_class_documentation() const; String get_method_documentation(const StringName &p_method) const; diff --git a/modules/gdnative/net/multiplayer_peer_gdnative.h b/modules/gdnative/net/multiplayer_peer_gdnative.h index cfaf14936e..64d764029f 100644 --- a/modules/gdnative/net/multiplayer_peer_gdnative.h +++ b/modules/gdnative/net/multiplayer_peer_gdnative.h @@ -50,28 +50,28 @@ public: void set_native_multiplayer_peer(const godot_net_multiplayer_peer *p_impl); /* Specific to PacketPeer */ - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); - virtual int get_max_packet_size() const; - virtual int get_available_packet_count() const; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; + virtual int get_max_packet_size() const override; + virtual int get_available_packet_count() const override; /* Specific to NetworkedMultiplayerPeer */ - virtual void set_transfer_mode(TransferMode p_mode); - virtual TransferMode get_transfer_mode() const; - virtual void set_target_peer(int p_peer_id); + virtual void set_transfer_mode(TransferMode p_mode) override; + virtual TransferMode get_transfer_mode() const override; + virtual void set_target_peer(int p_peer_id) override; - virtual int get_packet_peer() const; + virtual int get_packet_peer() const override; - virtual bool is_server() const; + virtual bool is_server() const override; - virtual void poll(); + virtual void poll() override; - virtual int get_unique_id() const; + virtual int get_unique_id() const override; - virtual void set_refuse_new_connections(bool p_enable); - virtual bool is_refusing_new_connections() const; + virtual void set_refuse_new_connections(bool p_enable) override; + virtual bool is_refusing_new_connections() const override; - virtual ConnectionStatus get_connection_status() const; + virtual ConnectionStatus get_connection_status() const override; }; #endif // MULTIPLAYER_PEER_GDNATIVE_H diff --git a/modules/gdnative/net/packet_peer_gdnative.h b/modules/gdnative/net/packet_peer_gdnative.h index 78d8bb32b6..00de8f7f4c 100644 --- a/modules/gdnative/net/packet_peer_gdnative.h +++ b/modules/gdnative/net/packet_peer_gdnative.h @@ -50,10 +50,10 @@ public: void set_native_packet_peer(const godot_net_packet_peer *p_impl); /* Specific to PacketPeer */ - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); - virtual int get_max_packet_size() const; - virtual int get_available_packet_count() const; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; + virtual int get_max_packet_size() const override; + virtual int get_available_packet_count() const override; }; #endif // PACKET_PEER_GDNATIVE_H diff --git a/modules/gdnative/net/stream_peer_gdnative.h b/modules/gdnative/net/stream_peer_gdnative.h index 0b2f995aa7..302fb48012 100644 --- a/modules/gdnative/net/stream_peer_gdnative.h +++ b/modules/gdnative/net/stream_peer_gdnative.h @@ -50,11 +50,11 @@ public: void set_native_stream_peer(const godot_net_stream_peer *p_interface); /* Specific to StreamPeer */ - Error put_data(const uint8_t *p_data, int p_bytes); - Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent); - Error get_data(uint8_t *p_buffer, int p_bytes); - Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received); - int get_available_bytes() const; + Error put_data(const uint8_t *p_data, int p_bytes) override; + Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent) override; + Error get_data(uint8_t *p_buffer, int p_bytes) override; + Error get_partial_data(uint8_t *p_buffer, int p_bytes, int &r_received) override; + int get_available_bytes() const override; }; #endif // STREAM_PEER_GDNATIVE_H diff --git a/modules/gdnative/pluginscript/pluginscript_script.h b/modules/gdnative/pluginscript/pluginscript_script.h index 659289ef9b..9cd38cd4b4 100644 --- a/modules/gdnative/pluginscript/pluginscript_script.h +++ b/modules/gdnative/pluginscript/pluginscript_script.h @@ -71,7 +71,7 @@ private: protected: static void _bind_methods(); - bool inherits_script(const Ref<Script> &p_script) const; + bool inherits_script(const Ref<Script> &p_script) const override; PluginScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Callable::CallError &r_error); Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error); @@ -79,57 +79,57 @@ protected: #ifdef TOOLS_ENABLED Set<PlaceHolderScriptInstance *> placeholders; //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); - virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; #endif public: - virtual bool can_instance() const; + virtual bool can_instance() const override; - virtual Ref<Script> get_base_script() const; //for script inheritance + virtual Ref<Script> get_base_script() const override; //for script inheritance - virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so - virtual ScriptInstance *instance_create(Object *p_this); - virtual bool instance_has(const Object *p_this) const; + virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so + virtual ScriptInstance *instance_create(Object *p_this) override; + virtual bool instance_has(const Object *p_this) const override; - virtual bool has_source_code() const; - virtual String get_source_code() const; - virtual void set_source_code(const String &p_code); - virtual Error reload(bool p_keep_state = false); + virtual bool has_source_code() const override; + virtual String get_source_code() const override; + virtual void set_source_code(const String &p_code) override; + virtual Error reload(bool p_keep_state = false) override; // TODO: load_source_code only allow utf-8 file, should handle bytecode as well ? virtual Error load_source_code(const String &p_path); - virtual bool has_method(const StringName &p_method) const; - virtual MethodInfo get_method_info(const StringName &p_method) const; + virtual bool has_method(const StringName &p_method) const override; + virtual MethodInfo get_method_info(const StringName &p_method) const override; bool has_property(const StringName &p_method) const; PropertyInfo get_property_info(const StringName &p_property) const; - bool is_tool() const { return _tool; } - bool is_valid() const { return true; } + bool is_tool() const override { return _tool; } + bool is_valid() const override { return true; } - virtual ScriptLanguage *get_language() const; + virtual ScriptLanguage *get_language() const override; - virtual bool has_script_signal(const StringName &p_signal) const; - virtual void get_script_signal_list(List<MethodInfo> *r_signals) const; + virtual bool has_script_signal(const StringName &p_signal) const override; + virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override; - virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const; + virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const override; - virtual void update_exports(); - virtual void get_script_method_list(List<MethodInfo> *r_methods) const; - virtual void get_script_property_list(List<PropertyInfo> *r_properties) const; + virtual void update_exports() override; + virtual void get_script_method_list(List<MethodInfo> *r_methods) const override; + virtual void get_script_property_list(List<PropertyInfo> *r_properties) const override; - virtual int get_member_line(const StringName &p_member) const; + virtual int get_member_line(const StringName &p_member) const override; - virtual Vector<ScriptNetData> get_rpc_methods() const; - virtual uint16_t get_rpc_method_id(const StringName &p_method) const; - virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const; + virtual Vector<ScriptNetData> get_rpc_methods() const override; + virtual uint16_t get_rpc_method_id(const StringName &p_method) const override; + virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const override; + virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const override; + virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const override; - virtual Vector<ScriptNetData> get_rset_properties() const; - virtual uint16_t get_rset_property_id(const StringName &p_property) const; - virtual StringName get_rset_property(const uint16_t p_rset_property_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const; + virtual Vector<ScriptNetData> get_rset_properties() const override; + virtual uint16_t get_rset_property_id(const StringName &p_property) const override; + virtual StringName get_rset_property(const uint16_t p_rset_property_id) const override; + virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const override; + virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const override; PluginScript(); void init(PluginScriptLanguage *language); diff --git a/modules/gdnative/register_types.cpp b/modules/gdnative/register_types.cpp index d1b1513ac3..3a2d0b09a3 100644 --- a/modules/gdnative/register_types.cpp +++ b/modules/gdnative/register_types.cpp @@ -171,7 +171,7 @@ void GDNativeExportPlugin::_export_file(const String &p_path, const String &p_ty String entry_lib_path = config->get_value("entry", key); if (entry_lib_path.begins_with("res://") && entry_lib_path.ends_with(".a")) { // If we find static library that was used for export - // we should add a fake loopup table. + // we should add a fake lookup table. // In case of dynamic library being used, // this symbols will not cause any issues with library loading. should_fake_dynamic = true; diff --git a/modules/gdnative/videodecoder/video_stream_gdnative.h b/modules/gdnative/videodecoder/video_stream_gdnative.h index 53017a6a97..408d4a2454 100644 --- a/modules/gdnative/videodecoder/video_stream_gdnative.h +++ b/modules/gdnative/videodecoder/video_stream_gdnative.h @@ -146,32 +146,32 @@ public: bool open_file(const String &p_file); - virtual void stop(); - virtual void play(); + virtual void stop() override; + virtual void play() override; - virtual bool is_playing() const; + virtual bool is_playing() const override; - virtual void set_paused(bool p_paused); - virtual bool is_paused() const; + virtual void set_paused(bool p_paused) override; + virtual bool is_paused() const override; - virtual void set_loop(bool p_enable); - virtual bool has_loop() const; + virtual void set_loop(bool p_enable) override; + virtual bool has_loop() const override; - virtual float get_length() const; + virtual float get_length() const override; - virtual float get_playback_position() const; - virtual void seek(float p_time); + virtual float get_playback_position() const override; + virtual void seek(float p_time) override; - virtual void set_audio_track(int p_idx); + virtual void set_audio_track(int p_idx) override; //virtual int mix(int16_t* p_buffer,int p_frames)=0; - virtual Ref<Texture2D> get_texture() const; - virtual void update(float p_delta); + virtual Ref<Texture2D> get_texture() const override; + virtual void update(float p_delta) override; - virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata); - virtual int get_channels() const; - virtual int get_mix_rate() const; + virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata) override; + virtual int get_channels() const override; + virtual int get_mix_rate() const override; }; class VideoStreamGDNative : public VideoStream { @@ -188,8 +188,8 @@ public: void set_file(const String &p_file); String get_file(); - virtual void set_audio_track(int p_track); - virtual Ref<VideoStreamPlayback> instance_playback(); + virtual void set_audio_track(int p_track) override; + virtual Ref<VideoStreamPlayback> instance_playback() override; VideoStreamGDNative() {} }; diff --git a/modules/gdnative/xr/xr_interface_gdnative.h b/modules/gdnative/xr/xr_interface_gdnative.h index 64f1282a7e..de96487397 100644 --- a/modules/gdnative/xr/xr_interface_gdnative.h +++ b/modules/gdnative/xr/xr_interface_gdnative.h @@ -58,34 +58,34 @@ public: void set_interface(const godot_xr_interface_gdnative *p_interface); - virtual StringName get_name() const; - virtual int get_capabilities() const; + virtual StringName get_name() const override; + virtual int get_capabilities() const override; - virtual bool is_initialized() const; - virtual bool initialize(); - virtual void uninitialize(); + virtual bool is_initialized() const override; + virtual bool initialize() override; + virtual void uninitialize() override; /** specific to AR **/ - virtual bool get_anchor_detection_is_enabled() const; - virtual void set_anchor_detection_is_enabled(bool p_enable); - virtual int get_camera_feed_id(); + virtual bool get_anchor_detection_is_enabled() const override; + virtual void set_anchor_detection_is_enabled(bool p_enable) override; + virtual int get_camera_feed_id() override; /** rendering and internal **/ - virtual Size2 get_render_targetsize(); - virtual bool is_stereo(); - virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform); + virtual Size2 get_render_targetsize() override; + virtual bool is_stereo() override; + virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) override; // we expose a Vector<float> version of this function to GDNative Vector<float> _get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); // and a CameraMatrix version to XRServer - virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); + virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) override; - virtual unsigned int get_external_texture_for_eye(XRInterface::Eyes p_eye); - virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect); + virtual unsigned int get_external_texture_for_eye(XRInterface::Eyes p_eye) override; + virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) override; - virtual void process(); - virtual void notification(int p_what); + virtual void process() override; + virtual void notification(int p_what) override; }; #endif // XR_INTERFACE_GDNATIVE_H diff --git a/modules/gdnavigation/navigation_mesh_editor_plugin.h b/modules/gdnavigation/navigation_mesh_editor_plugin.h index 728f958eaa..f09182fff4 100644 --- a/modules/gdnavigation/navigation_mesh_editor_plugin.h +++ b/modules/gdnavigation/navigation_mesh_editor_plugin.h @@ -73,11 +73,11 @@ class NavigationMeshEditorPlugin : public EditorPlugin { EditorNode *editor; public: - virtual String get_name() const { return "NavigationMesh"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); + virtual String get_name() const override { return "NavigationMesh"; } + bool has_main_screen() const override { return false; } + virtual void edit(Object *p_object) override; + virtual bool handles(Object *p_object) const override; + virtual void make_visible(bool p_visible) override; NavigationMeshEditorPlugin(EditorNode *p_node); ~NavigationMeshEditorPlugin(); diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml index f04cb4b4c3..36de66ea52 100644 --- a/modules/gdscript/doc_classes/@GDScript.xml +++ b/modules/gdscript/doc_classes/@GDScript.xml @@ -52,7 +52,7 @@ <argument index="0" name="s" type="float"> </argument> <description> - Returns the absolute value of parameter [code]s[/code] (i.e. unsigned value, works for integer and float). + Returns the absolute value of parameter [code]s[/code] (i.e. positive value). [codeblock] # a is 1 a = abs(-1) @@ -112,7 +112,7 @@ </argument> <description> Returns the arc tangent of [code]s[/code] in radians. Use it to get the angle from an angle's tangent in trigonometry: [code]atan(tan(angle)) == angle[/code]. - The method cannot know in which quadrant the angle should fall. See [method atan2] if you always want an exact angle. + The method cannot know in which quadrant the angle should fall. See [method atan2] if you have both [code]y[code] and [code]x[/code]. [codeblock] a = atan(0.5) # a is 0.463648 [/codeblock] @@ -127,6 +127,7 @@ </argument> <description> Returns the arc tangent of [code]y/x[/code] in radians. Use to get the angle of tangent [code]y/x[/code]. To compute the value, the method takes into account the sign of both arguments in order to determine the quadrant. + Important note: The Y coordinate comes first, by convention. [codeblock] a = atan2(0, -1) # a is 3.141593 [/codeblock] @@ -161,7 +162,7 @@ <argument index="0" name="s" type="float"> </argument> <description> - Rounds [code]s[/code] upward, returning the smallest integral value that is not less than [code]s[/code]. + Rounds [code]s[/code] upward (towards positive infinity), returning the smallest whole number that is not less than [code]s[/code]. [codeblock] i = ceil(1.45) # i is 2 i = ceil(1.001) # i is 2 @@ -283,7 +284,7 @@ <argument index="0" name="deg" type="float"> </argument> <description> - Returns degrees converted to radians. + Converts an angle expressed in degrees to radians. [codeblock] # r is 3.141593 r = deg2rad(180) @@ -307,7 +308,7 @@ <argument index="1" name="curve" type="float"> </argument> <description> - 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. + Easing function, based on exponent. The curve values are: 0 is constant, 1 is linear, 0 to 1 is ease-in, 1+ is ease out. Negative values are in-out/out in. </description> </method> <method name="exp"> @@ -330,7 +331,7 @@ <argument index="0" name="s" type="float"> </argument> <description> - Rounds [code]s[/code] to the closest smaller integer and returns it. + Rounds [code]s[/code] downward (towards negative infinity), returning the largest whole number that is not more than [code]s[/code]. [codeblock] # a is 2.0 a = floor(2.99) @@ -530,7 +531,7 @@ <argument index="0" name="s" type="float"> </argument> <description> - Returns whether [code]s[/code] is a NaN (Not-A-Number) value. + Returns whether [code]s[/code] is a NaN ("Not a Number" or invalid) value. </description> </method> <method name="is_zero_approx"> @@ -540,6 +541,7 @@ </argument> <description> Returns [code]true[/code] if [code]s[/code] is zero or almost zero. + This method is faster than using [method is_equal_approx] with one value as zero. </description> </method> <method name="len"> @@ -907,7 +909,7 @@ <argument index="0" name="rad" type="float"> </argument> <description> - Converts from radians to degrees. + Converts an angle expressed in radians to degrees. [codeblock] rad2deg(0.523599) # Returns 30 [/codeblock] @@ -1026,7 +1028,7 @@ <argument index="0" name="s" type="float"> </argument> <description> - Returns the integral value that is nearest to [code]s[/code], with halfway cases rounded away from zero. + Rounds [code]s[/code] to the nearest whole number, with halfway cases rounded away from zero. [codeblock] round(2.6) # Returns 3 [/codeblock] @@ -1108,10 +1110,11 @@ <argument index="0" name="s" type="float"> </argument> <description> - Returns the square root of [code]s[/code]. + Returns the square root of [code]s[/code], where [code]s[/code] is a non-negative number. [codeblock] sqrt(9) # Returns 3 [/codeblock] + If you need negative inputs, use [code]System.Numerics.Complex[/code] in C#. </description> </method> <method name="step_decimals"> @@ -1312,27 +1315,19 @@ Wraps float [code]value[/code] between [code]min[/code] and [code]max[/code]. Usable for creating loop-alike behavior or infinite surfaces. [codeblock] - # a is 0.5 - a = wrapf(10.5, 0.0, 10.0) - [/codeblock] - [codeblock] - # a is 9.5 - a = wrapf(-0.5, 0.0, 10.0) - [/codeblock] - [codeblock] - # Infinite loop between 0.0 and 0.99 - f = wrapf(f + 0.1, 0.0, 1.0) + # Infinite loop between 5.0 and 9.9 + value = wrapf(value + 0.1, 5.0, 10.0) [/codeblock] [codeblock] # Infinite rotation (in radians) angle = wrapf(angle + 0.1, 0.0, TAU) [/codeblock] - [b]Note:[/b] If you just want to wrap between 0.0 and [code]n[/code] (where [code]n[/code] is a positive floating-point value), it is better for performance to use the [method fmod] method like [code]fmod(number, n)[/code]. - [code]wrapf[/code] is more flexible than using the [method fmod] approach by giving the user a simple control over the minimum value. It also fully supports negative numbers, e.g. [codeblock] # Infinite rotation (in radians) angle = wrapf(angle + 0.1, -PI, PI) [/codeblock] + [b]Note:[/b] If [code]min[/code] is [code]0[/code], this is equivalent to [method fposmod], so prefer using that instead. + [code]wrapf[/code] is more flexible than using the [method fposmod] approach by giving the user control over the minimum value. </description> </method> <method name="wrapi"> @@ -1348,23 +1343,15 @@ Wraps integer [code]value[/code] between [code]min[/code] and [code]max[/code]. Usable for creating loop-alike behavior or infinite surfaces. [codeblock] - # a is 0 - a = wrapi(10, 0, 10) - [/codeblock] - [codeblock] - # a is 9 - a = wrapi(-1, 0, 10) - [/codeblock] - [codeblock] - # Infinite loop between 0 and 9 - frame = wrapi(frame + 1, 0, 10) + # Infinite loop between 5 and 9 + frame = wrapi(frame + 1, 5, 10) [/codeblock] - [b]Note:[/b] If you just want to wrap between 0 and [code]n[/code] (where [code]n[/code] is a positive integer value), it is better for performance to use the modulo operator like [code]number % n[/code]. - [code]wrapi[/code] is more flexible than using the modulo approach by giving the user a simple control over the minimum value. It also fully supports negative numbers, e.g. [codeblock] # result is -2 var result = wrapi(-6, -5, -1) [/codeblock] + [b]Note:[/b] If [code]min[/code] is [code]0[/code], this is equivalent to [method posmod], so prefer using that instead. + [code]wrapi[/code] is more flexible than using the [method posmod] approach by giving the user control over the minimum value. </description> </method> <method name="yield"> @@ -1406,17 +1393,16 @@ </methods> <constants> <constant name="PI" value="3.141593"> - Constant that represents how many times the diameter of a circle fits around its perimeter. + Constant that represents how many times the diameter of a circle fits around its perimeter. This is equivalent to [code]TAU / 2[/code]. </constant> <constant name="TAU" value="6.283185"> - The circle constant, the circumference of the unit circle. + The circle constant, the circumference of the unit circle in radians. </constant> <constant name="INF" value="inf"> - A positive infinity. (For negative infinity, use -INF). + Positive infinity. For negative infinity, use -INF. </constant> <constant name="NAN" value="nan"> - Macro constant that expands to an expression of type float that represents a NaN. - The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0. + "Not a Number", an invalid value. [code]NaN[/code] has special properties, including that it is not equal to itself. It is output by some invalid operations, such as dividing zero by zero. </constant> </constants> </class> diff --git a/modules/gdscript/editor/gdscript_highlighter.cpp b/modules/gdscript/editor/gdscript_highlighter.cpp index d0f27b632b..43d0116125 100644 --- a/modules/gdscript/editor/gdscript_highlighter.cpp +++ b/modules/gdscript/editor/gdscript_highlighter.cpp @@ -29,26 +29,14 @@ /*************************************************************************/ #include "gdscript_highlighter.h" +#include "../gdscript.h" #include "../gdscript_tokenizer.h" #include "editor/editor_settings.h" -#include "scene/gui/text_edit.h" - -inline bool _is_symbol(CharType c) { - return is_symbol(c); -} - -static bool _is_text_char(CharType c) { - return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'; -} static bool _is_char(CharType c) { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'; } -static bool _is_number(CharType c) { - return (c >= '0' && c <= '9'); -} - static bool _is_hex_symbol(CharType c) { return ((c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); } @@ -57,8 +45,8 @@ static bool _is_bin_symbol(CharType c) { return (c == '0' || c == '1'); } -Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) { - Map<int, TextEdit::HighlighterInfo> color_map; +Dictionary GDScriptSyntaxHighlighter::_get_line_syntax_highlighting(int p_line) { + Dictionary color_map; Type next_type = NONE; Type current_type = NONE; @@ -82,36 +70,136 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ Color keyword_color; Color color; - int in_region = text_editor->_is_line_in_region(p_line); - int deregion = 0; + color_region_cache[p_line] = -1; + int in_region = -1; + if (p_line != 0) { + if (!color_region_cache.has(p_line - 1)) { + get_line_syntax_highlighting(p_line - 1); + } + in_region = color_region_cache[p_line - 1]; + } - const Map<int, TextEdit::Text::ColorRegionInfo> cri_map = text_editor->_get_line_color_region_info(p_line); - const String &str = text_editor->get_line(p_line); + const String &str = text_edit->get_line(p_line); + const int line_length = str.length(); Color prev_color; for (int j = 0; j < str.length(); j++) { - TextEdit::HighlighterInfo highlighter_info; + Dictionary highlighter_info; - if (deregion > 0) { - deregion--; - if (deregion == 0) { - in_region = -1; + color = font_color; + bool is_char = !is_symbol(str[j]); + bool is_a_symbol = is_symbol(str[j]); + bool is_number = (str[j] >= '0' && str[j] <= '9'); + + /* color regions */ + if (is_a_symbol || in_region != -1) { + int from = j; + for (; from < line_length; from++) { + if (str[from] == '\\') { + from++; + continue; + } + break; } - } - if (deregion != 0) { - if (color != prev_color) { - prev_color = color; - highlighter_info.color = color; - color_map[j] = highlighter_info; - } - continue; - } + if (from != line_length) { + /* check if we are in entering a region */ + if (in_region == -1) { + for (int c = 0; c < color_regions.size(); c++) { + /* check there is enough room */ + int chars_left = line_length - from; + int start_key_length = color_regions[c].start_key.length(); + int end_key_length = color_regions[c].end_key.length(); + if (chars_left < start_key_length) { + continue; + } + + /* search the line */ + bool match = true; + const CharType *start_key = color_regions[c].start_key.c_str(); + for (int k = 0; k < start_key_length; k++) { + if (start_key[k] != str[from + k]) { + match = false; + break; + } + } + if (!match) { + continue; + } + in_region = c; + from += start_key_length; + + /* check if it's the whole line */ + if (end_key_length == 0 || color_regions[c].line_only || from + end_key_length > line_length) { + prev_color = color_regions[in_region].color; + highlighter_info["color"] = color_regions[c].color; + color_map[j] = highlighter_info; + + j = line_length; + if (!color_regions[c].line_only) { + color_region_cache[p_line] = c; + } + } + break; + } - color = font_color; + if (j == line_length) { + continue; + } + } - bool is_char = _is_text_char(str[j]); - bool is_symbol = _is_symbol(str[j]); - bool is_number = _is_number(str[j]); + /* if we are in one find the end key */ + if (in_region != -1) { + /* check there is enough room */ + int chars_left = line_length - from; + int end_key_length = color_regions[in_region].end_key.length(); + if (chars_left < end_key_length) { + continue; + } + + /* search the line */ + int region_end_index = -1; + const CharType *end_key = color_regions[in_region].start_key.c_str(); + for (; from < line_length; from++) { + if (!is_a_symbol) { + continue; + } + + if (str[from] == '\\') { + from++; + continue; + } + + for (int k = 0; k < end_key_length; k++) { + if (end_key[k] == str[from + k]) { + region_end_index = from; + break; + } + } + + if (region_end_index != -1) { + break; + } + } + + prev_color = color_regions[in_region].color; + highlighter_info["color"] = color_regions[in_region].color; + color_map[j] = highlighter_info; + + previous_type = REGION; + previous_text = ""; + previous_column = j; + j = from; + if (region_end_index == -1) { + color_region_cache[p_line] = in_region; + } + + in_region = -1; + prev_is_char = false; + prev_is_number = false; + continue; + } + } + } // allow ABCDEF in hex notation if (is_hex_notation && (_is_hex_symbol(str[j]) || is_number)) { @@ -133,7 +221,7 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ // check for dot or underscore or 'x' for hex notation in floating point number or 'e' for scientific notation if ((str[j] == '.' || str[j] == 'x' || str[j] == 'b' || str[j] == '_' || str[j] == 'e') && !in_word && prev_is_number && !is_number) { is_number = true; - is_symbol = false; + is_a_symbol = false; is_char = false; if (str[j] == 'x' && str[j - 1] == '0') { @@ -151,43 +239,26 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ is_number = false; } - if (is_symbol && str[j] != '.' && in_word) { + if (is_a_symbol && str[j] != '.' && in_word) { in_word = false; } - if (is_symbol && cri_map.has(j)) { - const TextEdit::Text::ColorRegionInfo &cri = cri_map[j]; - - if (in_region == -1) { - if (!cri.end) { - in_region = cri.region; - } - } else { - TextEdit::ColorRegion cr = text_editor->_get_color_region(cri.region); - if (in_region == cri.region && !cr.line_only) { //ignore otherwise - if (cri.end || cr.eq) { - deregion = cr.eq ? cr.begin_key.length() : cr.end_key.length(); - } - } - } - } - if (!is_char) { in_keyword = false; } - if (in_region == -1 && !in_keyword && is_char && !prev_is_char) { + if (!in_keyword && is_char && !prev_is_char) { int to = j; - while (to < str.length() && _is_text_char(str[to])) { + while (to < str.length() && !is_symbol(str[to])) { to++; } String word = str.substr(j, to - j); Color col = Color(); - if (text_editor->has_keyword_color(word)) { - col = text_editor->get_keyword_color(word); - } else if (text_editor->has_member_color(word)) { - col = text_editor->get_member_color(word); + if (keywords.has(word)) { + col = keywords[word]; + } else if (member_keywords.has(word)) { + col = member_keywords[word]; for (int k = j - 1; k >= 0; k--) { if (str[k] == '.') { col = Color(); //member indexing not allowed @@ -206,7 +277,7 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ if (!in_function_name && in_word && !in_keyword) { int k = j; - while (k < str.length() && !_is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') { + while (k < str.length() && !is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') { k++; } @@ -224,7 +295,7 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ if (!in_function_name && !in_member_variable && !in_keyword && !is_number && in_word) { int k = j; - while (k > 0 && !_is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') { + while (k > 0 && !is_symbol(str[k]) && str[k] != '\t' && str[k] != ' ') { k--; } @@ -233,7 +304,7 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ } } - if (is_symbol) { + if (is_a_symbol) { if (in_function_name) { in_function_args = true; } @@ -270,14 +341,11 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ if (!in_node_path && in_region == -1 && str[j] == '$') { in_node_path = true; - } else if (in_region != -1 || (is_symbol && str[j] != '/')) { + } else if (in_region != -1 || (is_a_symbol && str[j] != '/')) { in_node_path = false; } - if (in_region >= 0) { - next_type = REGION; - color = text_editor->_get_color_region(in_region).color; - } else if (in_node_path) { + if (in_node_path) { next_type = NODE_PATH; color = node_path_color; } else if (in_keyword) { @@ -294,7 +362,7 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ } else { color = function_color; } - } else if (is_symbol) { + } else if (is_a_symbol) { next_type = SYMBOL; color = symbol_color; } else if (is_number) { @@ -335,32 +403,133 @@ Map<int, TextEdit::HighlighterInfo> GDScriptSyntaxHighlighter::_get_line_syntax_ if (color != prev_color) { prev_color = color; - highlighter_info.color = color; + highlighter_info["color"] = color; color_map[j] = highlighter_info; } } return color_map; } -String GDScriptSyntaxHighlighter::get_name() const { +String GDScriptSyntaxHighlighter::_get_name() const { return "GDScript"; } -List<String> GDScriptSyntaxHighlighter::get_supported_languages() { - List<String> languages; +Array GDScriptSyntaxHighlighter::_get_supported_languages() const { + Array languages; languages.push_back("GDScript"); return languages; } void GDScriptSyntaxHighlighter::_update_cache() { - font_color = text_editor->get_theme_color("font_color"); - symbol_color = text_editor->get_theme_color("symbol_color"); - function_color = text_editor->get_theme_color("function_color"); - number_color = text_editor->get_theme_color("number_color"); - member_color = text_editor->get_theme_color("member_variable_color"); + keywords.clear(); + member_keywords.clear(); + color_regions.clear(); + color_region_cache.clear(); + + font_color = text_edit->get_theme_color("font_color"); + symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color"); + function_color = EDITOR_GET("text_editor/highlighting/function_color"); + number_color = EDITOR_GET("text_editor/highlighting/number_color"); + member_color = EDITOR_GET("text_editor/highlighting/member_variable_color"); + + /* Engine types. */ + const Color types_color = EDITOR_GET("text_editor/highlighting/engine_type_color"); + List<StringName> types; + ClassDB::get_class_list(&types); + for (List<StringName>::Element *E = types.front(); E; E = E->next()) { + String n = E->get(); + if (n.begins_with("_")) { + n = n.substr(1, n.length()); + } + keywords[n] = types_color; + } + + /* User types. */ + const Color usertype_color = EDITOR_GET("text_editor/highlighting/user_type_color"); + List<StringName> global_classes; + ScriptServer::get_global_class_list(&global_classes); + for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) { + keywords[String(E->get())] = usertype_color; + } + + /* Autoloads. */ + Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); + for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) { + const ProjectSettings::AutoloadInfo &info = E->value(); + if (info.is_singleton) { + keywords[info.name] = usertype_color; + } + } - const String text_editor_color_theme = EditorSettings::get_singleton()->get("text_editor/theme/color_theme"); - const bool default_theme = text_editor_color_theme == "Default"; + const GDScriptLanguage *gdscript = GDScriptLanguage::get_singleton(); + + /* Core types. */ + const Color basetype_color = EDITOR_GET("text_editor/highlighting/base_type_color"); + List<String> core_types; + gdscript->get_core_type_words(&core_types); + for (List<String>::Element *E = core_types.front(); E; E = E->next()) { + keywords[E->get()] = basetype_color; + } + + /* Reserved words. */ + const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color"); + List<String> keyword_list; + gdscript->get_reserved_words(&keyword_list); + for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) { + keywords[E->get()] = keyword_color; + } + + /* Comments */ + const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); + List<String> comments; + gdscript->get_comment_delimiters(&comments); + for (List<String>::Element *E = comments.front(); E; E = E->next()) { + String comment = E->get(); + String beg = comment.get_slice(" ", 0); + String end = comment.get_slice_count(" ") > 1 ? comment.get_slice(" ", 1) : String(); + add_color_region(beg, end, comment_color, end == ""); + } + + /* Strings */ + const Color string_color = EDITOR_GET("text_editor/highlighting/string_color"); + List<String> strings; + gdscript->get_string_delimiters(&strings); + for (List<String>::Element *E = strings.front(); E; E = E->next()) { + String string = E->get(); + String beg = string.get_slice(" ", 0); + String end = string.get_slice_count(" ") > 1 ? string.get_slice(" ", 1) : String(); + add_color_region(beg, end, string_color, end == ""); + } + + const Ref<Script> script = _get_edited_resource(); + if (script.is_valid()) { + /* Member types. */ + const Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color"); + StringName instance_base = script->get_instance_base_type(); + if (instance_base != StringName()) { + List<PropertyInfo> plist; + ClassDB::get_property_list(instance_base, &plist); + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { + String name = E->get().name; + if (E->get().usage & PROPERTY_USAGE_CATEGORY || E->get().usage & PROPERTY_USAGE_GROUP || E->get().usage & PROPERTY_USAGE_SUBGROUP) { + continue; + } + if (name.find("/") != -1) { + continue; + } + member_keywords[name] = member_variable_color; + } + + List<String> clist; + ClassDB::get_integer_constant_list(instance_base, &clist); + for (List<String>::Element *E = clist.front(); E; E = E->next()) { + member_keywords[E->get()] = member_variable_color; + } + } + } + + const String text_edit_color_theme = EditorSettings::get_singleton()->get("text_editor/theme/color_theme"); + const bool default_theme = text_edit_color_theme == "Default"; if (default_theme || EditorSettings::get_singleton()->is_dark_theme()) { function_definition_color = Color(0.4, 0.9, 1.0); @@ -372,7 +541,7 @@ void GDScriptSyntaxHighlighter::_update_cache() { EDITOR_DEF("text_editor/highlighting/gdscript/function_definition_color", function_definition_color); EDITOR_DEF("text_editor/highlighting/gdscript/node_path_color", node_path_color); - if (text_editor_color_theme == "Adaptive" || default_theme) { + if (text_edit_color_theme == "Adaptive" || default_theme) { EditorSettings::get_singleton()->set_initial_value( "text_editor/highlighting/gdscript/function_definition_color", function_definition_color, @@ -388,6 +557,31 @@ void GDScriptSyntaxHighlighter::_update_cache() { type_color = EDITOR_GET("text_editor/highlighting/base_type_color"); } -SyntaxHighlighter *GDScriptSyntaxHighlighter::create() { - return memnew(GDScriptSyntaxHighlighter); +void GDScriptSyntaxHighlighter::add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only) { + for (int i = 0; i < p_start_key.length(); i++) { + ERR_FAIL_COND_MSG(!is_symbol(p_start_key[i]), "color regions must start with a symbol"); + } + + if (p_end_key.length() > 0) { + for (int i = 0; i < p_end_key.length(); i++) { + ERR_FAIL_COND_MSG(!is_symbol(p_end_key[i]), "color regions must end with a symbol"); + } + } + + for (int i = 0; i < color_regions.size(); i++) { + ERR_FAIL_COND_MSG(color_regions[i].start_key == p_start_key, "color region with start key '" + p_start_key + "' already exists."); + } + + ColorRegion color_region; + color_region.color = p_color; + color_region.start_key = p_start_key; + color_region.end_key = p_end_key; + color_region.line_only = p_line_only; + color_regions.push_back(color_region); +} + +Ref<EditorSyntaxHighlighter> GDScriptSyntaxHighlighter::_create() const { + Ref<GDScriptSyntaxHighlighter> syntax_highlighter; + syntax_highlighter.instance(); + return syntax_highlighter; } diff --git a/modules/gdscript/editor/gdscript_highlighter.h b/modules/gdscript/editor/gdscript_highlighter.h index e652fb1471..49357f3d2e 100644 --- a/modules/gdscript/editor/gdscript_highlighter.h +++ b/modules/gdscript/editor/gdscript_highlighter.h @@ -31,10 +31,25 @@ #ifndef GDSCRIPT_HIGHLIGHTER_H #define GDSCRIPT_HIGHLIGHTER_H +#include "editor/plugins/script_editor_plugin.h" #include "scene/gui/text_edit.h" -class GDScriptSyntaxHighlighter : public SyntaxHighlighter { +class GDScriptSyntaxHighlighter : public EditorSyntaxHighlighter { + GDCLASS(GDScriptSyntaxHighlighter, EditorSyntaxHighlighter) + private: + struct ColorRegion { + Color color; + String start_key; + String end_key; + bool line_only; + }; + Vector<ColorRegion> color_regions; + Map<int, int> color_region_cache; + + Dictionary keywords; + Dictionary member_keywords; + enum Type { NONE, REGION, @@ -59,14 +74,16 @@ private: Color node_path_color; Color type_color; + void add_color_region(const String &p_start_key, const String &p_end_key, const Color &p_color, bool p_line_only = false); + public: - static SyntaxHighlighter *create(); + virtual void _update_cache() override; + virtual Dictionary _get_line_syntax_highlighting(int p_line) override; - virtual void _update_cache(); - virtual Map<int, TextEdit::HighlighterInfo> _get_line_syntax_highlighting(int p_line); + virtual String _get_name() const override; + virtual Array _get_supported_languages() const override; - virtual String get_name() const; - virtual List<String> get_supported_languages(); + virtual Ref<EditorSyntaxHighlighter> _create() const override; }; #endif // GDSCRIPT_HIGHLIGHTER_H diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp index a1b18978fc..6d454e43f2 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.cpp @@ -38,25 +38,8 @@ void GDScriptEditorTranslationParserPlugin::get_recognized_extensions(List<Strin } Error GDScriptEditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_extracted_strings) { - List<String> extensions; - get_recognized_extensions(&extensions); - bool extension_valid = false; - for (auto E = extensions.front(); E; E = E->next()) { - if (p_path.get_extension() == E->get()) { - extension_valid = true; - break; - } - } - - if (!extension_valid) { - Vector<String> temp; - for (auto E = extensions.front(); E; E = E->next()) { - temp.push_back(E->get()); - } - String valid_extensions = String(", ").join(temp); - ERR_PRINT("Argument p_path \"" + p_path + "\" has wrong extension. List of valid extensions: " + valid_extensions); - return ERR_INVALID_PARAMETER; - } + // Parse and match all GDScript function API that involves translation string. + // E.g get_node("Label").text = "something", var test = tr("something"), "something" will be matched and collected. Error err; RES loaded_res = ResourceLoader::load(p_path, "", false, &err); @@ -66,26 +49,18 @@ Error GDScriptEditorTranslationParserPlugin::parse_file(const String &p_path, Ve } Ref<GDScript> gdscript = loaded_res; - parse_text(gdscript->get_source_code(), r_extracted_strings); - - return OK; -} - -void GDScriptEditorTranslationParserPlugin::parse_text(const String &p_text, Vector<String> *r_extracted_strings) { - // Parse and match all GDScript function API that involves translation string. - // E.g get_node("Label").text = "something", var test = tr("something"), "something" will be matched and collected. - + String source_code = gdscript->get_source_code(); Vector<String> parsed_strings; // Search translation strings with RegEx. regex.clear(); regex.compile(String("|").join(patterns)); - Array results = regex.search_all(p_text); + Array results = regex.search_all(source_code); _get_captured_strings(results, &parsed_strings); // Special handling for FileDialog. Vector<String> temp; - _parse_file_dialog(p_text, &temp); + _parse_file_dialog(source_code, &temp); parsed_strings.append_array(temp); // Filter out / and + @@ -97,6 +72,8 @@ void GDScriptEditorTranslationParserPlugin::parse_text(const String &p_text, Vec } r_extracted_strings->append_array(parsed_strings); + + return OK; } void GDScriptEditorTranslationParserPlugin::_parse_file_dialog(const String &p_source_code, Vector<String> *r_output) { diff --git a/modules/gdscript/editor/gdscript_translation_parser_plugin.h b/modules/gdscript/editor/gdscript_translation_parser_plugin.h index ef967845b9..9fa4b69f01 100644 --- a/modules/gdscript/editor/gdscript_translation_parser_plugin.h +++ b/modules/gdscript/editor/gdscript_translation_parser_plugin.h @@ -47,9 +47,8 @@ class GDScriptEditorTranslationParserPlugin : public EditorTranslationParserPlug void _get_captured_strings(const Array &p_results, Vector<String> *r_output); public: - virtual Error parse_file(const String &p_path, Vector<String> *r_extracted_strings); - virtual void parse_text(const String &p_text, Vector<String> *r_extracted_strings); - virtual void get_recognized_extensions(List<String> *r_extensions) const; + virtual Error parse_file(const String &p_path, Vector<String> *r_extracted_strings) override; + virtual void get_recognized_extensions(List<String> *r_extensions) const override; GDScriptEditorTranslationParserPlugin(); }; diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index e770dc3abd..9a5de2c293 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -124,7 +124,7 @@ class GDScript : public Script { #ifdef TOOLS_ENABLED Set<PlaceHolderScriptInstance *> placeholders; //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); - virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; #endif #ifdef DEBUG_ENABLED @@ -143,15 +143,15 @@ protected: bool _set(const StringName &p_name, const Variant &p_value); void _get_property_list(List<PropertyInfo> *p_properties) const; - Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); + Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override; //void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount); static void _bind_methods(); public: - virtual bool is_valid() const { return valid; } + virtual bool is_valid() const override { return valid; } - bool inherits_script(const Ref<Script> &p_script) const; + bool inherits_script(const Ref<Script> &p_script) const override; const Map<StringName, Ref<GDScript>> &get_subclasses() const { return subclasses; } const Map<StringName, Variant> &get_constants() const { return constants; } @@ -164,10 +164,10 @@ public: const Ref<GDScriptNativeClass> &get_native() const { return native; } const String &get_script_class_name() const { return name; } - virtual bool has_script_signal(const StringName &p_signal) const; - virtual void get_script_signal_list(List<MethodInfo> *r_signals) const; + virtual bool has_script_signal(const StringName &p_signal) const override; + virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override; - bool is_tool() const { return tool; } + bool is_tool() const override { return tool; } Ref<GDScript> get_base() const; const Map<StringName, MemberInfo> &debug_get_member_indices() const { return member_indices; } @@ -175,21 +175,21 @@ public: StringName debug_get_member_by_index(int p_idx) const; Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error); - virtual bool can_instance() const; + virtual bool can_instance() const override; - virtual Ref<Script> get_base_script() const; + virtual Ref<Script> get_base_script() const override; - virtual StringName get_instance_base_type() const; // this may not work in all scripts, will return empty if so - virtual ScriptInstance *instance_create(Object *p_this); - virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this); - virtual bool instance_has(const Object *p_this) const; + virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so + virtual ScriptInstance *instance_create(Object *p_this) override; + virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override; + virtual bool instance_has(const Object *p_this) const override; - virtual bool has_source_code() const; - virtual String get_source_code() const; - virtual void set_source_code(const String &p_code); - virtual void update_exports(); + virtual bool has_source_code() const override; + virtual String get_source_code() const override; + virtual void set_source_code(const String &p_code) override; + virtual void update_exports() override; - virtual Error reload(bool p_keep_state = false); + virtual Error reload(bool p_keep_state = false) override; void set_script_path(const String &p_path) { path = p_path; } //because subclasses need a path too... Error load_source_code(const String &p_path); @@ -197,17 +197,17 @@ public: Vector<uint8_t> get_as_byte_code() const; - bool get_property_default_value(const StringName &p_property, Variant &r_value) const; + bool get_property_default_value(const StringName &p_property, Variant &r_value) const override; - virtual void get_script_method_list(List<MethodInfo> *p_list) const; - virtual bool has_method(const StringName &p_method) const; - virtual MethodInfo get_method_info(const StringName &p_method) const; + virtual void get_script_method_list(List<MethodInfo> *p_list) const override; + virtual bool has_method(const StringName &p_method) const override; + virtual MethodInfo get_method_info(const StringName &p_method) const override; - virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + virtual void get_script_property_list(List<PropertyInfo> *p_list) const override; - virtual ScriptLanguage *get_language() const; + virtual ScriptLanguage *get_language() const override; - virtual int get_member_line(const StringName &p_member) const { + virtual int get_member_line(const StringName &p_member) const override { #ifdef TOOLS_ENABLED if (member_lines.has(p_member)) { return member_lines[p_member]; @@ -216,23 +216,23 @@ public: return -1; } - virtual void get_constants(Map<StringName, Variant> *p_constants); - virtual void get_members(Set<StringName> *p_members); + virtual void get_constants(Map<StringName, Variant> *p_constants) override; + virtual void get_members(Set<StringName> *p_members) override; - virtual Vector<ScriptNetData> get_rpc_methods() const; - virtual uint16_t get_rpc_method_id(const StringName &p_method) const; - virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const; + virtual Vector<ScriptNetData> get_rpc_methods() const override; + virtual uint16_t get_rpc_method_id(const StringName &p_method) const override; + virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const override; + virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const override; + virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const override; - virtual Vector<ScriptNetData> get_rset_properties() const; - virtual uint16_t get_rset_property_id(const StringName &p_variable) const; - virtual StringName get_rset_property(const uint16_t p_variable_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const; + virtual Vector<ScriptNetData> get_rset_properties() const override; + virtual uint16_t get_rset_property_id(const StringName &p_variable) const override; + virtual StringName get_rset_property(const uint16_t p_variable_id) const override; + virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const override; + virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const override; #ifdef TOOLS_ENABLED - virtual bool is_placeholder_fallback_enabled() const { return placeholder_fallback_enabled; } + virtual bool is_placeholder_fallback_enabled() const override { return placeholder_fallback_enabled; } #endif GDScript(); diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index ca452bf008..63da849723 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4072,6 +4072,9 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { while (true) { current_function = function; Node *arg = _parse_and_reduce_expression(p_class, _static); + if (!arg) { + return; + } current_function = nullptr; cparent->arguments.push_back(arg); diff --git a/modules/gdscript/language_server/gdscript_extend_parser.cpp b/modules/gdscript/language_server/gdscript_extend_parser.cpp index 330530be80..385d5dd7cb 100644 --- a/modules/gdscript/language_server/gdscript_extend_parser.cpp +++ b/modules/gdscript/language_server/gdscript_extend_parser.cpp @@ -62,7 +62,7 @@ void ExtendGDScriptParser::update_diagnostics() { const GDScriptWarning &warning = E->get(); lsp::Diagnostic diagnostic; diagnostic.severity = lsp::DiagnosticSeverity::Warning; - diagnostic.message = warning.get_message(); + diagnostic.message = "(" + warning.get_name() + "): " + warning.get_message(); diagnostic.source = "gdscript"; diagnostic.code = warning.code; lsp::Range range; diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 53e760ffa7..6c4e529922 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -55,11 +55,13 @@ Ref<ResourceFormatSaverGDScript> resource_saver_gd; #include "language_server/gdscript_language_server.h" #endif // !GDSCRIPT_NO_LSP +Ref<GDScriptEditorTranslationParserPlugin> gdscript_translation_parser_plugin; + class EditorExportGDScript : public EditorExportPlugin { GDCLASS(EditorExportGDScript, EditorExportPlugin); public: - virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features) { + virtual void _export_file(const String &p_path, const String &p_type, const Set<String> &p_features) override { int script_mode = EditorExportPreset::MODE_SCRIPT_COMPILED; String script_key; @@ -140,6 +142,12 @@ static void _editor_init() { gd_export.instance(); EditorExport::get_singleton()->add_export_plugin(gd_export); +#ifdef TOOLS_ENABLED + Ref<GDScriptSyntaxHighlighter> gdscript_syntax_highlighter; + gdscript_syntax_highlighter.instance(); + ScriptEditor::get_singleton()->register_syntax_highlighter(gdscript_syntax_highlighter); +#endif + #ifndef GDSCRIPT_NO_LSP register_lsp_types(); GDScriptLanguageServer *lsp_plugin = memnew(GDScriptLanguageServer); @@ -164,10 +172,8 @@ void register_gdscript_types() { ResourceSaver::add_resource_format_saver(resource_saver_gd); #ifdef TOOLS_ENABLED - ScriptEditor::register_create_syntax_highlighter_function(GDScriptSyntaxHighlighter::create); EditorNode::add_init_callback(_editor_init); - Ref<GDScriptEditorTranslationParserPlugin> gdscript_translation_parser_plugin; gdscript_translation_parser_plugin.instance(); EditorTranslationParser::get_singleton()->add_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD); #endif // TOOLS_ENABLED @@ -185,4 +191,9 @@ void unregister_gdscript_types() { ResourceSaver::remove_resource_format_saver(resource_saver_gd); resource_saver_gd.unref(); + +#ifdef TOOLS_ENABLED + EditorTranslationParser::get_singleton()->remove_parser(gdscript_translation_parser_plugin, EditorTranslationParser::STANDARD); + gdscript_translation_parser_plugin.unref(); +#endif // TOOLS_ENABLED } diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index 84b68ba6e7..7e136ff9bb 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -255,12 +255,12 @@ protected: void _notification(int p_what); public: - virtual bool forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { return grid_map_editor->forward_spatial_input_event(p_camera, p_event); } - virtual String get_name() const { return "GridMap"; } - bool has_main_screen() const { return false; } - virtual void edit(Object *p_object); - virtual bool handles(Object *p_object) const; - virtual void make_visible(bool p_visible); + virtual bool forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) override { return grid_map_editor->forward_spatial_input_event(p_camera, p_event); } + virtual String get_name() const override { return "GridMap"; } + bool has_main_screen() const override { return false; } + virtual void edit(Object *p_object) override; + virtual bool handles(Object *p_object) const override; + virtual void make_visible(bool p_visible) override; GridMapEditorPlugin(EditorNode *p_node); ~GridMapEditorPlugin(); diff --git a/modules/lightmapper_rd/lightmapper_rd.h b/modules/lightmapper_rd/lightmapper_rd.h index 6cb3ecbe9e..cd000414cf 100644 --- a/modules/lightmapper_rd/lightmapper_rd.h +++ b/modules/lightmapper_rd/lightmapper_rd.h @@ -235,22 +235,22 @@ class LightmapperRD : public Lightmapper { void _raster_geometry(RenderingDevice *rd, Size2i atlas_size, int atlas_slices, int grid_size, AABB bounds, float p_bias, Vector<int> slice_triangle_count, RID position_tex, RID unocclude_tex, RID normal_tex, RID raster_depth_buffer, RID rasterize_shader, RID raster_base_uniform); public: - virtual void add_mesh(const MeshData &p_mesh); - virtual void add_directional_light(bool p_static, const Vector3 &p_direction, const Color &p_color, float p_energy, float p_angular_distance); - virtual void add_omni_light(bool p_static, const Vector3 &p_position, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_size); - virtual void add_spot_light(bool p_static, const Vector3 &p_position, const Vector3 p_direction, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_spot_angle, float p_spot_attenuation, float p_size); - virtual void add_probe(const Vector3 &p_position); - virtual BakeError bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function = nullptr, void *p_bake_userdata = nullptr); - - int get_bake_texture_count() const; - Ref<Image> get_bake_texture(int p_index) const; - int get_bake_mesh_count() const; - Variant get_bake_mesh_userdata(int p_index) const; - Rect2 get_bake_mesh_uv_scale(int p_index) const; - int get_bake_mesh_texture_slice(int p_index) const; - int get_bake_probe_count() const; - Vector3 get_bake_probe_point(int p_probe) const; - Vector<Color> get_bake_probe_sh(int p_probe) const; + virtual void add_mesh(const MeshData &p_mesh) override; + virtual void add_directional_light(bool p_static, const Vector3 &p_direction, const Color &p_color, float p_energy, float p_angular_distance) override; + virtual void add_omni_light(bool p_static, const Vector3 &p_position, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_size) override; + virtual void add_spot_light(bool p_static, const Vector3 &p_position, const Vector3 p_direction, const Color &p_color, float p_energy, float p_range, float p_attenuation, float p_spot_angle, float p_spot_attenuation, float p_size) override; + virtual void add_probe(const Vector3 &p_position) override; + virtual BakeError bake(BakeQuality p_quality, bool p_use_denoiser, int p_bounces, float p_bias, int p_max_texture_size, bool p_bake_sh, GenerateProbes p_generate_probes, const Ref<Image> &p_environment_panorama, const Basis &p_environment_transform, BakeStepFunc p_step_function = nullptr, void *p_bake_userdata = nullptr) override; + + int get_bake_texture_count() const override; + Ref<Image> get_bake_texture(int p_index) const override; + int get_bake_mesh_count() const override; + Variant get_bake_mesh_userdata(int p_index) const override; + Rect2 get_bake_mesh_uv_scale(int p_index) const override; + int get_bake_mesh_texture_slice(int p_index) const override; + int get_bake_probe_count() const override; + Vector3 get_bake_probe_point(int p_probe) const override; + Vector<Color> get_bake_probe_sh(int p_probe) const override; LightmapperRD(); }; diff --git a/modules/mobile_vr/mobile_vr_interface.h b/modules/mobile_vr/mobile_vr_interface.h index e986a4a3de..9b03fff777 100644 --- a/modules/mobile_vr/mobile_vr_interface.h +++ b/modules/mobile_vr/mobile_vr_interface.h @@ -128,21 +128,21 @@ public: void set_k2(const real_t p_k2); real_t get_k2() const; - virtual StringName get_name() const; - virtual int get_capabilities() const; + virtual StringName get_name() const override; + virtual int get_capabilities() const override; - virtual bool is_initialized() const; - virtual bool initialize(); - virtual void uninitialize(); + virtual bool is_initialized() const override; + virtual bool initialize() override; + virtual void uninitialize() override; - virtual Size2 get_render_targetsize(); - virtual bool is_stereo(); - virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform); - virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far); - virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect); + virtual Size2 get_render_targetsize() override; + virtual bool is_stereo() override; + virtual Transform get_transform_for_eye(XRInterface::Eyes p_eye, const Transform &p_cam_transform) override; + virtual CameraMatrix get_projection_for_eye(XRInterface::Eyes p_eye, real_t p_aspect, real_t p_z_near, real_t p_z_far) override; + virtual void commit_for_eye(XRInterface::Eyes p_eye, RID p_render_target, const Rect2 &p_screen_rect) override; - virtual void process(); - virtual void notification(int p_what) {} + virtual void process() override; + virtual void notification(int p_what) override {} MobileVRInterface(); ~MobileVRInterface(); diff --git a/modules/mono/class_db_api_json.cpp b/modules/mono/class_db_api_json.cpp index 39e3a95afa..d7b2028204 100644 --- a/modules/mono/class_db_api_json.cpp +++ b/modules/mono/class_db_api_json.cpp @@ -53,8 +53,9 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { for (List<StringName>::Element *E = names.front(); E; E = E->next()) { ClassDB::ClassInfo *t = ClassDB::classes.getptr(E->get()); ERR_FAIL_COND(!t); - if (t->api != p_api || !t->exposed) + if (t->api != p_api || !t->exposed) { continue; + } Dictionary class_dict; classes_dict[t->name] = class_dict; @@ -72,8 +73,9 @@ void class_db_api_to_json(const String &p_output_file, ClassDB::APIType p_api) { ERR_CONTINUE(name.empty()); - if (name[0] == '_') + if (name[0] == '_') { continue; // Ignore non-virtual methods that start with an underscore + } snames.push_back(*k); } diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index ae25bd3544..7d3ae31588 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -125,8 +125,9 @@ void CSharpLanguage::init() { print_line("Run this binary with '--generate-mono-glue path/to/modules/mono/glue'"); #endif - if (gdmono->is_runtime_initialized()) + if (gdmono->is_runtime_initialized()) { gdmono->initialize_load_assemblies(); + } #ifdef TOOLS_ENABLED EditorNode::add_init_callback(&_editor_init_callback); @@ -134,8 +135,13 @@ void CSharpLanguage::init() { } void CSharpLanguage::finish() { - if (finalized) + finalize(); +} + +void CSharpLanguage::finalize() { + if (finalized) { return; + } finalizing = true; @@ -390,15 +396,17 @@ bool CSharpLanguage::supports_builtin_mode() const { #ifdef TOOLS_ENABLED static String variant_type_to_managed_name(const String &p_var_type_name) { - if (p_var_type_name.empty()) + if (p_var_type_name.empty()) { return "object"; + } if (!ClassDB::class_exists(p_var_type_name)) { return p_var_type_name; } - if (p_var_type_name == Variant::get_type_name(Variant::OBJECT)) + if (p_var_type_name == Variant::get_type_name(Variant::OBJECT)) { return "Godot.Object"; + } if (p_var_type_name == Variant::get_type_name(Variant::FLOAT)) { #ifdef REAL_T_IS_DOUBLE @@ -408,36 +416,49 @@ static String variant_type_to_managed_name(const String &p_var_type_name) { #endif } - if (p_var_type_name == Variant::get_type_name(Variant::STRING)) + if (p_var_type_name == Variant::get_type_name(Variant::STRING)) { return "string"; // I prefer this one >:[ + } - if (p_var_type_name == Variant::get_type_name(Variant::DICTIONARY)) + if (p_var_type_name == Variant::get_type_name(Variant::DICTIONARY)) { return "Collections.Dictionary"; + } - if (p_var_type_name == Variant::get_type_name(Variant::ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::ARRAY)) { return "Collections.Array"; + } - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_BYTE_ARRAY)) + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_BYTE_ARRAY)) { return "byte[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT32_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT32_ARRAY)) { return "int[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT64_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_INT64_ARRAY)) { return "long[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT32_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT32_ARRAY)) { return "float[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT64_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_FLOAT64_ARRAY)) { return "double[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_STRING_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_STRING_ARRAY)) { return "string[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR2_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR2_ARRAY)) { return "Vector2[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR3_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_VECTOR3_ARRAY)) { return "Vector3[]"; - if (p_var_type_name == Variant::get_type_name(Variant::PACKED_COLOR_ARRAY)) + } + if (p_var_type_name == Variant::get_type_name(Variant::PACKED_COLOR_ARRAY)) { return "Color[]"; + } - if (p_var_type_name == Variant::get_type_name(Variant::SIGNAL)) + if (p_var_type_name == Variant::get_type_name(Variant::SIGNAL)) { return "SignalInfo"; + } Variant::Type var_types[] = { Variant::BOOL, @@ -462,8 +483,9 @@ static String variant_type_to_managed_name(const String &p_var_type_name) { }; for (unsigned int i = 0; i < sizeof(var_types) / sizeof(Variant::Type); i++) { - if (p_var_type_name == Variant::get_type_name(var_types[i])) + if (p_var_type_name == Variant::get_type_name(var_types[i])) { return p_var_type_name; + } } return "object"; @@ -477,8 +499,9 @@ String CSharpLanguage::make_function(const String &, const String &p_name, const for (int i = 0; i < p_args.size(); i++) { const String &arg = p_args[i]; - if (i > 0) + if (i > 0) { s += ", "; + } s += variant_type_to_managed_name(arg.get_slice(":", 1)) + " " + escape_csharp_keyword(arg.get_slice(":", 0)); } @@ -516,32 +539,36 @@ String CSharpLanguage::debug_get_error() const { } int CSharpLanguage::debug_get_stack_level_count() const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return 1; + } // TODO: StackTrace return 1; } int CSharpLanguage::debug_get_stack_level_line(int p_level) const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return _debug_parse_err_line; + } // TODO: StackTrace return 1; } String CSharpLanguage::debug_get_stack_level_function(int p_level) const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return String(); + } // TODO: StackTrace return String(); } String CSharpLanguage::debug_get_stack_level_source(int p_level) const { - if (_debug_parse_err_line >= 0) + if (_debug_parse_err_line >= 0) { return _debug_parse_err_file; + } // TODO: StackTrace return String(); @@ -551,15 +578,17 @@ Vector<ScriptLanguage::StackInfo> CSharpLanguage::debug_get_current_stack_info() #ifdef DEBUG_ENABLED // Printing an error here will result in endless recursion, so we must be careful static thread_local bool _recursion_flag_ = false; - if (_recursion_flag_) + if (_recursion_flag_) { return Vector<StackInfo>(); + } _recursion_flag_ = true; SCOPE_EXIT { _recursion_flag_ = false; }; GD_MONO_SCOPE_THREAD_ATTACH; - if (!gdmono->is_runtime_initialized() || !GDMono::get_singleton()->get_core_api_assembly() || !GDMonoCache::cached_data.corlib_cache_updated) + if (!gdmono->is_runtime_initialized() || !GDMono::get_singleton()->get_core_api_assembly() || !GDMonoCache::cached_data.corlib_cache_updated) { return Vector<StackInfo>(); + } MonoObject *stack_trace = mono_object_new(mono_domain_get(), CACHED_CLASS(System_Diagnostics_StackTrace)->get_mono_ptr()); @@ -581,8 +610,9 @@ Vector<ScriptLanguage::StackInfo> CSharpLanguage::debug_get_current_stack_info() Vector<ScriptLanguage::StackInfo> CSharpLanguage::stack_trace_get_info(MonoObject *p_stack_trace) { // Printing an error here will result in endless recursion, so we must be careful static thread_local bool _recursion_flag_ = false; - if (_recursion_flag_) + if (_recursion_flag_) { return Vector<StackInfo>(); + } _recursion_flag_ = true; SCOPE_EXIT { _recursion_flag_ = false; }; @@ -599,8 +629,9 @@ Vector<ScriptLanguage::StackInfo> CSharpLanguage::stack_trace_get_info(MonoObjec int frame_count = mono_array_length(frames); - if (frame_count <= 0) + if (frame_count <= 0) { return Vector<StackInfo>(); + } Vector<StackInfo> si; si.resize(frame_count); @@ -646,8 +677,9 @@ void CSharpLanguage::pre_unsafe_unreference(Object *p_obj) { ObjectID id = p_obj->get_instance_id(); Map<ObjectID, int>::Element *elem = unsafe_object_references.find(id); ERR_FAIL_NULL(elem); - if (--elem->value() == 0) + if (--elem->value() == 0) { unsafe_object_references.erase(elem); + } #endif } @@ -673,8 +705,9 @@ void CSharpLanguage::frame() { struct CSharpScriptDepSort { // must support sorting so inheritance works properly (parent must be reloaded first) bool operator()(const Ref<CSharpScript> &A, const Ref<CSharpScript> &B) const { - if (A == B) + if (A == B) { return false; // shouldn't happen but.. + } GDMonoClass *I = B->base; while (I) { if (I == A->script_class) { @@ -717,8 +750,9 @@ void CSharpLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_soft #ifdef GD_MONO_HOT_RELOAD bool CSharpLanguage::is_assembly_reloading_needed() { - if (!gdmono->is_runtime_initialized()) + if (!gdmono->is_runtime_initialized()) { return false; + } GDMonoAssembly *proj_assembly = gdmono->get_project_assembly(); @@ -736,23 +770,27 @@ bool CSharpLanguage::is_assembly_reloading_needed() { if (!FileAccess::exists(proj_asm_path)) { // Maybe it wasn't loaded from the default path, so check this as well proj_asm_path = GodotSharpDirs::get_res_temp_assemblies_dir().plus_file(appname_safe); - if (!FileAccess::exists(proj_asm_path)) + if (!FileAccess::exists(proj_asm_path)) { return false; // No assembly to load + } } - if (FileAccess::get_modified_time(proj_asm_path) <= proj_assembly->get_modified_time()) + if (FileAccess::get_modified_time(proj_asm_path) <= proj_assembly->get_modified_time()) { return false; // Already up to date + } } else { - if (!FileAccess::exists(GodotSharpDirs::get_res_temp_assemblies_dir().plus_file(appname_safe))) + if (!FileAccess::exists(GodotSharpDirs::get_res_temp_assemblies_dir().plus_file(appname_safe))) { return false; // No assembly to load + } } return true; } void CSharpLanguage::reload_assemblies(bool p_soft_reload) { - if (!gdmono->is_runtime_initialized()) + if (!gdmono->is_runtime_initialized()) { return; + } // There is no soft reloading with Mono. It's always hard reloading. @@ -858,8 +896,9 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { CSharpInstance *csi = static_cast<CSharpInstance *>(obj->get_script_instance()); // Call OnBeforeSerialize - if (csi->script->script_class->implements_interface(CACHED_CLASS(ISerializationListener))) + if (csi->script->script_class->implements_interface(CACHED_CLASS(ISerializationListener))) { obj->get_script_instance()->call_multilevel(string_names.on_before_serialize); + } // Save instance info CSharpScript::StateBackup state; @@ -894,8 +933,9 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { for (const Map<ObjectID, CSharpScript::StateBackup>::Element *F = scr->pending_reload_state.front(); F; F = F->next()) { Object *obj = ObjectDB::get_instance(F->key()); - if (!obj) + if (!obj) { continue; + } ObjectID obj_id = obj->get_instance_id(); @@ -1092,8 +1132,9 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) { } // Call OnAfterDeserialization - if (csi->script->script_class->implements_interface(CACHED_CLASS(ISerializationListener))) + if (csi->script->script_class->implements_interface(CACHED_CLASS(ISerializationListener))) { obj->get_script_instance()->call_multilevel(string_names.on_after_deserialize); + } } } @@ -1246,6 +1287,7 @@ void CSharpLanguage::_on_scripts_domain_unloaded() { script_binding.inited = false; } +#ifdef GD_MONO_HOT_RELOAD { MutexLock lock(ManagedCallable::instances_mutex); @@ -1255,6 +1297,7 @@ void CSharpLanguage::_on_scripts_domain_unloaded() { managed_callable->delegate_invoke = nullptr; } } +#endif scripts_metadata_invalidated = true; } @@ -1275,7 +1318,8 @@ void CSharpLanguage::_editor_init_callback() { GDMonoUtils::runtime_object_init(mono_object, editor_klass, &exc); UNHANDLED_EXCEPTION(exc); - EditorPlugin *godotsharp_editor = Object::cast_to<EditorPlugin>(GDMonoMarshal::mono_object_to_variant(mono_object)); + EditorPlugin *godotsharp_editor = Object::cast_to<EditorPlugin>( + GDMonoMarshal::mono_object_to_variant(mono_object).operator Object *()); CRASH_COND(godotsharp_editor == nullptr); // Enable it as a plugin @@ -1324,7 +1368,7 @@ CSharpLanguage::CSharpLanguage() { } CSharpLanguage::~CSharpLanguage() { - finish(); + finalize(); singleton = nullptr; } @@ -1341,8 +1385,9 @@ bool CSharpLanguage::setup_csharp_script_binding(CSharpScriptBinding &r_script_b // ¯\_(ツ)_/¯ const ClassDB::ClassInfo *classinfo = ClassDB::classes.getptr(type_name); - while (classinfo && !classinfo->exposed) + while (classinfo && !classinfo->exposed) { classinfo = classinfo->inherits_ptr; + } ERR_FAIL_NULL_V(classinfo, false); type_name = classinfo->name; @@ -1380,13 +1425,15 @@ void *CSharpLanguage::alloc_instance_binding_data(Object *p_object) { MutexLock lock(language_bind_mutex); Map<Object *, CSharpScriptBinding>::Element *match = script_bindings.find(p_object); - if (match) + if (match) { return (void *)match; + } CSharpScriptBinding script_binding; - if (!setup_csharp_script_binding(script_binding, p_object)) + if (!setup_csharp_script_binding(script_binding, p_object)) { return nullptr; + } return (void *)insert_script_binding(p_object, script_binding); } @@ -1404,8 +1451,9 @@ void CSharpLanguage::free_instance_binding_data(void *p_data) { return; } - if (finalizing) + if (finalizing) { return; // inside CSharpLanguage::finish(), all the gchandle bindings are released there + } GD_MONO_ASSERT_THREAD_ATTACHED; @@ -1444,8 +1492,9 @@ void CSharpLanguage::refcount_incremented_instance_binding(Object *p_object) { CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->get(); MonoGCHandleData &gchandle = script_binding.gchandle; - if (!script_binding.inited) + if (!script_binding.inited) { return; + } if (ref_owner->reference_get_count() > 1 && gchandle.is_weak()) { // The managed side also holds a reference, hence 1 instead of 0 GD_MONO_SCOPE_THREAD_ATTACH; @@ -1455,8 +1504,9 @@ void CSharpLanguage::refcount_incremented_instance_binding(Object *p_object) { // so the owner must hold the managed side alive again to avoid it from being GCed. MonoObject *target = gchandle.get_target(); - if (!target) + if (!target) { return; // Called after the managed side was collected, so nothing to do here + } // Release the current weak handle and replace it with a strong handle. MonoGCHandleData strong_gchandle = MonoGCHandleData::new_strong_handle(target); @@ -1481,8 +1531,9 @@ bool CSharpLanguage::refcount_decremented_instance_binding(Object *p_object) { int refcount = ref_owner->reference_get_count(); - if (!script_binding.inited) + if (!script_binding.inited) { return refcount == 0; + } if (refcount == 1 && !gchandle.is_released() && !gchandle.is_weak()) { // The managed side also holds a reference, hence 1 instead of 0 GD_MONO_SCOPE_THREAD_ATTACH; @@ -1491,8 +1542,9 @@ bool CSharpLanguage::refcount_decremented_instance_binding(Object *p_object) { // the managed instance takes responsibility of deleting the owner when GCed. MonoObject *target = gchandle.get_target(); - if (!target) + if (!target) { return refcount == 0; // Called after the managed side was collected, so nothing to do here + } // Release the current strong handle and replace it with a weak handle. MonoGCHandleData weak_gchandle = MonoGCHandleData::new_weak_handle(target); @@ -1514,8 +1566,9 @@ CSharpInstance *CSharpInstance::create_for_managed_type(Object *p_owner, CSharpS instance->owner = p_owner; instance->gchandle = p_gchandle; - if (instance->base_ref) + if (instance->base_ref) { instance->_reference_owner_unsafe(); + } p_script->instances.insert(p_owner); @@ -1572,8 +1625,9 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) { MonoObject *ret = method->invoke(mono_object, args); - if (ret && GDMonoMarshal::unbox<MonoBoolean>(ret)) + if (ret && GDMonoMarshal::unbox<MonoBoolean>(ret)) { return true; + } break; } @@ -1658,8 +1712,9 @@ void CSharpInstance::get_properties_state_for_reloading(List<Pair<StringName, Va ManagedType managedType; GDMonoField *field = script->script_class->get_field(state_pair.first); - if (!field) + if (!field) { continue; // Properties ignored. We get the property baking fields instead. + } managedType = field->get_type(); @@ -1679,8 +1734,9 @@ void CSharpInstance::get_event_signals_state_for_reloading(List<Pair<StringName, const CSharpScript::EventSignal &event_signal = E->value(); MonoDelegate *delegate_field_value = (MonoDelegate *)event_signal.field->get_value(owner_managed); - if (!delegate_field_value) + if (!delegate_field_value) { continue; // Empty + } Array serialized_data; MonoObject *managed_serialized_data = GDMonoMarshal::variant_to_mono_object(serialized_data); @@ -1725,8 +1781,9 @@ void CSharpInstance::get_property_list(List<PropertyInfo> *p_properties) const { if (ret) { Array array = Array(GDMonoMarshal::mono_object_to_variant(ret)); - for (int i = 0, size = array.size(); i < size; i++) + for (int i = 0, size = array.size(); i < size; i++) { p_properties->push_back(PropertyInfo::from_dict(array.get(i))); + } return; } @@ -1739,20 +1796,23 @@ void CSharpInstance::get_property_list(List<PropertyInfo> *p_properties) const { Variant::Type CSharpInstance::get_property_type(const StringName &p_name, bool *r_is_valid) const { if (script->member_info.has(p_name)) { - if (r_is_valid) + if (r_is_valid) { *r_is_valid = true; + } return script->member_info[p_name].type; } - if (r_is_valid) + if (r_is_valid) { *r_is_valid = false; + } return Variant::NIL; } bool CSharpInstance::has_method(const StringName &p_method) const { - if (!script.is_valid()) + if (!script.is_valid()) { return false; + } GD_MONO_SCOPE_THREAD_ATTACH; @@ -1868,8 +1928,9 @@ bool CSharpInstance::_unreference_owner_unsafe() { CRASH_COND(owner == nullptr); #endif - if (!unsafe_referenced) + if (!unsafe_referenced) { return false; // Already unreferenced + } unsafe_referenced = false; @@ -1902,7 +1963,7 @@ MonoObject *CSharpInstance::_internal_new_managed() { bool die = _unreference_owner_unsafe(); // Not ok for the owner to die here. If there is a situation where this can happen, it will be considered a bug. - CRASH_COND(die == true); + CRASH_COND(die); owner = nullptr; @@ -1912,8 +1973,9 @@ MonoObject *CSharpInstance::_internal_new_managed() { // Tie managed to unmanaged gchandle = MonoGCHandleData::new_strong_handle(mono_object); - if (base_ref) + if (base_ref) { _reference_owner_unsafe(); // Here, after assigning the gchandle (for the refcount_incremented callback) + } CACHED_FIELD(GodotObject, ptr)->set_value_raw(mono_object, owner); @@ -2130,7 +2192,7 @@ void CSharpInstance::_call_notification(int p_notification) { // Custom version of _call_multilevel, optimized for _notification - uint32_t arg = p_notification; + int32_t arg = p_notification; void *args[1] = { &arg }; StringName method_name = CACHED_STRING_NAME(_notification); @@ -2154,8 +2216,9 @@ String CSharpInstance::to_string(bool *r_valid) { MonoObject *mono_object = get_mono_object(); if (mono_object == nullptr) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } @@ -2164,14 +2227,16 @@ String CSharpInstance::to_string(bool *r_valid) { if (exc) { GDMonoUtils::set_pending_exception(exc); - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } if (result == nullptr) { - if (r_valid) + if (r_valid) { *r_valid = false; + } return String(); } @@ -2233,7 +2298,7 @@ CSharpInstance::~CSharpInstance() { // Unreference the owner here, before the new "instance binding" references it. // Otherwise, the unsafe reference debug checks will incorrectly detect a bug. bool die = _unreference_owner_unsafe(); - CRASH_COND(die == true); // `owner_keep_alive` holds a reference, so it can't die + CRASH_COND(die); // `owner_keep_alive` holds a reference, so it can't die void *data = owner->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index()); CRASH_COND(data == nullptr); @@ -2342,11 +2407,13 @@ void CSharpScript::_update_member_info_no_exports() { bool CSharpScript::_update_exports() { #ifdef TOOLS_ENABLED bool is_editor = Engine::get_singleton()->is_editor_hint(); - if (is_editor) + if (is_editor) { placeholder_fallback_enabled = true; // until proven otherwise + } #endif - if (!valid) + if (!valid) { return false; + } bool changed = false; @@ -2543,8 +2610,9 @@ void CSharpScript::load_script_signals(GDMonoClass *p_class, GDMonoClass *p_nati for (int i = delegates.size() - 1; i >= 0; --i) { GDMonoClass *delegate = delegates[i]; - if (!delegate->has_attribute(CACHED_CLASS(SignalAttribute))) + if (!delegate->has_attribute(CACHED_CLASS(SignalAttribute))) { continue; + } // Arguments are accessibles as arguments of .Invoke method GDMonoMethod *invoke_method = delegate->get_method(mono_get_delegate_invoke(delegate->get_mono_ptr())); @@ -2577,11 +2645,13 @@ void CSharpScript::load_script_signals(GDMonoClass *p_class, GDMonoClass *p_nati GDMonoClass *field_class = field->get_type().type_class; - if (!mono_class_is_delegate(field_class->get_mono_ptr())) + if (!mono_class_is_delegate(field_class->get_mono_ptr())) { continue; + } - if (!found_event_signals.find(field->get_name())) + if (!found_event_signals.find(field->get_name())) { continue; + } GDMonoMethod *invoke_method = field_class->get_method(mono_get_delegate_invoke(field_class->get_mono_ptr())); @@ -2640,14 +2710,16 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect if (p_member->is_static()) { #ifdef TOOLS_ENABLED - if (p_member->has_attribute(CACHED_CLASS(ExportAttribute))) + if (p_member->has_attribute(CACHED_CLASS(ExportAttribute))) { ERR_PRINT("Cannot export member because it is static: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); + } #endif return false; } - if (member_info.has(p_member->get_name())) + if (member_info.has(p_member->get_name())) { return false; + } ManagedType type; @@ -2665,15 +2737,17 @@ bool CSharpScript::_get_member_export(IMonoClassMember *p_member, bool p_inspect GDMonoProperty *property = static_cast<GDMonoProperty *>(p_member); if (!property->has_getter()) { #ifdef TOOLS_ENABLED - if (exported) + if (exported) { ERR_PRINT("Read-only property cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); + } #endif return false; } if (!property->has_setter()) { #ifdef TOOLS_ENABLED - if (exported) + if (exported) { ERR_PRINT("Write-only property (without getter) cannot be exported: '" + MEMBER_FULL_QUALIFIED_NAME(p_member) + "'."); + } #endif return false; } @@ -2802,8 +2876,9 @@ int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, Manage ManagedType elem_type; - if (!GDMonoMarshal::try_get_array_element_type(p_type, elem_type)) + if (!GDMonoMarshal::try_get_array_element_type(p_type, elem_type)) { return 0; + } Variant::Type elem_variant_type = GDMonoMarshal::managed_to_variant_type(elem_type); @@ -2830,15 +2905,6 @@ int CSharpScript::_try_get_member_export_hint(IMonoClassMember *p_member, Manage } #endif -void CSharpScript::_clear() { - tool = false; - valid = false; - - base = nullptr; - native = nullptr; - script_class = nullptr; -} - Variant CSharpScript::call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (unlikely(GDMono::get_singleton() == nullptr)) { // Probably not the best error but eh. @@ -2871,11 +2937,7 @@ Variant CSharpScript::call(const StringName &p_method, const Variant **p_args, i } void CSharpScript::_resource_path_changed() { - String path = get_path(); - - if (!path.empty()) { - name = get_path().get_file().get_basename(); - } + _update_name(); } bool CSharpScript::_get(const StringName &p_name, Variant &r_ret) const { @@ -2931,8 +2993,9 @@ void CSharpScript::initialize_for_managed_type(Ref<CSharpScript> p_script, GDMon GDMonoClass *base = p_script->script_class->get_parent_class(); - if (base != p_script->native) + if (base != p_script->native) { p_script->base = base; + } p_script->valid = true; p_script->tool = p_script->script_class->has_attribute(CACHED_CLASS(ToolAttribute)); @@ -2958,8 +3021,9 @@ void CSharpScript::initialize_for_managed_type(Ref<CSharpScript> p_script, GDMon while (native_top) { native_top->fetch_methods_with_godot_api_checks(p_script->native); - if (native_top == CACHED_CLASS(GodotObject)) + if (native_top == CACHED_CLASS(GodotObject)) { break; + } native_top = native_top->get_parent_class(); } @@ -3005,10 +3069,11 @@ bool CSharpScript::can_instance() const { } StringName CSharpScript::get_instance_base_type() const { - if (native) + if (native) { return native->get_name(); - else + } else { return StringName(); + } } CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Callable::CallError &r_error) { @@ -3071,7 +3136,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg bool die = instance->_unreference_owner_unsafe(); // Not ok for the owner to die here. If there is a situation where this can happen, it will be considered a bug. - CRASH_COND(die == true); + CRASH_COND(die); p_owner->set_script_instance(nullptr); r_error.error = Callable::CallError::CALL_ERROR_INSTANCE_IS_NULL; @@ -3081,8 +3146,9 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg // Tie managed to unmanaged instance->gchandle = MonoGCHandleData::new_strong_handle(mono_object); - if (instance->base_ref) + if (instance->base_ref) { instance->_reference_owner_unsafe(); // Here, after assigning the gchandle (for the refcount_incremented callback) + } { MutexLock lock(CSharpLanguage::get_singleton()->script_instances_mutex); @@ -3184,8 +3250,9 @@ String CSharpScript::get_source_code() const { } void CSharpScript::set_source_code(const String &p_code) { - if (source == p_code) + if (source == p_code) { return; + } source = p_code; #ifdef TOOLS_ENABLED source_changed_cache = true; @@ -3193,8 +3260,9 @@ void CSharpScript::set_source_code(const String &p_code) { } void CSharpScript::get_script_method_list(List<MethodInfo> *p_list) const { - if (!script_class) + if (!script_class) { return; + } GD_MONO_SCOPE_THREAD_ATTACH; @@ -3206,8 +3274,9 @@ void CSharpScript::get_script_method_list(List<MethodInfo> *p_list) const { } bool CSharpScript::has_method(const StringName &p_method) const { - if (!script_class) + if (!script_class) { return false; + } GD_MONO_SCOPE_THREAD_ATTACH; @@ -3215,8 +3284,9 @@ bool CSharpScript::has_method(const StringName &p_method) const { } MethodInfo CSharpScript::get_method_info(const StringName &p_method) const { - if (!script_class) + if (!script_class) { return MethodInfo(); + } GD_MONO_SCOPE_THREAD_ATTACH; @@ -3290,8 +3360,9 @@ Error CSharpScript::reload(bool p_keep_state) { GDMonoClass *base_class = script_class->get_parent_class(); - if (base_class != native) + if (base_class != native) { base = base_class; + } #ifdef DEBUG_ENABLED // For debug builds, we must fetch from all native base methods as well. @@ -3303,8 +3374,9 @@ Error CSharpScript::reload(bool p_keep_state) { while (native_top) { native_top->fetch_methods_with_godot_api_checks(native); - if (native_top == CACHED_CLASS(GodotObject)) + if (native_top == CACHED_CLASS(GodotObject)) { break; + } native_top = native_top->get_parent_class(); } @@ -3434,8 +3506,9 @@ void CSharpScript::get_script_signal_list(List<MethodInfo> *r_signals) const { const SignalParameter ¶m = params[i]; PropertyInfo arg_info = PropertyInfo(param.type, param.name); - if (param.type == Variant::NIL && param.nil_is_variant) + if (param.type == Variant::NIL && param.nil_is_variant) { arg_info.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + } mi.arguments.push_back(arg_info); } @@ -3453,8 +3526,9 @@ void CSharpScript::get_script_signal_list(List<MethodInfo> *r_signals) const { const SignalParameter ¶m = params[i]; PropertyInfo arg_info = PropertyInfo(param.type, param.name); - if (param.type == Variant::NIL && param.nil_is_variant) + if (param.type == Variant::NIL && param.nil_is_variant) { arg_info.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + } mi.arguments.push_back(arg_info); } @@ -3497,18 +3571,24 @@ int CSharpScript::get_member_line(const StringName &p_member) const { } MultiplayerAPI::RPCMode CSharpScript::_member_get_rpc_mode(IMonoClassMember *p_member) const { - if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute))) + if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute))) { return MultiplayerAPI::RPC_MODE_REMOTE; - if (p_member->has_attribute(CACHED_CLASS(MasterAttribute))) + } + if (p_member->has_attribute(CACHED_CLASS(MasterAttribute))) { return MultiplayerAPI::RPC_MODE_MASTER; - if (p_member->has_attribute(CACHED_CLASS(PuppetAttribute))) + } + if (p_member->has_attribute(CACHED_CLASS(PuppetAttribute))) { return MultiplayerAPI::RPC_MODE_PUPPET; - if (p_member->has_attribute(CACHED_CLASS(RemoteSyncAttribute))) + } + if (p_member->has_attribute(CACHED_CLASS(RemoteSyncAttribute))) { return MultiplayerAPI::RPC_MODE_REMOTESYNC; - if (p_member->has_attribute(CACHED_CLASS(MasterSyncAttribute))) + } + if (p_member->has_attribute(CACHED_CLASS(MasterSyncAttribute))) { return MultiplayerAPI::RPC_MODE_MASTERSYNC; - if (p_member->has_attribute(CACHED_CLASS(PuppetSyncAttribute))) + } + if (p_member->has_attribute(CACHED_CLASS(PuppetSyncAttribute))) { return MultiplayerAPI::RPC_MODE_PUPPETSYNC; + } return MultiplayerAPI::RPC_MODE_DISABLED; } @@ -3583,14 +3663,27 @@ Error CSharpScript::load_source_code(const String &p_path) { return OK; } -StringName CSharpScript::get_script_name() const { - return name; +void CSharpScript::_update_name() { + String path = get_path(); + + if (!path.empty()) { + name = get_path().get_file().get_basename(); + } +} + +void CSharpScript::_clear() { + tool = false; + valid = false; + + base = nullptr; + native = nullptr; + script_class = nullptr; } CSharpScript::CSharpScript() { _clear(); - _resource_path_changed(); + _update_name(); #ifdef DEBUG_ENABLED { @@ -3620,8 +3713,9 @@ void CSharpScript::get_members(Set<StringName> *p_members) { /*************** RESOURCE ***************/ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) { - if (r_error) + if (r_error) { *r_error = ERR_FILE_CANT_OPEN; + } // TODO ignore anything inside bin/ and obj/ in tools builds? @@ -3638,8 +3732,9 @@ RES ResourceFormatLoaderCSharpScript::load(const String &p_path, const String &p script->reload(); - if (r_error) + if (r_error) { *r_error = OK; + } return scriptres; } diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h index 0bf08ceafd..c2370364f9 100644 --- a/modules/mono/csharp_script.h +++ b/modules/mono/csharp_script.h @@ -135,7 +135,7 @@ private: bool exports_invalidated = true; void _update_exports_values(Map<StringName, Variant> &values, List<PropertyInfo> &propnames); void _update_member_info_no_exports(); - virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); + void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; #endif #if defined(TOOLS_ENABLED) || defined(DEBUG_ENABLED) @@ -146,6 +146,8 @@ private: void _clear(); + void _update_name(); + void load_script_signals(GDMonoClass *p_class, GDMonoClass *p_native_class); bool _get_signal(GDMonoClass *p_class, GDMonoMethod *p_delegate_invoke, Vector<SignalParameter> ¶ms); @@ -169,68 +171,66 @@ private: protected: static void _bind_methods(); - Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); - virtual void _resource_path_changed(); + Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override; + void _resource_path_changed() override; bool _get(const StringName &p_name, Variant &r_ret) const; bool _set(const StringName &p_name, const Variant &p_value); void _get_property_list(List<PropertyInfo> *p_properties) const; public: - virtual bool can_instance() const; - virtual StringName get_instance_base_type() const; - virtual ScriptInstance *instance_create(Object *p_this); - virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this); - virtual bool instance_has(const Object *p_this) const; + bool can_instance() const override; + StringName get_instance_base_type() const override; + ScriptInstance *instance_create(Object *p_this) override; + PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override; + bool instance_has(const Object *p_this) const override; - virtual bool has_source_code() const; - virtual String get_source_code() const; - virtual void set_source_code(const String &p_code); + bool has_source_code() const override; + String get_source_code() const override; + void set_source_code(const String &p_code) override; - virtual Error reload(bool p_keep_state = false); + Error reload(bool p_keep_state = false) override; - virtual bool has_script_signal(const StringName &p_signal) const; - virtual void get_script_signal_list(List<MethodInfo> *r_signals) const; + bool has_script_signal(const StringName &p_signal) const override; + void get_script_signal_list(List<MethodInfo> *r_signals) const override; - virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const; - virtual void get_script_property_list(List<PropertyInfo> *p_list) const; - virtual void update_exports(); + bool get_property_default_value(const StringName &p_property, Variant &r_value) const override; + void get_script_property_list(List<PropertyInfo> *p_list) const override; + void update_exports() override; void get_members(Set<StringName> *p_members) override; - virtual bool is_tool() const { return tool; } - virtual bool is_valid() const { return valid; } + bool is_tool() const override { return tool; } + bool is_valid() const override { return valid; } - bool inherits_script(const Ref<Script> &p_script) const; + bool inherits_script(const Ref<Script> &p_script) const override; - virtual Ref<Script> get_base_script() const; - virtual ScriptLanguage *get_language() const; + Ref<Script> get_base_script() const override; + ScriptLanguage *get_language() const override; - virtual void get_script_method_list(List<MethodInfo> *p_list) const; - bool has_method(const StringName &p_method) const; - MethodInfo get_method_info(const StringName &p_method) const; + void get_script_method_list(List<MethodInfo> *p_list) const override; + bool has_method(const StringName &p_method) const override; + MethodInfo get_method_info(const StringName &p_method) const override; - virtual int get_member_line(const StringName &p_member) const; + int get_member_line(const StringName &p_member) const override; - virtual Vector<ScriptNetData> get_rpc_methods() const; - virtual uint16_t get_rpc_method_id(const StringName &p_method) const; - virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const; + Vector<ScriptNetData> get_rpc_methods() const override; + uint16_t get_rpc_method_id(const StringName &p_method) const override; + StringName get_rpc_method(const uint16_t p_rpc_method_id) const override; + MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const override; + MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const override; - virtual Vector<ScriptNetData> get_rset_properties() const; - virtual uint16_t get_rset_property_id(const StringName &p_variable) const; - virtual StringName get_rset_property(const uint16_t p_variable_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const; + Vector<ScriptNetData> get_rset_properties() const override; + uint16_t get_rset_property_id(const StringName &p_variable) const override; + StringName get_rset_property(const uint16_t p_variable_id) const override; + MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const override; + MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const override; #ifdef TOOLS_ENABLED - virtual bool is_placeholder_fallback_enabled() const { return placeholder_fallback_enabled; } + bool is_placeholder_fallback_enabled() const override { return placeholder_fallback_enabled; } #endif Error load_source_code(const String &p_path); - StringName get_script_name() const; - CSharpScript(); ~CSharpScript(); }; @@ -249,8 +249,6 @@ class CSharpInstance : public ScriptInstance { Ref<CSharpScript> script; MonoGCHandleData gchandle; - Vector<Callable> event_signal_callables; - bool _reference_owner_unsafe(); /* @@ -277,18 +275,18 @@ public: _FORCE_INLINE_ bool is_destructing_script_instance() { return destructing_script_instance; } - virtual Object *get_owner(); + Object *get_owner() override; - virtual bool set(const StringName &p_name, const Variant &p_value); - virtual bool get(const StringName &p_name, Variant &r_ret) const; - virtual void get_property_list(List<PropertyInfo> *p_properties) const; - virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const; + bool set(const StringName &p_name, const Variant &p_value) override; + bool get(const StringName &p_name, Variant &r_ret) const override; + void get_property_list(List<PropertyInfo> *p_properties) const override; + Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const override; - /* TODO */ virtual void get_method_list(List<MethodInfo> *p_list) const {} - virtual bool has_method(const StringName &p_method) const; - virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); - virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount); - virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount); + /* TODO */ void get_method_list(List<MethodInfo> *p_list) const override {} + bool has_method(const StringName &p_method) const override; + Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override; + void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount) override; + void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount) override; void mono_object_disposed(MonoObject *p_obj); @@ -301,29 +299,29 @@ public: void connect_event_signals(); void disconnect_event_signals(); - virtual void refcount_incremented(); - virtual bool refcount_decremented(); + void refcount_incremented() override; + bool refcount_decremented() override; - virtual Vector<ScriptNetData> get_rpc_methods() const; - virtual uint16_t get_rpc_method_id(const StringName &p_method) const; - virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const; + Vector<ScriptNetData> get_rpc_methods() const override; + uint16_t get_rpc_method_id(const StringName &p_method) const override; + StringName get_rpc_method(const uint16_t p_rpc_method_id) const override; + MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const override; + MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const override; - virtual Vector<ScriptNetData> get_rset_properties() const; - virtual uint16_t get_rset_property_id(const StringName &p_variable) const; - virtual StringName get_rset_property(const uint16_t p_variable_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const; + Vector<ScriptNetData> get_rset_properties() const override; + uint16_t get_rset_property_id(const StringName &p_variable) const override; + StringName get_rset_property(const uint16_t p_variable_id) const override; + MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_variable_id) const override; + MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const override; - virtual void notification(int p_notification); + void notification(int p_notification) override; void _call_notification(int p_notification); - virtual String to_string(bool *r_valid); + String to_string(bool *r_valid) override; - virtual Ref<Script> get_script() const; + Ref<Script> get_script() const override; - virtual ScriptLanguage *get_language(); + ScriptLanguage *get_language() override; CSharpInstance(const Ref<CSharpScript> &p_script); ~CSharpInstance(); @@ -437,83 +435,90 @@ public: } _FORCE_INLINE_ const Dictionary &get_scripts_metadata() { - if (scripts_metadata_invalidated) + if (scripts_metadata_invalidated) { _load_scripts_metadata(); + } return scripts_metadata; } _FORCE_INLINE_ ManagedCallableMiddleman *get_managed_callable_middleman() const { return managed_callable_middleman; } - virtual String get_name() const; + String get_name() const override; /* LANGUAGE FUNCTIONS */ - virtual String get_type() const; - virtual String get_extension() const; - virtual Error execute_file(const String &p_path); - virtual void init(); - virtual void finish(); + String get_type() const override; + String get_extension() const override; + Error execute_file(const String &p_path) override; + void init() override; + void finish() override; + + void finalize(); /* EDITOR FUNCTIONS */ - virtual void get_reserved_words(List<String> *p_words) const; - virtual void get_comment_delimiters(List<String> *p_delimiters) const; - virtual void get_string_delimiters(List<String> *p_delimiters) const; - virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const; - virtual bool is_using_templates(); - virtual void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script); - /* TODO */ virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path, List<String> *r_functions, List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const { return true; } - virtual String validate_path(const String &p_path) const; - virtual Script *create_script() const; - virtual bool has_named_classes() const; - virtual bool supports_builtin_mode() const; - /* TODO? */ virtual int find_function(const String &p_function, const String &p_code) const { return -1; } - virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const; + void get_reserved_words(List<String> *p_words) const override; + void get_comment_delimiters(List<String> *p_delimiters) const override; + void get_string_delimiters(List<String> *p_delimiters) const override; + Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const override; + bool is_using_templates() override; + void make_template(const String &p_class_name, const String &p_base_class_name, Ref<Script> &p_script) override; + /* TODO */ bool validate(const String &p_script, int &r_line_error, int &r_col_error, + String &r_test_error, const String &p_path, List<String> *r_functions, + List<ScriptLanguage::Warning> *r_warnings = nullptr, Set<int> *r_safe_lines = nullptr) const override { + return true; + } + String validate_path(const String &p_path) const override; + Script *create_script() const override; + bool has_named_classes() const override; + bool supports_builtin_mode() const override; + /* TODO? */ int find_function(const String &p_function, const String &p_code) const override { return -1; } + String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override; virtual String _get_indentation() const; - /* TODO? */ virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const {} - /* TODO */ virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) {} + /* TODO? */ void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override {} + /* TODO */ void add_global_constant(const StringName &p_variable, const Variant &p_value) override {} /* DEBUGGER FUNCTIONS */ - virtual String debug_get_error() const; - virtual int debug_get_stack_level_count() const; - virtual int debug_get_stack_level_line(int p_level) const; - virtual String debug_get_stack_level_function(int p_level) const; - virtual String debug_get_stack_level_source(int p_level) const; - /* TODO */ virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {} - /* TODO */ virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {} - /* TODO */ virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {} - /* TODO */ virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { return ""; } - virtual Vector<StackInfo> debug_get_current_stack_info(); + String debug_get_error() const override; + int debug_get_stack_level_count() const override; + int debug_get_stack_level_line(int p_level) const override; + String debug_get_stack_level_function(int p_level) const override; + String debug_get_stack_level_source(int p_level) const override; + /* TODO */ void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) override {} + /* TODO */ void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) override {} + /* TODO */ void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) override {} + /* TODO */ String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) override { return ""; } + Vector<StackInfo> debug_get_current_stack_info() override; /* PROFILING FUNCTIONS */ - /* TODO */ virtual void profiling_start() {} - /* TODO */ virtual void profiling_stop() {} - /* TODO */ virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { return 0; } - /* TODO */ virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { return 0; } + /* TODO */ void profiling_start() override {} + /* TODO */ void profiling_stop() override {} + /* TODO */ int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override { return 0; } + /* TODO */ int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override { return 0; } - virtual void frame(); + void frame() override; - /* TODO? */ virtual void get_public_functions(List<MethodInfo> *p_functions) const {} - /* TODO? */ virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const {} + /* TODO? */ void get_public_functions(List<MethodInfo> *p_functions) const override {} + /* TODO? */ void get_public_constants(List<Pair<String, Variant>> *p_constants) const override {} - virtual void reload_all_scripts(); - virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload); + void reload_all_scripts() override; + void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override; /* LOADER FUNCTIONS */ - virtual void get_recognized_extensions(List<String> *p_extensions) const; + void get_recognized_extensions(List<String> *p_extensions) const override; #ifdef TOOLS_ENABLED - virtual Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col); - virtual bool overrides_external_editor(); + Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) override; + bool overrides_external_editor() override; #endif /* THREAD ATTACHING */ - virtual void thread_enter(); - virtual void thread_exit(); + void thread_enter() override; + void thread_exit() override; // Don't use these. I'm watching you - virtual void *alloc_instance_binding_data(Object *p_object); - virtual void free_instance_binding_data(void *p_data); - virtual void refcount_incremented_instance_binding(Object *p_object); - virtual bool refcount_decremented_instance_binding(Object *p_object); + void *alloc_instance_binding_data(Object *p_object) override; + void free_instance_binding_data(void *p_data) override; + void refcount_incremented_instance_binding(Object *p_object) override; + bool refcount_decremented_instance_binding(Object *p_object) override; Map<Object *, CSharpScriptBinding>::Element *insert_script_binding(Object *p_object, const CSharpScriptBinding &p_script_binding); bool setup_csharp_script_binding(CSharpScriptBinding &r_script_binding, Object *p_object); @@ -531,17 +536,17 @@ public: class ResourceFormatLoaderCSharpScript : public ResourceFormatLoader { public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false); - 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; + RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false) override; + void get_recognized_extensions(List<String> *p_extensions) const override; + bool handles_type(const String &p_type) const override; + String get_resource_type(const String &p_path) const override; }; class ResourceFormatSaverCSharpScript : public ResourceFormatSaver { public: - virtual Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0); - virtual void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const; - virtual bool recognize(const RES &p_resource) const; + Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override; + void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override; + bool recognize(const RES &p_resource) const override; }; #endif // CSHARP_SCRIPT_H diff --git a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging.CLI/Program.cs b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging.CLI/Program.cs index 99a55c471b..4db71500da 100644 --- a/modules/mono/editor/GodotTools/GodotTools.IdeMessaging.CLI/Program.cs +++ b/modules/mono/editor/GodotTools/GodotTools.IdeMessaging.CLI/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Reflection; diff --git a/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/Program.cs b/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/Program.cs index affb2a47e7..ce2b378623 100644 --- a/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/Program.cs +++ b/modules/mono/editor/GodotTools/GodotTools.OpenVisualStudio/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index 730ffcb945..79e4b7c794 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -62,10 +62,8 @@ #define OPEN_BLOCK_L2 INDENT2 OPEN_BLOCK INDENT3 #define OPEN_BLOCK_L3 INDENT3 OPEN_BLOCK INDENT4 -#define OPEN_BLOCK_L4 INDENT4 OPEN_BLOCK INDENT5 #define CLOSE_BLOCK_L2 INDENT2 CLOSE_BLOCK #define CLOSE_BLOCK_L3 INDENT3 CLOSE_BLOCK -#define CLOSE_BLOCK_L4 INDENT4 CLOSE_BLOCK #define CS_FIELD_MEMORYOWN "memoryOwn" #define CS_PARAM_METHODBIND "method" diff --git a/modules/mono/editor/code_completion.cpp b/modules/mono/editor/code_completion.cpp index 7a5e465e7a..942c6d26a6 100644 --- a/modules/mono/editor/code_completion.cpp +++ b/modules/mono/editor/code_completion.cpp @@ -45,8 +45,9 @@ _FORCE_INLINE_ String quoted(const String &p_str) { } void _add_nodes_suggestions(const Node *p_base, const Node *p_node, PackedStringArray &r_suggestions) { - if (p_node != p_base && !p_node->get_owner()) + if (p_node != p_base && !p_node->get_owner()) { return; + } String path_relative_to_orig = p_base->get_path_to(p_node); @@ -58,18 +59,21 @@ void _add_nodes_suggestions(const Node *p_base, const Node *p_node, PackedString } Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) { - if (p_current->get_owner() != p_base && p_base != p_current) + if (p_current->get_owner() != p_base && p_base != p_current) { return nullptr; + } Ref<Script> c = p_current->get_script(); - if (c == p_script) + if (c == p_script) { return p_current; + } for (int i = 0; i < p_current->get_child_count(); i++) { Node *found = _find_node_for_script(p_base, p_current->get_child(i), p_script); - if (found) + if (found) { return found; + } } return nullptr; @@ -87,8 +91,9 @@ void _get_directory_contents(EditorFileSystemDirectory *p_dir, PackedStringArray Node *_try_find_owner_node_in_tree(const Ref<Script> p_script) { SceneTree *tree = SceneTree::get_singleton(); - if (!tree) + if (!tree) { return nullptr; + } Node *base = tree->get_edited_scene_root(); if (base) { base = _find_node_for_script(base, base, p_script); @@ -107,8 +112,9 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr for (List<PropertyInfo>::Element *E = project_props.front(); E; E = E->next()) { const PropertyInfo &prop = E->get(); - if (!prop.name.begins_with("input/")) + if (!prop.name.begins_with("input/")) { continue; + } String name = prop.name.substr(prop.name.find("/") + 1, prop.name.length()); suggestions.push_back(quoted(name)); @@ -117,16 +123,11 @@ PackedStringArray get_code_completion(CompletionKind p_kind, const String &p_scr case CompletionKind::NODE_PATHS: { { // AutoLoads - List<PropertyInfo> props; - ProjectSettings::get_singleton()->get_property_list(&props); + Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); - for (List<PropertyInfo>::Element *E = props.front(); E; E = E->next()) { - String s = E->get().name; - if (!s.begins_with("autoload/")) { - continue; - } - String name = s.get_slice("/", 1); - suggestions.push_back(quoted("/root/" + name)); + for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) { + const ProjectSettings::AutoloadInfo &info = E->value(); + suggestions.push_back(quoted("/root/" + String(info.name))); } } diff --git a/modules/mono/editor/csharp_project.cpp b/modules/mono/editor/csharp_project.cpp index 3a30f3106c..6f54eb09a2 100644 --- a/modules/mono/editor/csharp_project.cpp +++ b/modules/mono/editor/csharp_project.cpp @@ -45,8 +45,9 @@ namespace CSharpProject { void add_item(const String &p_project_path, const String &p_item_type, const String &p_include) { - if (!GLOBAL_DEF("mono/project/auto_update_project", true)) + if (!GLOBAL_DEF("mono/project/auto_update_project", true)) { return; + } GDMonoAssembly *tools_project_editor_assembly = GDMono::get_singleton()->get_tools_project_editor_assembly(); diff --git a/modules/mono/editor/editor_internal_calls.cpp b/modules/mono/editor/editor_internal_calls.cpp index b183787618..68fc372959 100644 --- a/modules/mono/editor/editor_internal_calls.cpp +++ b/modules/mono/editor/editor_internal_calls.cpp @@ -324,7 +324,7 @@ MonoObject *godot_icall_Internal_GetScriptsMetadataOrNothing(MonoReflectionType MonoType *dict_type = mono_reflection_type_get_type(p_dict_reftype); - uint32_t type_encoding = mono_type_get_type(dict_type); + int type_encoding = mono_type_get_type(dict_type); MonoClass *type_class_raw = mono_class_from_mono_type(dict_type); GDMonoClass *type_class = GDMono::get_singleton()->get_class(type_class_raw); diff --git a/modules/mono/editor/godotsharp_export.cpp b/modules/mono/editor/godotsharp_export.cpp index 1cdb08d50e..b15e9b060a 100644 --- a/modules/mono/editor/godotsharp_export.cpp +++ b/modules/mono/editor/godotsharp_export.cpp @@ -75,8 +75,9 @@ Error get_assembly_dependencies(GDMonoAssembly *p_assembly, const Vector<String> const String &ref_name = ref_info.name; - if (r_assembly_dependencies.has(ref_name)) + if (r_assembly_dependencies.has(ref_name)) { continue; + } GDMonoAssembly *ref_assembly = nullptr; @@ -130,8 +131,9 @@ Error get_exported_assembly_dependencies(const Dictionary &p_initial_assemblies, ERR_FAIL_COND_V_MSG(!load_success, ERR_CANT_RESOLVE, "Cannot load assembly (refonly): '" + assembly_name + "'."); Error err = get_assembly_dependencies(assembly, search_dirs, r_assembly_dependencies); - if (err != OK) + if (err != OK) { return err; + } } return OK; diff --git a/modules/mono/editor/script_class_parser.cpp b/modules/mono/editor/script_class_parser.cpp index 7276612230..012ccd5339 100644 --- a/modules/mono/editor/script_class_parser.cpp +++ b/modules/mono/editor/script_class_parser.cpp @@ -208,8 +208,9 @@ ScriptClassParser::Token ScriptClassParser::get_token() { tk_string += res; } else { - if (code[idx] == '\n') + if (code[idx] == '\n') { line++; + } tk_string += code[idx]; } idx++; @@ -300,15 +301,17 @@ Error ScriptClassParser::_skip_generic_type_params() { tk = get_token(); - if (tk != TK_PERIOD) + if (tk != TK_PERIOD) { break; + } } } if (tk == TK_OP_LESS) { Error err = _skip_generic_type_params(); - if (err) + if (err) { return err; + } tk = get_token(); } @@ -349,12 +352,14 @@ Error ScriptClassParser::_parse_type_full_name(String &r_full_name) { // We don't mind if the base is generic, but we skip it any ways since this information is not needed Error err = _skip_generic_type_params(); - if (err) + if (err) { return err; + } } - if (code[idx] != '.') // We only want to take the next token if it's a period + if (code[idx] != '.') { // We only want to take the next token if it's a period return OK; + } tk = get_token(); @@ -369,15 +374,17 @@ Error ScriptClassParser::_parse_class_base(Vector<String> &r_base) { String name; Error err = _parse_type_full_name(name); - if (err) + if (err) { return err; + } Token tk = get_token(); if (tk == TK_COMMA) { err = _parse_class_base(r_base); - if (err) + if (err) { return err; + } } else if (tk == TK_IDENTIFIER && String(value) == "where") { err = _parse_type_constraints(); if (err) { @@ -433,8 +440,9 @@ Error ScriptClassParser::_parse_type_constraints() { tk = get_token(); - if (tk != TK_PERIOD) + if (tk != TK_PERIOD) { break; + } } } } @@ -452,8 +460,9 @@ Error ScriptClassParser::_parse_type_constraints() { } } else if (tk == TK_OP_LESS) { Error err = _skip_generic_type_params(); - if (err) + if (err) { return err; + } } else if (tk == TK_CURLY_BRACKET_OPEN) { return OK; } else { @@ -522,8 +531,9 @@ Error ScriptClassParser::parse(const String &p_code) { const NameDecl &name_decl = E->value(); if (name_decl.type == NameDecl::NAMESPACE_DECL) { - if (E != name_stack.front()) + if (E != name_stack.front()) { class_decl.namespace_ += "."; + } class_decl.namespace_ += name_decl.name; } else { class_decl.name += name_decl.name + "."; @@ -540,8 +550,9 @@ Error ScriptClassParser::parse(const String &p_code) { if (tk == TK_COLON) { Error err = _parse_class_base(class_decl.base); - if (err) + if (err) { return err; + } curly_stack++; type_curly_stack++; @@ -555,8 +566,9 @@ Error ScriptClassParser::parse(const String &p_code) { generic = true; Error err = _skip_generic_type_params(); - if (err) + if (err) { return err; + } } else if (tk == TK_IDENTIFIER && String(value) == "where") { Error err = _parse_type_constraints(); if (err) { @@ -584,8 +596,9 @@ Error ScriptClassParser::parse(const String &p_code) { classes.push_back(class_decl); } else if (OS::get_singleton()->is_stdout_verbose()) { String full_name = class_decl.namespace_; - if (full_name.length()) + if (full_name.length()) { full_name += "."; + } full_name += class_decl.name; OS::get_singleton()->print("Ignoring generic class declaration: %s\n", full_name.utf8().get_data()); } @@ -602,8 +615,9 @@ Error ScriptClassParser::parse(const String &p_code) { int at_level = curly_stack; Error err = _parse_namespace_name(name, curly_stack); - if (err) + if (err) { return err; + } NameDecl name_decl; name_decl.name = name; @@ -614,8 +628,9 @@ Error ScriptClassParser::parse(const String &p_code) { } else if (tk == TK_CURLY_BRACKET_CLOSE) { curly_stack--; if (name_stack.has(curly_stack)) { - if (name_stack[curly_stack].type != NameDecl::NAMESPACE_DECL) + if (name_stack[curly_stack].type != NameDecl::NAMESPACE_DECL) { type_curly_stack--; + } name_stack.erase(curly_stack); } } @@ -628,8 +643,9 @@ Error ScriptClassParser::parse(const String &p_code) { error = true; } - if (error) + if (error) { return ERR_PARSE_ERROR; + } return OK; } @@ -702,8 +718,9 @@ static void run_dummy_preprocessor(String &r_source, const String &p_filepath) { // Custom join ignoring lines removed by the preprocessor for (int i = 0; i < lines.size(); i++) { - if (i > 0 && include_lines[i - 1]) + if (i > 0 && include_lines[i - 1]) { r_source += '\n'; + } if (include_lines[i]) { r_source += lines[i]; diff --git a/modules/mono/editor/script_class_parser.h b/modules/mono/editor/script_class_parser.h index c194ed1422..d611e8fb74 100644 --- a/modules/mono/editor/script_class_parser.h +++ b/modules/mono/editor/script_class_parser.h @@ -53,7 +53,6 @@ public: String namespace_; Vector<String> base; bool nested; - bool has_script_attr; }; private: diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs index 6a4f785551..3aecce50f5 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/AABB.cs @@ -14,6 +14,10 @@ using real_t = System.Single; namespace Godot { + /// <summary> + /// Axis-Aligned Bounding Box. AABB consists of a position, a size, and + /// several utility functions. It is typically used for fast overlap tests. + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct AABB : IEquatable<AABB> @@ -21,24 +25,55 @@ namespace Godot private Vector3 _position; private Vector3 _size; + /// <summary> + /// Beginning corner. Typically has values lower than End. + /// </summary> + /// <value>Directly uses a private field.</value> public Vector3 Position { get { return _position; } set { _position = value; } } + /// <summary> + /// Size from Position to End. Typically all components are positive. + /// If the size is negative, you can use <see cref="Abs"/> to fix it. + /// </summary> + /// <value>Directly uses a private field.</value> public Vector3 Size { get { return _size; } set { _size = value; } } + /// <summary> + /// Ending corner. This is calculated as <see cref="Position"/> plus + /// <see cref="Size"/>. Setting this value will change the size. + /// </summary> + /// <value>Getting is equivalent to `value = Position + Size`, setting is equivalent to `Size = value - Position`.</value> public Vector3 End { get { return _position + _size; } set { _size = value - _position; } } + /// <summary> + /// Returns an AABB with equivalent position and size, modified so that + /// the most-negative corner is the origin and the size is positive. + /// </summary> + /// <returns>The modified AABB.</returns> + public AABB Abs() + { + Vector3 end = End; + Vector3 topLeft = new Vector3(Mathf.Min(_position.x, end.x), Mathf.Min(_position.y, end.y), Mathf.Min(_position.z, end.z)); + return new AABB(topLeft, _size.Abs()); + } + + /// <summary> + /// Returns true if this AABB completely encloses another one. + /// </summary> + /// <param name="with">The other AABB that may be enclosed.</param> + /// <returns>A bool for whether or not this AABB encloses `b`.</returns> public bool Encloses(AABB with) { Vector3 src_min = _position; @@ -54,33 +89,59 @@ namespace Godot src_max.z > dst_max.z; } + /// <summary> + /// Returns this AABB expanded to include a given point. + /// </summary> + /// <param name="point">The point to include.</param> + /// <returns>The expanded AABB.</returns> public AABB Expand(Vector3 point) { Vector3 begin = _position; Vector3 end = _position + _size; if (point.x < begin.x) + { begin.x = point.x; + } if (point.y < begin.y) + { begin.y = point.y; + } if (point.z < begin.z) + { begin.z = point.z; + } if (point.x > end.x) + { end.x = point.x; + } if (point.y > end.y) + { end.y = point.y; + } if (point.z > end.z) + { end.z = point.z; + } return new AABB(begin, end - begin); } + /// <summary> + /// Returns the area of the AABB. + /// </summary> + /// <returns>The area.</returns> public real_t GetArea() { return _size.x * _size.y * _size.z; } + /// <summary> + /// Gets the position of one of the 8 endpoints of the AABB. + /// </summary> + /// <param name="idx">Which endpoint to get.</param> + /// <returns>An endpoint of the AABB.</returns> public Vector3 GetEndpoint(int idx) { switch (idx) @@ -106,6 +167,10 @@ namespace Godot } } + /// <summary> + /// Returns the normalized longest axis of the AABB. + /// </summary> + /// <returns>A vector representing the normalized longest axis of the AABB.</returns> public Vector3 GetLongestAxis() { var axis = new Vector3(1f, 0f, 0f); @@ -125,6 +190,10 @@ namespace Godot return axis; } + /// <summary> + /// Returns the <see cref="Vector3.Axis"/> index of the longest axis of the AABB. + /// </summary> + /// <returns>A <see cref="Vector3.Axis"/> index for which axis is longest.</returns> public Vector3.Axis GetLongestAxisIndex() { var axis = Vector3.Axis.X; @@ -144,6 +213,10 @@ namespace Godot return axis; } + /// <summary> + /// Returns the scalar length of the longest axis of the AABB. + /// </summary> + /// <returns>The scalar length of the longest axis of the AABB.</returns> public real_t GetLongestAxisSize() { real_t max_size = _size.x; @@ -157,6 +230,10 @@ namespace Godot return max_size; } + /// <summary> + /// Returns the normalized shortest axis of the AABB. + /// </summary> + /// <returns>A vector representing the normalized shortest axis of the AABB.</returns> public Vector3 GetShortestAxis() { var axis = new Vector3(1f, 0f, 0f); @@ -176,6 +253,10 @@ namespace Godot return axis; } + /// <summary> + /// Returns the <see cref="Vector3.Axis"/> index of the shortest axis of the AABB. + /// </summary> + /// <returns>A <see cref="Vector3.Axis"/> index for which axis is shortest.</returns> public Vector3.Axis GetShortestAxisIndex() { var axis = Vector3.Axis.X; @@ -195,6 +276,10 @@ namespace Godot return axis; } + /// <summary> + /// Returns the scalar length of the shortest axis of the AABB. + /// </summary> + /// <returns>The scalar length of the shortest axis of the AABB.</returns> public real_t GetShortestAxisSize() { real_t max_size = _size.x; @@ -208,6 +293,12 @@ namespace Godot return max_size; } + /// <summary> + /// Returns the support point in a given direction. + /// This is useful for collision detection algorithms. + /// </summary> + /// <param name="dir">The direction to find support for.</param> + /// <returns>A vector representing the support.</returns> public Vector3 GetSupport(Vector3 dir) { Vector3 half_extents = _size * 0.5f; @@ -219,6 +310,11 @@ namespace Godot dir.z > 0f ? -half_extents.z : half_extents.z); } + /// <summary> + /// Returns a copy of the AABB grown a given amount of units towards all the sides. + /// </summary> + /// <param name="by">The amount to grow by.</param> + /// <returns>The grown AABB.</returns> public AABB Grow(real_t by) { var res = this; @@ -233,16 +329,29 @@ namespace Godot return res; } + /// <summary> + /// Returns true if the AABB is flat or empty, or false otherwise. + /// </summary> + /// <returns>A bool for whether or not the AABB has area.</returns> public bool HasNoArea() { return _size.x <= 0f || _size.y <= 0f || _size.z <= 0f; } + /// <summary> + /// Returns true if the AABB has no surface (no size), or false otherwise. + /// </summary> + /// <returns>A bool for whether or not the AABB has area.</returns> public bool HasNoSurface() { return _size.x <= 0f && _size.y <= 0f && _size.z <= 0f; } + /// <summary> + /// Returns true if the AABB contains a point, or false otherwise. + /// </summary> + /// <param name="point">The point to check.</param> + /// <returns>A bool for whether or not the AABB contains `point`.</returns> public bool HasPoint(Vector3 point) { if (point.x < _position.x) @@ -261,6 +370,11 @@ namespace Godot return true; } + /// <summary> + /// Returns the intersection of this AABB and `b`. + /// </summary> + /// <param name="with">The other AABB.</param> + /// <returns>The clipped AABB.</returns> public AABB Intersection(AABB with) { Vector3 src_min = _position; @@ -297,24 +411,57 @@ namespace Godot return new AABB(min, max - min); } - public bool Intersects(AABB with) + /// <summary> + /// Returns true if the AABB overlaps with `b` + /// (i.e. they have at least one point in common). + /// + /// If `includeBorders` is true, they will also be considered overlapping + /// if their borders touch, even without intersection. + /// </summary> + /// <param name="with">The other AABB to check for intersections with.</param> + /// <param name="includeBorders">Whether or not to consider borders.</param> + /// <returns>A bool for whether or not they are intersecting.</returns> + public bool Intersects(AABB with, bool includeBorders = false) { - if (_position.x >= with._position.x + with._size.x) - return false; - if (_position.x + _size.x <= with._position.x) - return false; - if (_position.y >= with._position.y + with._size.y) - return false; - if (_position.y + _size.y <= with._position.y) - return false; - if (_position.z >= with._position.z + with._size.z) - return false; - if (_position.z + _size.z <= with._position.z) - return false; + if (includeBorders) + { + if (_position.x > with._position.x + with._size.x) + return false; + if (_position.x + _size.x < with._position.x) + return false; + if (_position.y > with._position.y + with._size.y) + return false; + if (_position.y + _size.y < with._position.y) + return false; + if (_position.z > with._position.z + with._size.z) + return false; + if (_position.z + _size.z < with._position.z) + return false; + } + else + { + if (_position.x >= with._position.x + with._size.x) + return false; + if (_position.x + _size.x <= with._position.x) + return false; + if (_position.y >= with._position.y + with._size.y) + return false; + if (_position.y + _size.y <= with._position.y) + return false; + if (_position.z >= with._position.z + with._size.z) + return false; + if (_position.z + _size.z <= with._position.z) + return false; + } return true; } + /// <summary> + /// Returns true if the AABB is on both sides of `plane`. + /// </summary> + /// <param name="plane">The plane to check for intersection.</param> + /// <returns>A bool for whether or not the AABB intersects the plane.</returns> public bool IntersectsPlane(Plane plane) { Vector3[] points = @@ -335,14 +482,24 @@ namespace Godot for (int i = 0; i < 8; i++) { if (plane.DistanceTo(points[i]) > 0) + { over = true; + } else + { under = true; + } } return under && over; } + /// <summary> + /// Returns true if the AABB intersects the line segment between `from` and `to`. + /// </summary> + /// <param name="from">The start of the line segment.</param> + /// <param name="to">The end of the line segment.</param> + /// <returns>A bool for whether or not the AABB intersects the line segment.</returns> public bool IntersectsSegment(Vector3 from, Vector3 to) { real_t min = 0f; @@ -359,7 +516,9 @@ namespace Godot if (segFrom < segTo) { if (segFrom > boxEnd || segTo < boxBegin) + { return false; + } real_t length = segTo - segFrom; cmin = segFrom < boxBegin ? (boxBegin - segFrom) / length : 0f; @@ -368,7 +527,9 @@ namespace Godot else { if (segTo > boxEnd || segFrom < boxBegin) + { return false; + } real_t length = segTo - segFrom; cmin = segFrom > boxEnd ? (boxEnd - segFrom) / length : 0f; @@ -381,14 +542,23 @@ namespace Godot } if (cmax < max) + { max = cmax; + } if (max < min) + { return false; + } } return true; } + /// <summary> + /// Returns a larger AABB that contains this AABB and `b`. + /// </summary> + /// <param name="with">The other AABB.</param> + /// <returns>The merged AABB.</returns> public AABB Merge(AABB with) { Vector3 beg1 = _position; @@ -411,22 +581,52 @@ namespace Godot return new AABB(min, max - min); } - // Constructors + /// <summary> + /// Constructs an AABB from a position and size. + /// </summary> + /// <param name="position">The position.</param> + /// <param name="size">The size, typically positive.</param> public AABB(Vector3 position, Vector3 size) { _position = position; _size = size; } + + /// <summary> + /// Constructs an AABB from a position, width, height, and depth. + /// </summary> + /// <param name="position">The position.</param> + /// <param name="width">The width, typically positive.</param> + /// <param name="height">The height, typically positive.</param> + /// <param name="depth">The depth, typically positive.</param> public AABB(Vector3 position, real_t width, real_t height, real_t depth) { _position = position; _size = new Vector3(width, height, depth); } + + /// <summary> + /// Constructs an AABB from x, y, z, and size. + /// </summary> + /// <param name="x">The position's X coordinate.</param> + /// <param name="y">The position's Y coordinate.</param> + /// <param name="z">The position's Z coordinate.</param> + /// <param name="size">The size, typically positive.</param> public AABB(real_t x, real_t y, real_t z, Vector3 size) { _position = new Vector3(x, y, z); _size = size; } + + /// <summary> + /// Constructs an AABB from x, y, z, width, height, and depth. + /// </summary> + /// <param name="x">The position's X coordinate.</param> + /// <param name="y">The position's Y coordinate.</param> + /// <param name="z">The position's Z coordinate.</param> + /// <param name="width">The width, typically positive.</param> + /// <param name="height">The height, typically positive.</param> + /// <param name="depth">The depth, typically positive.</param> public AABB(real_t x, real_t y, real_t z, real_t width, real_t height, real_t depth) { _position = new Vector3(x, y, z); @@ -458,6 +658,12 @@ namespace Godot return _position == other._position && _size == other._size; } + /// <summary> + /// Returns true if this AABB and `other` are approximately equal, by running + /// <see cref="Vector3.IsEqualApprox(Vector3)"/> on each component. + /// </summary> + /// <param name="other">The other AABB to compare.</param> + /// <returns>Whether or not the AABBs are approximately equal.</returns> public bool IsEqualApprox(AABB other) { return _position.IsEqualApprox(other._position) && _size.IsEqualApprox(other._size); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs index baf470a0cc..16c666b8eb 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs @@ -8,6 +8,20 @@ using real_t = System.Single; namespace Godot { + /// <summary> + /// 3×3 matrix used for 3D rotation and scale. + /// Almost always used as an orthogonal basis for a Transform. + /// + /// Contains 3 vector fields X, Y and Z as its columns, which are typically + /// interpreted as the local basis vectors of a 3D transformation. For such use, + /// it is composed of a scaling and a rotation matrix, in that order (M = R.S). + /// + /// Can also be accessed as array of 3D vectors. These vectors are normally + /// orthogonal to each other, but are not necessarily normalized (due to scaling). + /// + /// For more information, read this documentation article: + /// https://docs.godotengine.org/en/latest/tutorials/math/matrices_and_transforms.html + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Basis : IEquatable<Basis> @@ -15,9 +29,9 @@ namespace Godot // NOTE: x, y and z are public-only. Use Column0, Column1 and Column2 internally. /// <summary> - /// Returns the basis matrix’s x vector. - /// This is equivalent to <see cref="Column0"/>. + /// The basis matrix's X vector (column 0). /// </summary> + /// <value>Equivalent to <see cref="Column0"/> and array index `[0]`.</value> public Vector3 x { get => Column0; @@ -25,9 +39,9 @@ namespace Godot } /// <summary> - /// Returns the basis matrix’s y vector. - /// This is equivalent to <see cref="Column1"/>. + /// The basis matrix's Y vector (column 1). /// </summary> + /// <value>Equivalent to <see cref="Column1"/> and array index `[1]`.</value> public Vector3 y { get => Column1; @@ -35,19 +49,40 @@ namespace Godot } /// <summary> - /// Returns the basis matrix’s z vector. - /// This is equivalent to <see cref="Column2"/>. + /// The basis matrix's Z vector (column 2). /// </summary> + /// <value>Equivalent to <see cref="Column2"/> and array index `[2]`.</value> public Vector3 z { get => Column2; set => Column2 = value; } + /// <summary> + /// Row 0 of the basis matrix. Shows which vectors contribute + /// to the X direction. Rows are not very useful for user code, + /// but are more efficient for some internal calculations. + /// </summary> public Vector3 Row0; + + /// <summary> + /// Row 1 of the basis matrix. Shows which vectors contribute + /// to the Y direction. Rows are not very useful for user code, + /// but are more efficient for some internal calculations. + /// </summary> public Vector3 Row1; + + /// <summary> + /// Row 2 of the basis matrix. Shows which vectors contribute + /// to the Z direction. Rows are not very useful for user code, + /// but are more efficient for some internal calculations. + /// </summary> public Vector3 Row2; + /// <summary> + /// Column 0 of the basis matrix (the X vector). + /// </summary> + /// <value>Equivalent to <see cref="x"/> and array index `[0]`.</value> public Vector3 Column0 { get => new Vector3(Row0.x, Row1.x, Row2.x); @@ -58,6 +93,11 @@ namespace Godot this.Row2.x = value.z; } } + + /// <summary> + /// Column 1 of the basis matrix (the Y vector). + /// </summary> + /// <value>Equivalent to <see cref="y"/> and array index `[1]`.</value> public Vector3 Column1 { get => new Vector3(Row0.y, Row1.y, Row2.y); @@ -68,6 +108,11 @@ namespace Godot this.Row2.y = value.z; } } + + /// <summary> + /// Column 2 of the basis matrix (the Z vector). + /// </summary> + /// <value>Equivalent to <see cref="z"/> and array index `[2]`.</value> public Vector3 Column2 { get => new Vector3(Row0.z, Row1.z, Row2.z); @@ -79,6 +124,10 @@ namespace Godot } } + /// <summary> + /// The scale of this basis. + /// </summary> + /// <value>Equivalent to the lengths of each column vector, but negative if the determinant is negative.</value> public Vector3 Scale { get @@ -86,11 +135,18 @@ namespace Godot real_t detSign = Mathf.Sign(Determinant()); return detSign * new Vector3 ( - new Vector3(this.Row0[0], this.Row1[0], this.Row2[0]).Length(), - new Vector3(this.Row0[1], this.Row1[1], this.Row2[1]).Length(), - new Vector3(this.Row0[2], this.Row1[2], this.Row2[2]).Length() + Column0.Length(), + Column1.Length(), + Column2.Length() ); } + set + { + value /= Scale; // Value becomes what's called "delta_scale" in core. + Column0 *= value.x; + Column1 *= value.y; + Column2 *= value.z; + } } /// <summary> @@ -157,8 +213,9 @@ namespace Godot real_t det = orthonormalizedBasis.Determinant(); if (det < 0) { - // Ensure that the determinant is 1, such that result is a proper rotation matrix which can be represented by Euler angles. - orthonormalizedBasis = orthonormalizedBasis.Scaled(Vector3.NegOne); + // Ensure that the determinant is 1, such that result is a proper + // rotation matrix which can be represented by Euler angles. + orthonormalizedBasis = orthonormalizedBasis.Scaled(-Vector3.One); } return orthonormalizedBasis.Quat(); @@ -182,6 +239,15 @@ namespace Godot Row2 = new Vector3(0, 0, diagonal.z); } + /// <summary> + /// Returns the determinant of the basis matrix. If the basis is + /// uniformly scaled, its determinant is the square of the scale. + /// + /// A negative determinant means the basis has a negative scale. + /// A zero determinant means the basis isn't invertible, + /// and is usually considered invalid. + /// </summary> + /// <returns>The determinant of the basis matrix.</returns> public real_t Determinant() { real_t cofac00 = Row1[1] * Row2[2] - Row1[2] * Row2[1]; @@ -191,6 +257,16 @@ namespace Godot return Row0[0] * cofac00 + Row0[1] * cofac10 + Row0[2] * cofac20; } + /// <summary> + /// Returns the basis's rotation in the form of Euler angles + /// (in the YXZ convention: when *decomposing*, first Z, then X, and Y last). + /// The returned vector contains the rotation angles in + /// the format (X angle, Y angle, Z angle). + /// + /// Consider using the <see cref="Basis.Quat()"/> method instead, which + /// returns a <see cref="Godot.Quat"/> quaternion instead of Euler angles. + /// </summary> + /// <returns>A Vector3 representing the basis rotation in Euler angles.</returns> public Vector3 GetEuler() { Basis m = Orthonormalized(); @@ -223,6 +299,12 @@ namespace Godot return euler; } + /// <summary> + /// Get rows by index. Rows are not very useful for user code, + /// but are more efficient for some internal calculations. + /// </summary> + /// <param name="index">Which row.</param> + /// <returns>One of `Row0`, `Row1`, or `Row2`.</returns> public Vector3 GetRow(int index) { switch (index) @@ -238,6 +320,12 @@ namespace Godot } } + /// <summary> + /// Sets rows by index. Rows are not very useful for user code, + /// but are more efficient for some internal calculations. + /// </summary> + /// <param name="index">Which row.</param> + /// <param name="value">The vector to set the row to.</param> public void SetRow(int index, Vector3 value) { switch (index) @@ -256,16 +344,16 @@ namespace Godot } } - public Vector3 GetColumn(int index) - { - return this[index]; - } - - public void SetColumn(int index, Vector3 value) - { - this[index] = value; - } - + /// <summary> + /// This function considers a discretization of rotations into + /// 24 points on unit sphere, lying along the vectors (x, y, z) with + /// each component being either -1, 0, or 1, and returns the index + /// of the point best representing the orientation of the object. + /// It is mainly used by the <see cref="GridMap"/> editor. + /// + /// For further details, refer to the Godot source code. + /// </summary> + /// <returns>The orthogonal index.</returns> public int GetOrthogonalIndex() { var orth = this; @@ -279,11 +367,17 @@ namespace Godot real_t v = row[j]; if (v > 0.5f) + { v = 1.0f; + } else if (v < -0.5f) + { v = -1.0f; + } else + { v = 0f; + } row[j] = v; @@ -294,12 +388,18 @@ namespace Godot for (int i = 0; i < 24; i++) { if (orth == _orthoBases[i]) + { return i; + } } return 0; } + /// <summary> + /// Returns the inverse of the matrix. + /// </summary> + /// <returns>The inverse matrix.</returns> public Basis Inverse() { real_t cofac00 = Row1[1] * Row2[2] - Row1[2] * Row2[1]; @@ -309,7 +409,9 @@ namespace Godot real_t det = Row0[0] * cofac00 + Row0[1] * cofac10 + Row0[2] * cofac20; if (det == 0) + { throw new InvalidOperationException("Matrix determinant is zero and cannot be inverted."); + } real_t detInv = 1.0f / det; @@ -328,11 +430,17 @@ namespace Godot ); } + /// <summary> + /// Returns the orthonormalized version of the basis matrix (useful to + /// call occasionally to avoid rounding errors for orthogonal matrices). + /// This performs a Gram-Schmidt orthonormalization on the basis of the matrix. + /// </summary> + /// <returns>An orthonormalized basis matrix.</returns> public Basis Orthonormalized() { - Vector3 column0 = GetColumn(0); - Vector3 column1 = GetColumn(1); - Vector3 column2 = GetColumn(2); + Vector3 column0 = this[0]; + Vector3 column1 = this[1]; + Vector3 column2 = this[2]; column0.Normalize(); column1 = column1 - column0 * column0.Dot(column1); @@ -343,48 +451,86 @@ namespace Godot return new Basis(column0, column1, column2); } + /// <summary> + /// Introduce an additional rotation around the given `axis` + /// by `phi` (in radians). The axis must be a normalized vector. + /// </summary> + /// <param name="axis">The axis to rotate around. Must be normalized.</param> + /// <param name="phi">The angle to rotate, in radians.</param> + /// <returns>The rotated basis matrix.</returns> public Basis Rotated(Vector3 axis, real_t phi) { return new Basis(axis, phi) * this; } + /// <summary> + /// Introduce an additional scaling specified by the given 3D scaling factor. + /// </summary> + /// <param name="scale">The scale to introduce.</param> + /// <returns>The scaled basis matrix.</returns> public Basis Scaled(Vector3 scale) { - var b = this; + Basis b = this; b.Row0 *= scale.x; b.Row1 *= scale.y; b.Row2 *= scale.z; return b; } - public Basis Slerp(Basis target, real_t t) + /// <summary> + /// Assuming that the matrix is a proper rotation matrix, slerp performs + /// a spherical-linear interpolation with another rotation matrix. + /// </summary> + /// <param name="target">The destination basis for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting basis matrix of the interpolation.</returns> + public Basis Slerp(Basis target, real_t weight) { - var from = new Quat(this); - var to = new Quat(target); + Quat from = new Quat(this); + Quat to = new Quat(target); - var b = new Basis(from.Slerp(to, t)); - b.Row0 *= Mathf.Lerp(Row0.Length(), target.Row0.Length(), t); - b.Row1 *= Mathf.Lerp(Row1.Length(), target.Row1.Length(), t); - b.Row2 *= Mathf.Lerp(Row2.Length(), target.Row2.Length(), t); + Basis b = new Basis(from.Slerp(to, weight)); + b.Row0 *= Mathf.Lerp(Row0.Length(), target.Row0.Length(), weight); + b.Row1 *= Mathf.Lerp(Row1.Length(), target.Row1.Length(), weight); + b.Row2 *= Mathf.Lerp(Row2.Length(), target.Row2.Length(), weight); return b; } + /// <summary> + /// Transposed dot product with the X axis of the matrix. + /// </summary> + /// <param name="with">A vector to calculate the dot product with.</param> + /// <returns>The resulting dot product.</returns> public real_t Tdotx(Vector3 with) { return this.Row0[0] * with[0] + this.Row1[0] * with[1] + this.Row2[0] * with[2]; } + /// <summary> + /// Transposed dot product with the Y axis of the matrix. + /// </summary> + /// <param name="with">A vector to calculate the dot product with.</param> + /// <returns>The resulting dot product.</returns> public real_t Tdoty(Vector3 with) { return this.Row0[1] * with[0] + this.Row1[1] * with[1] + this.Row2[1] * with[2]; } + /// <summary> + /// Transposed dot product with the Z axis of the matrix. + /// </summary> + /// <param name="with">A vector to calculate the dot product with.</param> + /// <returns>The resulting dot product.</returns> public real_t Tdotz(Vector3 with) { return this.Row0[2] * with[0] + this.Row1[2] * with[1] + this.Row2[2] * with[2]; } + /// <summary> + /// Returns the transposed version of the basis matrix. + /// </summary> + /// <returns>The transposed basis matrix.</returns> public Basis Transposed() { var tr = this; @@ -404,6 +550,11 @@ namespace Godot return tr; } + /// <summary> + /// Returns a vector transformed (multiplied) by the basis matrix. + /// </summary> + /// <param name="v">A vector to transform.</param> + /// <returns>The transfomed vector.</returns> public Vector3 Xform(Vector3 v) { return new Vector3 @@ -414,6 +565,14 @@ namespace Godot ); } + /// <summary> + /// Returns a vector transformed (multiplied) by the transposed basis matrix. + /// + /// Note: This results in a multiplication by the inverse of the + /// basis matrix only if it represents a rotation-reflection. + /// </summary> + /// <param name="v">A vector to inversely transform.</param> + /// <returns>The inversely transfomed vector.</returns> public Vector3 XformInv(Vector3 v) { return new Vector3 @@ -424,6 +583,12 @@ namespace Godot ); } + /// <summary> + /// Returns the basis's rotation in the form of a quaternion. + /// See <see cref="GetEuler()"/> if you need Euler angles, but keep in + /// mind that quaternions should generally be preferred to Euler angles. + /// </summary> + /// <returns>A <see cref="Godot.Quat"/> representing the basis's rotation.</returns> public Quat Quat() { real_t trace = Row0[0] + Row1[1] + Row2[2]; @@ -508,11 +673,33 @@ namespace Godot private static readonly Basis _flipY = new Basis(1, 0, 0, 0, -1, 0, 0, 0, 1); private static readonly Basis _flipZ = new Basis(1, 0, 0, 0, 1, 0, 0, 0, -1); + /// <summary> + /// The identity basis, with no rotation or scaling applied. + /// This is used as a replacement for `Basis()` in GDScript. + /// Do not use `new Basis()` with no arguments in C#, because it sets all values to zero. + /// </summary> + /// <value>Equivalent to `new Basis(Vector3.Right, Vector3.Up, Vector3.Back)`.</value> public static Basis Identity { get { return _identity; } } + /// <summary> + /// The basis that will flip something along the X axis when used in a transformation. + /// </summary> + /// <value>Equivalent to `new Basis(Vector3.Left, Vector3.Up, Vector3.Back)`.</value> public static Basis FlipX { get { return _flipX; } } + /// <summary> + /// The basis that will flip something along the Y axis when used in a transformation. + /// </summary> + /// <value>Equivalent to `new Basis(Vector3.Right, Vector3.Down, Vector3.Back)`.</value> public static Basis FlipY { get { return _flipY; } } + /// <summary> + /// The basis that will flip something along the Z axis when used in a transformation. + /// </summary> + /// <value>Equivalent to `new Basis(Vector3.Right, Vector3.Up, Vector3.Forward)`.</value> public static Basis FlipZ { get { return _flipZ; } } + /// <summary> + /// Constructs a pure rotation basis matrix from the given quaternion. + /// </summary> + /// <param name="quat">The quaternion to create the basis from.</param> public Basis(Quat quat) { real_t s = 2.0f / quat.LengthSquared; @@ -535,26 +722,41 @@ namespace Godot Row2 = new Vector3(xz - wy, yz + wx, 1.0f - (xx + yy)); } - public Basis(Vector3 euler) + /// <summary> + /// Constructs a pure rotation basis matrix from the given Euler angles + /// (in the YXZ convention: when *composing*, first Y, then X, and Z last), + /// given in the vector format as (X angle, Y angle, Z angle). + /// + /// Consider using the <see cref="Basis(Quat)"/> constructor instead, which + /// uses a <see cref="Godot.Quat"/> quaternion instead of Euler angles. + /// </summary> + /// <param name="eulerYXZ">The Euler angles to create the basis from.</param> + public Basis(Vector3 eulerYXZ) { real_t c; real_t s; - c = Mathf.Cos(euler.x); - s = Mathf.Sin(euler.x); + c = Mathf.Cos(eulerYXZ.x); + s = Mathf.Sin(eulerYXZ.x); var xmat = new Basis(1, 0, 0, 0, c, -s, 0, s, c); - c = Mathf.Cos(euler.y); - s = Mathf.Sin(euler.y); + c = Mathf.Cos(eulerYXZ.y); + s = Mathf.Sin(eulerYXZ.y); var ymat = new Basis(c, 0, s, 0, 1, 0, -s, 0, c); - c = Mathf.Cos(euler.z); - s = Mathf.Sin(euler.z); + c = Mathf.Cos(eulerYXZ.z); + s = Mathf.Sin(eulerYXZ.z); var zmat = new Basis(c, -s, 0, s, c, 0, 0, 0, 1); this = ymat * xmat * zmat; } + /// <summary> + /// Constructs a pure rotation basis matrix, rotated around the given `axis` + /// by `phi` (in radians). The axis must be a normalized vector. + /// </summary> + /// <param name="axis">The axis to rotate around. Must be normalized.</param> + /// <param name="phi">The angle to rotate, in radians.</param> public Basis(Vector3 axis, real_t phi) { Vector3 axisSq = new Vector3(axis.x * axis.x, axis.y * axis.y, axis.z * axis.z); @@ -582,6 +784,12 @@ namespace Godot Row2.y = xyzt + zyxs; } + /// <summary> + /// Constructs a basis matrix from 3 axis vectors (matrix columns). + /// </summary> + /// <param name="column0">The X vector, or Column0.</param> + /// <param name="column1">The Y vector, or Column1.</param> + /// <param name="column2">The Z vector, or Column2.</param> public Basis(Vector3 column0, Vector3 column1, Vector3 column2) { Row0 = new Vector3(column0.x, column1.x, column2.x); @@ -637,6 +845,12 @@ namespace Godot return Row0.Equals(other.Row0) && Row1.Equals(other.Row1) && Row2.Equals(other.Row2); } + /// <summary> + /// Returns true if this basis and `other` are approximately equal, by running + /// <see cref="Vector3.IsEqualApprox(Vector3)"/> on each component. + /// </summary> + /// <param name="other">The other basis to compare.</param> + /// <returns>Whether or not the matrices are approximately equal.</returns> public bool IsEqualApprox(Basis other) { return Row0.IsEqualApprox(other.Row0) && Row1.IsEqualApprox(other.Row1) && Row2.IsEqualApprox(other.Row2); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs index 6030b72a44..d851abc6d3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Color.cs @@ -3,15 +3,44 @@ using System.Runtime.InteropServices; namespace Godot { + /// <summary> + /// A color represented by red, green, blue, and alpha (RGBA) components. + /// The alpha component is often used for transparency. + /// Values are in floating-point and usually range from 0 to 1. + /// Some properties (such as CanvasItem.modulate) may accept values + /// greater than 1 (overbright or HDR colors). + /// + /// If you want to supply values in a range of 0 to 255, you should use + /// <see cref="Color8"/> and the `r8`/`g8`/`b8`/`a8` properties. + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Color : IEquatable<Color> { + /// <summary> + /// The color's red component, typically on the range of 0 to 1. + /// </summary> public float r; + + /// <summary> + /// The color's green component, typically on the range of 0 to 1. + /// </summary> public float g; + + /// <summary> + /// The color's blue component, typically on the range of 0 to 1. + /// </summary> public float b; + + /// <summary> + /// The color's alpha (transparency) component, typically on the range of 0 to 1. + /// </summary> public float a; + /// <summary> + /// Wrapper for <see cref="r"/> that uses the range 0 to 255 instead of 0 to 1. + /// </summary> + /// <value>Getting is equivalent to multiplying by 255 and rounding. Setting is equivalent to dividing by 255.</value> public int r8 { get @@ -24,6 +53,10 @@ namespace Godot } } + /// <summary> + /// Wrapper for <see cref="g"/> that uses the range 0 to 255 instead of 0 to 1. + /// </summary> + /// <value>Getting is equivalent to multiplying by 255 and rounding. Setting is equivalent to dividing by 255.</value> public int g8 { get @@ -36,6 +69,10 @@ namespace Godot } } + /// <summary> + /// Wrapper for <see cref="b"/> that uses the range 0 to 255 instead of 0 to 1. + /// </summary> + /// <value>Getting is equivalent to multiplying by 255 and rounding. Setting is equivalent to dividing by 255.</value> public int b8 { get @@ -48,6 +85,10 @@ namespace Godot } } + /// <summary> + /// Wrapper for <see cref="a"/> that uses the range 0 to 255 instead of 0 to 1. + /// </summary> + /// <value>Getting is equivalent to multiplying by 255 and rounding. Setting is equivalent to dividing by 255.</value> public int a8 { get @@ -60,6 +101,10 @@ namespace Godot } } + /// <summary> + /// The HSV hue of this color, on the range 0 to 1. + /// </summary> + /// <value>Getting is a long process, refer to the source code for details. Setting uses <see cref="FromHsv"/>.</value> public float h { get @@ -70,21 +115,31 @@ namespace Godot float delta = max - min; if (delta == 0) + { return 0; + } float h; if (r == max) + { h = (g - b) / delta; // Between yellow & magenta + } else if (g == max) + { h = 2 + (b - r) / delta; // Between cyan & yellow + } else + { h = 4 + (r - g) / delta; // Between magenta & cyan + } h /= 6.0f; if (h < 0) + { h += 1.0f; + } return h; } @@ -94,6 +149,10 @@ namespace Godot } } + /// <summary> + /// The HSV saturation of this color, on the range 0 to 1. + /// </summary> + /// <value>Getting is equivalent to the ratio between the min and max RGB value. Setting uses <see cref="FromHsv"/>.</value> public float s { get @@ -103,7 +162,7 @@ namespace Godot float delta = max - min; - return max != 0 ? delta / max : 0; + return max == 0 ? 0 : delta / max; } set { @@ -111,6 +170,10 @@ namespace Godot } } + /// <summary> + /// The HSV value (brightness) of this color, on the range 0 to 1. + /// </summary> + /// <value>Getting is equivalent to using `Max()` on the RGB components. Setting uses <see cref="FromHsv"/>.</value> public float v { get @@ -123,25 +186,10 @@ namespace Godot } } - public static Color ColorN(string name, float alpha = 1f) - { - name = name.Replace(" ", String.Empty); - name = name.Replace("-", String.Empty); - name = name.Replace("_", String.Empty); - name = name.Replace("'", String.Empty); - name = name.Replace(".", String.Empty); - name = name.ToLower(); - - if (!Colors.namedColors.ContainsKey(name)) - { - throw new ArgumentOutOfRangeException($"Invalid Color Name: {name}"); - } - - Color color = Colors.namedColors[name]; - color.a = alpha; - return color; - } - + /// <summary> + /// Access color components using their index. + /// </summary> + /// <value>`[0]` is equivalent to `.r`, `[1]` is equivalent to `.g`, `[2]` is equivalent to `.b`, `[3]` is equivalent to `.a`.</value> public float this[int index] { get @@ -182,73 +230,13 @@ namespace Godot } } - public void ToHsv(out float hue, out float saturation, out float value) - { - float max = (float)Mathf.Max(r, Mathf.Max(g, b)); - float min = (float)Mathf.Min(r, Mathf.Min(g, b)); - - float delta = max - min; - - if (delta == 0) - { - hue = 0; - } - else - { - if (r == max) - hue = (g - b) / delta; // Between yellow & magenta - else if (g == max) - hue = 2 + (b - r) / delta; // Between cyan & yellow - else - hue = 4 + (r - g) / delta; // Between magenta & cyan - - hue /= 6.0f; - - if (hue < 0) - hue += 1.0f; - } - - saturation = max == 0 ? 0 : 1f - 1f * min / max; - value = max; - } - - public static Color FromHsv(float hue, float saturation, float value, float alpha = 1.0f) - { - if (saturation == 0) - { - // acp_hromatic (grey) - return new Color(value, value, value, alpha); - } - - int i; - float f, p, q, t; - - hue *= 6.0f; - hue %= 6f; - i = (int)hue; - - f = hue - i; - p = value * (1 - saturation); - q = value * (1 - saturation * f); - t = value * (1 - saturation * (1 - f)); - - switch (i) - { - case 0: // Red is the dominant color - return new Color(value, t, p, alpha); - case 1: // Green is the dominant color - return new Color(q, value, p, alpha); - case 2: - return new Color(p, value, t, alpha); - case 3: // Blue is the dominant color - return new Color(p, q, value, alpha); - case 4: - return new Color(t, p, value, alpha); - default: // (5) Red is the dominant color - return new Color(value, p, q, alpha); - } - } - + /// <summary> + /// Returns a new color resulting from blending this color over another. + /// If the color is opaque, the result is also opaque. + /// The second color may have a range of alpha values. + /// </summary> + /// <param name="over">The color to blend over.</param> + /// <returns>This color blended over `over`.</returns> public Color Blend(Color over) { Color res; @@ -268,6 +256,10 @@ namespace Godot return res; } + /// <summary> + /// Returns the most contrasting color. + /// </summary> + /// <returns>The most contrasting color</returns> public Color Contrasted() { return new Color( @@ -278,6 +270,12 @@ namespace Godot ); } + /// <summary> + /// Returns a new color resulting from making this color darker + /// by the specified ratio (on the range of 0 to 1). + /// </summary> + /// <param name="amount">The ratio to darken by.</param> + /// <returns>The darkened color.</returns> public Color Darkened(float amount) { Color res = this; @@ -287,6 +285,10 @@ namespace Godot return res; } + /// <summary> + /// Returns the inverted color: `(1 - r, 1 - g, 1 - b, a)`. + /// </summary> + /// <returns>The inverted color.</returns> public Color Inverted() { return new Color( @@ -297,6 +299,12 @@ namespace Godot ); } + /// <summary> + /// Returns a new color resulting from making this color lighter + /// by the specified ratio (on the range of 0 to 1). + /// </summary> + /// <param name="amount">The ratio to lighten by.</param> + /// <returns>The darkened color.</returns> public Color Lightened(float amount) { Color res = this; @@ -306,6 +314,13 @@ namespace Godot return res; } + /// <summary> + /// Returns the result of the linear interpolation between + /// this color and `to` by amount `weight`. + /// </summary> + /// <param name="to">The destination color for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting color of the interpolation.</returns> public Color Lerp(Color to, float weight) { return new Color @@ -317,6 +332,13 @@ namespace Godot ); } + /// <summary> + /// Returns the result of the linear interpolation between + /// this color and `to` by color amount `weight`. + /// </summary> + /// <param name="to">The destination color for interpolation.</param> + /// <param name="weight">A color with components on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting color of the interpolation.</returns> public Color Lerp(Color to, Color weight) { return new Color @@ -328,6 +350,12 @@ namespace Godot ); } + /// <summary> + /// Returns the color's 32-bit integer in ABGR format + /// (each byte represents a component of the ABGR profile). + /// ABGR is the reversed version of the default format. + /// </summary> + /// <returns>A uint representing this color in ABGR32 format.</returns> public uint ToAbgr32() { uint c = (byte)Math.Round(a * 255); @@ -341,6 +369,12 @@ namespace Godot return c; } + /// <summary> + /// Returns the color's 64-bit integer in ABGR format + /// (each word represents a component of the ABGR profile). + /// ABGR is the reversed version of the default format. + /// </summary> + /// <returns>A ulong representing this color in ABGR64 format.</returns> public ulong ToAbgr64() { ulong c = (ushort)Math.Round(a * 65535); @@ -354,6 +388,12 @@ namespace Godot return c; } + /// <summary> + /// Returns the color's 32-bit integer in ARGB format + /// (each byte represents a component of the ARGB profile). + /// ARGB is more compatible with DirectX, but not used much in Godot. + /// </summary> + /// <returns>A uint representing this color in ARGB32 format.</returns> public uint ToArgb32() { uint c = (byte)Math.Round(a * 255); @@ -367,6 +407,12 @@ namespace Godot return c; } + /// <summary> + /// Returns the color's 64-bit integer in ARGB format + /// (each word represents a component of the ARGB profile). + /// ARGB is more compatible with DirectX, but not used much in Godot. + /// </summary> + /// <returns>A ulong representing this color in ARGB64 format.</returns> public ulong ToArgb64() { ulong c = (ushort)Math.Round(a * 65535); @@ -380,6 +426,12 @@ namespace Godot return c; } + /// <summary> + /// Returns the color's 32-bit integer in RGBA format + /// (each byte represents a component of the RGBA profile). + /// RGBA is Godot's default and recommended format. + /// </summary> + /// <returns>A uint representing this color in RGBA32 format.</returns> public uint ToRgba32() { uint c = (byte)Math.Round(r * 255); @@ -393,6 +445,12 @@ namespace Godot return c; } + /// <summary> + /// Returns the color's 64-bit integer in RGBA format + /// (each word represents a component of the RGBA profile). + /// RGBA is Godot's default and recommended format. + /// </summary> + /// <returns>A ulong representing this color in RGBA64 format.</returns> public ulong ToRgba64() { ulong c = (ushort)Math.Round(r * 65535); @@ -406,6 +464,11 @@ namespace Godot return c; } + /// <summary> + /// Returns the color's HTML hexadecimal color string in RGBA format. + /// </summary> + /// <param name="includeAlpha">Whether or not to include alpha. If false, the color is RGB instead of RGBA.</param> + /// <returns>A string for the HTML hexadecimal representation of this color.</returns> public string ToHtml(bool includeAlpha = true) { var txt = string.Empty; @@ -415,12 +478,20 @@ namespace Godot txt += ToHex32(b); if (includeAlpha) - txt = ToHex32(a) + txt; + { + txt += ToHex32(a); + } return txt; } - // Constructors + /// <summary> + /// Constructs a color from RGBA values on the range of 0 to 1. + /// </summary> + /// <param name="r">The color's red component, typically on the range of 0 to 1.</param> + /// <param name="g">The color's green component, typically on the range of 0 to 1.</param> + /// <param name="b">The color's blue component, typically on the range of 0 to 1.</param> + /// <param name="a">The color's alpha (transparency) value, typically on the range of 0 to 1. Default: 1.</param> public Color(float r, float g, float b, float a = 1.0f) { this.r = r; @@ -429,6 +500,11 @@ namespace Godot this.a = a; } + /// <summary> + /// Constructs a color from an existing color and an alpha value. + /// </summary> + /// <param name="c">The color to construct from. Only its RGB values are used.</param> + /// <param name="a">The color's alpha (transparency) value, typically on the range of 0 to 1. Default: 1.</param> public Color(Color c, float a = 1.0f) { r = c.r; @@ -437,6 +513,11 @@ namespace Godot this.a = a; } + /// <summary> + /// Constructs a color from a 32-bit integer + /// (each byte represents a component of the RGBA profile). + /// </summary> + /// <param name="rgba">The uint representing the color.</param> public Color(uint rgba) { a = (rgba & 0xFF) / 255.0f; @@ -448,6 +529,11 @@ namespace Godot r = (rgba & 0xFF) / 255.0f; } + /// <summary> + /// Constructs a color from a 64-bit integer + /// (each word represents a component of the RGBA profile). + /// </summary> + /// <param name="rgba">The ulong representing the color.</param> public Color(ulong rgba) { a = (rgba & 0xFFFF) / 65535.0f; @@ -459,6 +545,212 @@ namespace Godot r = (rgba & 0xFFFF) / 65535.0f; } + /// <summary> + /// Constructs a color from the HTML hexadecimal color string in RGBA format. + /// </summary> + /// <param name="rgba">A string for the HTML hexadecimal representation of this color.</param> + public Color(string rgba) + { + if (rgba.Length == 0) + { + r = 0f; + g = 0f; + b = 0f; + a = 1.0f; + return; + } + + if (rgba[0] == '#') + { + rgba = rgba.Substring(1); + } + + bool alpha; + + if (rgba.Length == 8) + { + alpha = true; + } + else if (rgba.Length == 6) + { + alpha = false; + } + else + { + throw new ArgumentOutOfRangeException("Invalid color code. Length is " + rgba.Length + " but a length of 6 or 8 is expected: " + rgba); + } + + if (alpha) + { + a = ParseCol8(rgba, 6) / 255f; + + if (a < 0) + { + throw new ArgumentOutOfRangeException("Invalid color code. Alpha part is not valid hexadecimal: " + rgba); + } + } + else + { + a = 1.0f; + } + + int from = alpha ? 2 : 0; + + r = ParseCol8(rgba, 0) / 255f; + + if (r < 0) + { + throw new ArgumentOutOfRangeException("Invalid color code. Red part is not valid hexadecimal: " + rgba); + } + + g = ParseCol8(rgba, 2) / 255f; + + if (g < 0) + { + throw new ArgumentOutOfRangeException("Invalid color code. Green part is not valid hexadecimal: " + rgba); + } + + b = ParseCol8(rgba, 4) / 255f; + + if (b < 0) + { + throw new ArgumentOutOfRangeException("Invalid color code. Blue part is not valid hexadecimal: " + rgba); + } + } + + /// <summary> + /// Returns a color constructed from integer red, green, blue, and alpha channels. + /// Each channel should have 8 bits of information ranging from 0 to 255. + /// </summary> + /// <param name="r8">The red component represented on the range of 0 to 255.</param> + /// <param name="g8">The green component represented on the range of 0 to 255.</param> + /// <param name="b8">The blue component represented on the range of 0 to 255.</param> + /// <param name="a8">The alpha (transparency) component represented on the range of 0 to 255.</param> + /// <returns>The constructed color.</returns> + public static Color Color8(byte r8, byte g8, byte b8, byte a8 = 255) + { + return new Color(r8 / 255f, g8 / 255f, b8 / 255f, a8 / 255f); + } + + /// <summary> + /// Returns a color according to the standardized name, with the + /// specified alpha value. Supported color names are the same as + /// the constants defined in <see cref="Colors"/>. + /// </summary> + /// <param name="name">The name of the color.</param> + /// <param name="alpha">The alpha (transparency) component represented on the range of 0 to 1. Default: 1.</param> + /// <returns>The constructed color.</returns> + public static Color ColorN(string name, float alpha = 1f) + { + name = name.Replace(" ", String.Empty); + name = name.Replace("-", String.Empty); + name = name.Replace("_", String.Empty); + name = name.Replace("'", String.Empty); + name = name.Replace(".", String.Empty); + name = name.ToLower(); + + if (!Colors.namedColors.ContainsKey(name)) + { + throw new ArgumentOutOfRangeException($"Invalid Color Name: {name}"); + } + + Color color = Colors.namedColors[name]; + color.a = alpha; + return color; + } + + /// <summary> + /// Constructs a color from an HSV profile, with values on the + /// range of 0 to 1. This is equivalent to using each of + /// the `h`/`s`/`v` properties, but much more efficient. + /// </summary> + /// <param name="hue">The HSV hue, typically on the range of 0 to 1.</param> + /// <param name="saturation">The HSV saturation, typically on the range of 0 to 1.</param> + /// <param name="value">The HSV value (brightness), typically on the range of 0 to 1.</param> + /// <param name="alpha">The alpha (transparency) value, typically on the range of 0 to 1.</param> + /// <returns>The constructed color.</returns> + public static Color FromHsv(float hue, float saturation, float value, float alpha = 1.0f) + { + if (saturation == 0) + { + // acp_hromatic (grey) + return new Color(value, value, value, alpha); + } + + int i; + float f, p, q, t; + + hue *= 6.0f; + hue %= 6f; + i = (int)hue; + + f = hue - i; + p = value * (1 - saturation); + q = value * (1 - saturation * f); + t = value * (1 - saturation * (1 - f)); + + switch (i) + { + case 0: // Red is the dominant color + return new Color(value, t, p, alpha); + case 1: // Green is the dominant color + return new Color(q, value, p, alpha); + case 2: + return new Color(p, value, t, alpha); + case 3: // Blue is the dominant color + return new Color(p, q, value, alpha); + case 4: + return new Color(t, p, value, alpha); + default: // (5) Red is the dominant color + return new Color(value, p, q, alpha); + } + } + + /// <summary> + /// Converts a color to HSV values. This is equivalent to using each of + /// the `h`/`s`/`v` properties, but much more efficient. + /// </summary> + /// <param name="hue">Output parameter for the HSV hue.</param> + /// <param name="saturation">Output parameter for the HSV saturation.</param> + /// <param name="value">Output parameter for the HSV value.</param> + public void ToHsv(out float hue, out float saturation, out float value) + { + float max = (float)Mathf.Max(r, Mathf.Max(g, b)); + float min = (float)Mathf.Min(r, Mathf.Min(g, b)); + + float delta = max - min; + + if (delta == 0) + { + hue = 0; + } + else + { + if (r == max) + { + hue = (g - b) / delta; // Between yellow & magenta + } + else if (g == max) + { + hue = 2 + (b - r) / delta; // Between cyan & yellow + } + else + { + hue = 4 + (r - g) / delta; // Between magenta & cyan + } + + hue /= 6.0f; + + if (hue < 0) + { + hue += 1.0f; + } + } + + saturation = max == 0 ? 0 : 1f - 1f * min / max; + value = max; + } + private static int ParseCol8(string str, int ofs) { int ig = 0; @@ -488,9 +780,13 @@ namespace Godot } if (i == 0) + { ig += v * 16; + } else + { ig += v; + } } return ig; @@ -508,9 +804,13 @@ namespace Godot int lv = v & 0xF; if (lv < 10) + { c = (char)('0' + lv); + } else + { c = (char)('a' + lv - 10); + } v >>= 4; ret = c + ret; @@ -522,10 +822,14 @@ namespace Godot internal static bool HtmlIsValid(string color) { if (color.Length == 0) + { return false; + } if (color[0] == '#') + { color = color.Substring(1, color.Length - 1); + } bool alpha; @@ -544,83 +848,27 @@ namespace Godot if (alpha) { if (ParseCol8(color, 0) < 0) + { return false; + } } int from = alpha ? 2 : 0; if (ParseCol8(color, from + 0) < 0) - return false; - if (ParseCol8(color, from + 2) < 0) - return false; - if (ParseCol8(color, from + 4) < 0) - return false; - - return true; - } - - public static Color Color8(byte r8, byte g8, byte b8, byte a8 = 255) - { - return new Color(r8 / 255f, g8 / 255f, b8 / 255f, a8 / 255f); - } - - public Color(string rgba) - { - if (rgba.Length == 0) { - r = 0f; - g = 0f; - b = 0f; - a = 1.0f; - return; - } - - if (rgba[0] == '#') - rgba = rgba.Substring(1); - - bool alpha; - - if (rgba.Length == 8) - { - alpha = true; - } - else if (rgba.Length == 6) - { - alpha = false; - } - else - { - throw new ArgumentOutOfRangeException("Invalid color code. Length is " + rgba.Length + " but a length of 6 or 8 is expected: " + rgba); + return false; } - - if (alpha) + if (ParseCol8(color, from + 2) < 0) { - a = ParseCol8(rgba, 0) / 255f; - - if (a < 0) - throw new ArgumentOutOfRangeException("Invalid color code. Alpha part is not valid hexadecimal: " + rgba); + return false; } - else + if (ParseCol8(color, from + 4) < 0) { - a = 1.0f; + return false; } - int from = alpha ? 2 : 0; - - r = ParseCol8(rgba, from + 0) / 255f; - - if (r < 0) - throw new ArgumentOutOfRangeException("Invalid color code. Red part is not valid hexadecimal: " + rgba); - - g = ParseCol8(rgba, from + 2) / 255f; - - if (g < 0) - throw new ArgumentOutOfRangeException("Invalid color code. Green part is not valid hexadecimal: " + rgba); - - b = ParseCol8(rgba, from + 4) / 255f; - - if (b < 0) - throw new ArgumentOutOfRangeException("Invalid color code. Blue part is not valid hexadecimal: " + rgba); + return true; } public static Color operator +(Color left, Color right) @@ -708,13 +956,13 @@ namespace Godot if (Mathf.IsEqualApprox(left.g, right.g)) { if (Mathf.IsEqualApprox(left.b, right.b)) + { return left.a < right.a; + } return left.b < right.b; } - return left.g < right.g; } - return left.r < right.r; } @@ -725,13 +973,13 @@ namespace Godot if (Mathf.IsEqualApprox(left.g, right.g)) { if (Mathf.IsEqualApprox(left.b, right.b)) + { return left.a > right.a; + } return left.b > right.b; } - return left.g > right.g; } - return left.r > right.r; } @@ -750,6 +998,12 @@ namespace Godot return r == other.r && g == other.g && b == other.b && a == other.a; } + /// <summary> + /// Returns true if this color and `other` are approximately equal, by running + /// <see cref="Godot.Mathf.IsEqualApprox(float, float)"/> on each component. + /// </summary> + /// <param name="other">The other color to compare.</param> + /// <returns>Whether or not the colors are approximately equal.</returns> public bool IsEqualApprox(Color other) { return Mathf.IsEqualApprox(r, other.r) && Mathf.IsEqualApprox(g, other.g) && Mathf.IsEqualApprox(b, other.b) && Mathf.IsEqualApprox(a, other.a); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs index f41f5e9fc8..d05a0414aa 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Colors.cs @@ -3,6 +3,10 @@ using System.Collections.Generic; namespace Godot { + /// <summary> + /// This class contains color constants created from standardized color names. + /// The standardized color set is based on the X11 and .NET color names. + /// </summary> public static class Colors { // Color names and values are derived from core/color_names.inc diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs index 4f7aa99df8..6eecc262d6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Mathf.cs @@ -11,79 +11,185 @@ namespace Godot { // Define constants with Decimal precision and cast down to double or float. + /// <summary> + /// The circle constant, the circumference of the unit circle in radians. + /// </summary> public const real_t Tau = (real_t) 6.2831853071795864769252867666M; // 6.2831855f and 6.28318530717959 + + /// <summary> + /// Constant that represents how many times the diameter of a circle + /// fits around its perimeter. This is equivalent to `Mathf.Tau / 2`. + /// </summary> public const real_t Pi = (real_t) 3.1415926535897932384626433833M; // 3.1415927f and 3.14159265358979 + + /// <summary> + /// Positive infinity. For negative infinity, use `-Mathf.Inf`. + /// </summary> public const real_t Inf = real_t.PositiveInfinity; + + /// <summary> + /// "Not a Number", an invalid value. `NaN` has special properties, including + /// that it is not equal to itself. It is output by some invalid operations, + /// such as dividing zero by zero. + /// </summary> public const real_t NaN = real_t.NaN; private const real_t Deg2RadConst = (real_t) 0.0174532925199432957692369077M; // 0.0174532924f and 0.0174532925199433 private const real_t Rad2DegConst = (real_t) 57.295779513082320876798154814M; // 57.29578f and 57.2957795130823 + /// <summary> + /// Returns the absolute value of `s` (i.e. positive value). + /// </summary> + /// <param name="s">The input number.</param> + /// <returns>The absolute value of `s`.</returns> public static int Abs(int s) { return Math.Abs(s); } + /// <summary> + /// Returns the absolute value of `s` (i.e. positive value). + /// </summary> + /// <param name="s">The input number.</param> + /// <returns>The absolute value of `s`.</returns> public static real_t Abs(real_t s) { return Math.Abs(s); } + /// <summary> + /// Returns the arc cosine of `s` in radians. Use to get the angle of cosine s. + /// </summary> + /// <param name="s">The input cosine value. Must be on the range of -1.0 to 1.0.</param> + /// <returns>An angle that would result in the given cosine value. On the range `0` to `Tau/2`.</returns> public static real_t Acos(real_t s) { return (real_t)Math.Acos(s); } + /// <summary> + /// Returns the arc sine of `s` in radians. Use to get the angle of sine s. + /// </summary> + /// <param name="s">The input sine value. Must be on the range of -1.0 to 1.0.</param> + /// <returns>An angle that would result in the given sine value. On the range `-Tau/4` to `Tau/4`.</returns> public static real_t Asin(real_t s) { return (real_t)Math.Asin(s); } + /// <summary> + /// Returns the arc tangent of `s` in radians. Use to get the angle of tangent s. + /// + /// The method cannot know in which quadrant the angle should fall. + /// See <see cref="Atan2(real_t, real_t)"/> if you have both `y` and `x`. + /// </summary> + /// <param name="s">The input tangent value.</param> + /// <returns>An angle that would result in the given tangent value. On the range `-Tau/4` to `Tau/4`.</returns> public static real_t Atan(real_t s) { return (real_t)Math.Atan(s); } + /// <summary> + /// Returns the arc tangent of `y` and `x` in radians. Use to get the angle + /// of the tangent of `y/x`. To compute the value, the method takes into + /// account the sign of both arguments in order to determine the quadrant. + /// + /// Important note: The Y coordinate comes first, by convention. + /// </summary> + /// <param name="y">The Y coordinate of the point to find the angle to.</param> + /// <param name="x">The X coordinate of the point to find the angle to.</param> + /// <returns>An angle that would result in the given tangent value. On the range `-Tau/2` to `Tau/2`.</returns> public static real_t Atan2(real_t y, real_t x) { return (real_t)Math.Atan2(y, x); } + /// <summary> + /// 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). + /// </summary> + /// <param name="x">The input X coordinate.</param> + /// <param name="y">The input Y coordinate.</param> + /// <returns>A <see cref="Vector2"/> with X representing the distance and Y representing the angle.</returns> public static Vector2 Cartesian2Polar(real_t x, real_t y) { return new Vector2(Sqrt(x * x + y * y), Atan2(y, x)); } + /// <summary> + /// Rounds `s` upward (towards positive infinity). + /// </summary> + /// <param name="s">The number to ceil.</param> + /// <returns>The smallest whole number that is not less than `s`.</returns> public static real_t Ceil(real_t s) { return (real_t)Math.Ceiling(s); } + /// <summary> + /// Clamps a `value` so that it is not less than `min` and not more than `max`. + /// </summary> + /// <param name="value">The value to clamp.</param> + /// <param name="min">The minimum allowed value.</param> + /// <param name="max">The maximum allowed value.</param> + /// <returns>The clamped value.</returns> public static int Clamp(int value, int min, int max) { return value < min ? min : value > max ? max : value; } + /// <summary> + /// Clamps a `value` so that it is not less than `min` and not more than `max`. + /// </summary> + /// <param name="value">The value to clamp.</param> + /// <param name="min">The minimum allowed value.</param> + /// <param name="max">The maximum allowed value.</param> + /// <returns>The clamped value.</returns> public static real_t Clamp(real_t value, real_t min, real_t max) { return value < min ? min : value > max ? max : value; } + /// <summary> + /// Returns the cosine of angle `s` in radians. + /// </summary> + /// <param name="s">The angle in radians.</param> + /// <returns>The cosine of that angle.</returns> public static real_t Cos(real_t s) { return (real_t)Math.Cos(s); } + /// <summary> + /// Returns the hyperbolic cosine of angle `s` in radians. + /// </summary> + /// <param name="s">The angle in radians.</param> + /// <returns>The hyperbolic cosine of that angle.</returns> public static real_t Cosh(real_t s) { return (real_t)Math.Cosh(s); } + /// <summary> + /// Converts an angle expressed in degrees to radians. + /// </summary> + /// <param name="deg">An angle expressed in degrees.</param> + /// <returns>The same angle expressed in radians.</returns> public static real_t Deg2Rad(real_t deg) { return deg * Deg2RadConst; } + /// <summary> + /// Easing function, based on exponent. The curve values are: + /// `0` is constant, `1` is linear, `0` to `1` is ease-in, `1` or more is ease-out. + /// Negative values are in-out/out-in. + /// </summary> + /// <param name="s">The value to ease.</param> + /// <param name="curve">`0` is constant, `1` is linear, `0` to `1` is ease-in, `1` or more is ease-out.</param> + /// <returns>The eased value.</returns> public static real_t Ease(real_t s, real_t curve) { if (s < 0f) @@ -118,21 +224,47 @@ namespace Godot return 0f; } + /// <summary> + /// The natural exponential function. It raises the mathematical + /// constant `e` to the power of `s` and returns it. + /// </summary> + /// <param name="s">The exponent to raise `e` to.</param> + /// <returns>`e` raised to the power of `s`.</returns> public static real_t Exp(real_t s) { return (real_t)Math.Exp(s); } + /// <summary> + /// Rounds `s` downward (towards negative infinity). + /// </summary> + /// <param name="s">The number to floor.</param> + /// <returns>The largest whole number that is not more than `s`.</returns> public static real_t Floor(real_t s) { return (real_t)Math.Floor(s); } + /// <summary> + /// Returns a normalized value considering the given range. + /// This is the opposite of <see cref="Lerp(real_t, real_t, real_t)"/>. + /// </summary> + /// <param name="from">The interpolated value.</param> + /// <param name="to">The destination value for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting value of the inverse interpolation.</returns> public static real_t InverseLerp(real_t from, real_t to, real_t weight) { return (weight - from) / (to - from); } + /// <summary> + /// Returns true if `a` and `b` are approximately equal to each other. + /// The comparison is done using a tolerance calculation with <see cref="Epsilon"/>. + /// </summary> + /// <param name="a">One of the values.</param> + /// <param name="b">The other value.</param> + /// <returns>A bool for whether or not the two values are approximately equal.</returns> public static bool IsEqualApprox(real_t a, real_t b) { // Check for exact equality first, required to handle "infinity" values. @@ -149,26 +281,62 @@ namespace Godot return Abs(a - b) < tolerance; } + /// <summary> + /// Returns whether `s` is an infinity value (either positive infinity or negative infinity). + /// </summary> + /// <param name="s">The value to check.</param> + /// <returns>A bool for whether or not the value is an infinity value.</returns> public static bool IsInf(real_t s) { return real_t.IsInfinity(s); } + /// <summary> + /// Returns whether `s` is a `NaN` ("Not a Number" or invalid) value. + /// </summary> + /// <param name="s">The value to check.</param> + /// <returns>A bool for whether or not the value is a `NaN` value.</returns> public static bool IsNaN(real_t s) { return real_t.IsNaN(s); } + /// <summary> + /// Returns true if `s` is approximately zero. + /// The comparison is done using a tolerance calculation with <see cref="Epsilon"/>. + /// + /// This method is faster than using <see cref="IsEqualApprox(real_t, real_t)"/> with one value as zero. + /// </summary> + /// <param name="s">The value to check.</param> + /// <returns>A bool for whether or not the value is nearly zero.</returns> public static bool IsZeroApprox(real_t s) { return Abs(s) < Epsilon; } + /// <summary> + /// Linearly interpolates between two values by a normalized value. + /// This is the opposite <see cref="InverseLerp(real_t, real_t, real_t)"/>. + /// </summary> + /// <param name="from">The start value for interpolation.</param> + /// <param name="to">The destination value for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting value of the interpolation.</returns> public static real_t Lerp(real_t from, real_t to, real_t weight) { return from + (to - from) * weight; } + /// <summary> + /// Linearly interpolates between two angles (in radians) by a normalized value. + /// + /// Similar to <see cref="Lerp(real_t, real_t, real_t)"/>, + /// but interpolates correctly when the angles wrap around <see cref="Tau"/>. + /// </summary> + /// <param name="from">The start angle for interpolation.</param> + /// <param name="to">The destination angle for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting angle of the interpolation.</returns> public static real_t LerpAngle(real_t from, real_t to, real_t weight) { real_t difference = (to - from) % Mathf.Tau; @@ -176,36 +344,81 @@ namespace Godot return from + distance * weight; } + /// <summary> + /// Natural logarithm. The amount of time needed to reach a certain level of continuous growth. + /// + /// Note: This is not the same as the "log" function on most calculators, which uses a base 10 logarithm. + /// </summary> + /// <param name="s">The input value.</param> + /// <returns>The natural log of `s`.</returns> public static real_t Log(real_t s) { return (real_t)Math.Log(s); } + /// <summary> + /// Returns the maximum of two values. + /// </summary> + /// <param name="a">One of the values.</param> + /// <param name="b">The other value.</param> + /// <returns>Whichever of the two values is higher.</returns> public static int Max(int a, int b) { return a > b ? a : b; } + /// <summary> + /// Returns the maximum of two values. + /// </summary> + /// <param name="a">One of the values.</param> + /// <param name="b">The other value.</param> + /// <returns>Whichever of the two values is higher.</returns> public static real_t Max(real_t a, real_t b) { return a > b ? a : b; } + /// <summary> + /// Returns the minimum of two values. + /// </summary> + /// <param name="a">One of the values.</param> + /// <param name="b">The other value.</param> + /// <returns>Whichever of the two values is lower.</returns> public static int Min(int a, int b) { return a < b ? a : b; } + /// <summary> + /// Returns the minimum of two values. + /// </summary> + /// <param name="a">One of the values.</param> + /// <param name="b">The other value.</param> + /// <returns>Whichever of the two values is lower.</returns> public static real_t Min(real_t a, real_t b) { return a < b ? a : b; } + /// <summary> + /// Moves `from` toward `to` by the `delta` value. + /// + /// Use a negative delta value to move away. + /// </summary> + /// <param name="from">The start value.</param> + /// <param name="to">The value to move towards.</param> + /// <param name="delta">The amount to move by.</param> + /// <returns>The value after moving.</returns> public static real_t MoveToward(real_t from, real_t to, real_t delta) { return Abs(to - from) <= delta ? to : from + Sign(to - from) * delta; } + /// <summary> + /// Returns the nearest larger power of 2 for the integer `value`. + /// </summary> + /// <param name="value">The input value.</param> + /// <returns>The nearest larger power of 2.</returns> public static int NearestPo2(int value) { value--; @@ -218,14 +431,25 @@ namespace Godot return value; } + /// <summary> + /// Converts a 2D point expressed in the polar coordinate + /// system (a distance from the origin `r` and an angle `th`) + /// to the cartesian coordinate system (X and Y axis). + /// </summary> + /// <param name="r">The distance from the origin.</param> + /// <param name="th">The angle of the point.</param> + /// <returns>A <see cref="Vector2"/> representing the cartesian coordinate.</returns> public static Vector2 Polar2Cartesian(real_t r, real_t th) { return new Vector2(r * Cos(th), r * Sin(th)); } /// <summary> - /// Performs a canonical Modulus operation, where the output is on the range [0, b). + /// Performs a canonical Modulus operation, where the output is on the range `[0, b)`. /// </summary> + /// <param name="a">The dividend, the primary input.</param> + /// <param name="b">The divisor. The output is on the range `[0, b)`.</param> + /// <returns>The resulting output.</returns> public static int PosMod(int a, int b) { int c = a % b; @@ -237,8 +461,11 @@ namespace Godot } /// <summary> - /// Performs a canonical Modulus operation, where the output is on the range [0, b). + /// Performs a canonical Modulus operation, where the output is on the range `[0, b)`. /// </summary> + /// <param name="a">The dividend, the primary input.</param> + /// <param name="b">The divisor. The output is on the range `[0, b)`.</param> + /// <returns>The resulting output.</returns> public static real_t PosMod(real_t a, real_t b) { real_t c = a % b; @@ -249,43 +476,89 @@ namespace Godot return c; } + /// <summary> + /// Returns the result of `x` raised to the power of `y`. + /// </summary> + /// <param name="x">The base.</param> + /// <param name="y">The exponent.</param> + /// <returns>`x` raised to the power of `y`.</returns> public static real_t Pow(real_t x, real_t y) { return (real_t)Math.Pow(x, y); } + /// <summary> + /// Converts an angle expressed in radians to degrees. + /// </summary> + /// <param name="rad">An angle expressed in radians.</param> + /// <returns>The same angle expressed in degrees.</returns> public static real_t Rad2Deg(real_t rad) { return rad * Rad2DegConst; } + /// <summary> + /// Rounds `s` to the nearest whole number, + /// with halfway cases rounded towards the nearest multiple of two. + /// </summary> + /// <param name="s">The number to round.</param> + /// <returns>The rounded number.</returns> public static real_t Round(real_t s) { return (real_t)Math.Round(s); } + /// <summary> + /// Returns the sign of `s`: `-1` or `1`. Returns `0` if `s` is `0`. + /// </summary> + /// <param name="s">The input number.</param> + /// <returns>One of three possible values: `1`, `-1`, or `0`.</returns> public static int Sign(int s) { if (s == 0) return 0; return s < 0 ? -1 : 1; } + /// <summary> + /// Returns the sign of `s`: `-1` or `1`. Returns `0` if `s` is `0`. + /// </summary> + /// <param name="s">The input number.</param> + /// <returns>One of three possible values: `1`, `-1`, or `0`.</returns> public static int Sign(real_t s) { if (s == 0) return 0; return s < 0 ? -1 : 1; } + /// <summary> + /// Returns the sine of angle `s` in radians. + /// </summary> + /// <param name="s">The angle in radians.</param> + /// <returns>The sine of that angle.</returns> public static real_t Sin(real_t s) { return (real_t)Math.Sin(s); } + /// <summary> + /// Returns the hyperbolic sine of angle `s` in radians. + /// </summary> + /// <param name="s">The angle in radians.</param> + /// <returns>The hyperbolic sine of that angle.</returns> public static real_t Sinh(real_t s) { return (real_t)Math.Sinh(s); } + /// <summary> + /// Returns a number smoothly interpolated between `from` and `to`, + /// based on the `weight`. Similar to <see cref="Lerp(real_t, real_t, real_t)"/>, + /// but interpolates faster at the beginning and slower at the end. + /// </summary> + /// <param name="from">The start value for interpolation.</param> + /// <param name="to">The destination value for interpolation.</param> + /// <param name="weight">A value representing the amount of interpolation.</param> + /// <returns>The resulting value of the interpolation.</returns> public static real_t SmoothStep(real_t from, real_t to, real_t weight) { if (IsEqualApprox(from, to)) @@ -296,11 +569,25 @@ namespace Godot return x * x * (3 - 2 * x); } + /// <summary> + /// Returns the square root of `s`, where `s` is a non-negative number. + /// + /// If you need negative inputs, use `System.Numerics.Complex`. + /// </summary> + /// <param name="s">The input number. Must not be negative.</param> + /// <returns>The square root of `s`.</returns> public static real_t Sqrt(real_t s) { return (real_t)Math.Sqrt(s); } + /// <summary> + /// Returns the position of the first non-zero digit, after the + /// decimal point. Note that the maximum return value is 10, + /// which is a design decision in the implementation. + /// </summary> + /// <param name="step">The input value.</param> + /// <returns>The position of the first non-zero digit.</returns> public static int StepDecimals(real_t step) { double[] sd = new double[] { @@ -326,32 +613,68 @@ namespace Godot return 0; } + /// <summary> + /// Snaps float value `s` to a given `step`. + /// This can also be used to round a floating point + /// number to an arbitrary number of decimals. + /// </summary> + /// <param name="s">The value to stepify.</param> + /// <param name="step">The step size to snap to.</param> + /// <returns></returns> public static real_t Stepify(real_t s, real_t step) { if (step != 0f) { - s = Floor(s / step + 0.5f) * step; + return Floor(s / step + 0.5f) * step; } return s; } + /// <summary> + /// Returns the tangent of angle `s` in radians. + /// </summary> + /// <param name="s">The angle in radians.</param> + /// <returns>The tangent of that angle.</returns> public static real_t Tan(real_t s) { return (real_t)Math.Tan(s); } + /// <summary> + /// Returns the hyperbolic tangent of angle `s` in radians. + /// </summary> + /// <param name="s">The angle in radians.</param> + /// <returns>The hyperbolic tangent of that angle.</returns> public static real_t Tanh(real_t s) { return (real_t)Math.Tanh(s); } + /// <summary> + /// Wraps `value` between `min` and `max`. Usable for creating loop-alike + /// behavior or infinite surfaces. If `min` is `0`, this is equivalent + /// to <see cref="PosMod(int, int)"/>, so prefer using that instead. + /// </summary> + /// <param name="value">The value to wrap.</param> + /// <param name="min">The minimum allowed value and lower bound of the range.</param> + /// <param name="max">The maximum allowed value and upper bound of the range.</param> + /// <returns>The wrapped value.</returns> public static int Wrap(int value, int min, int max) { int range = max - min; return range == 0 ? min : min + ((value - min) % range + range) % range; } + /// <summary> + /// Wraps `value` between `min` and `max`. Usable for creating loop-alike + /// behavior or infinite surfaces. If `min` is `0`, this is equivalent + /// to <see cref="PosMod(real_t, real_t)"/>, so prefer using that instead. + /// </summary> + /// <param name="value">The value to wrap.</param> + /// <param name="min">The minimum allowed value and lower bound of the range.</param> + /// <param name="max">The maximum allowed value and upper bound of the range.</param> + /// <returns>The wrapped value.</returns> public static real_t Wrap(real_t value, real_t min, real_t max) { real_t range = max - min; diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/MathfEx.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/MathfEx.cs index 1b7fd4906f..c2f4701b5f 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/MathfEx.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/MathfEx.cs @@ -12,40 +12,89 @@ namespace Godot { // Define constants with Decimal precision and cast down to double or float. + /// <summary> + /// The natural number `e`. + /// </summary> public const real_t E = (real_t) 2.7182818284590452353602874714M; // 2.7182817f and 2.718281828459045 + + /// <summary> + /// The square root of 2. + /// </summary> public const real_t Sqrt2 = (real_t) 1.4142135623730950488016887242M; // 1.4142136f and 1.414213562373095 + /// <summary> + /// A very small number used for float comparison with error tolerance. + /// 1e-06 with single-precision floats, but 1e-14 if `REAL_T_IS_DOUBLE`. + /// </summary> #if REAL_T_IS_DOUBLE public const real_t Epsilon = 1e-14; // Epsilon size should depend on the precision used. #else public const real_t Epsilon = 1e-06f; #endif + /// <summary> + /// Returns the amount of digits after the decimal place. + /// </summary> + /// <param name="s">The input value.</param> + /// <returns>The amount of digits.</returns> public static int DecimalCount(real_t s) { return DecimalCount((decimal)s); } + /// <summary> + /// Returns the amount of digits after the decimal place. + /// </summary> + /// <param name="s">The input <see cref="System.Decimal"/> value.</param> + /// <returns>The amount of digits.</returns> public static int DecimalCount(decimal s) { return BitConverter.GetBytes(decimal.GetBits(s)[3])[2]; } + /// <summary> + /// Rounds `s` upward (towards positive infinity). + /// + /// This is the same as <see cref="Ceil(real_t)"/>, but returns an `int`. + /// </summary> + /// <param name="s">The number to ceil.</param> + /// <returns>The smallest whole number that is not less than `s`.</returns> public static int CeilToInt(real_t s) { return (int)Math.Ceiling(s); } + /// <summary> + /// Rounds `s` downward (towards negative infinity). + /// + /// This is the same as <see cref="Floor(real_t)"/>, but returns an `int`. + /// </summary> + /// <param name="s">The number to floor.</param> + /// <returns>The largest whole number that is not more than `s`.</returns> public static int FloorToInt(real_t s) { return (int)Math.Floor(s); } + /// <summary> + /// + /// </summary> + /// <param name="s"></param> + /// <returns></returns> public static int RoundToInt(real_t s) { return (int)Math.Round(s); } + /// <summary> + /// Returns true if `a` and `b` are approximately equal to each other. + /// The comparison is done using the provided tolerance value. + /// If you want the tolerance to be calculated for you, use <see cref="IsEqualApprox(real_t, real_t)"/>. + /// </summary> + /// <param name="a">One of the values.</param> + /// <param name="b">The other value.</param> + /// <param name="tolerance">The pre-calculated tolerance value.</param> + /// <returns>A bool for whether or not the two values are equal.</returns> public static bool IsEqualApprox(real_t a, real_t b, real_t tolerance) { // Check for exact equality first, required to handle "infinity" values. diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs index 885845e3a4..3b4e749532 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Plane.cs @@ -8,18 +8,33 @@ using real_t = System.Single; namespace Godot { + /// <summary> + /// Plane represents a normalized plane equation. + /// "Over" or "Above" the plane is considered the side of + /// the plane towards where the normal is pointing. + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Plane : IEquatable<Plane> { private Vector3 _normal; + /// <summary> + /// The normal of the plane, which must be normalized. + /// In the scalar equation of the plane `ax + by + cz = d`, this is + /// the vector `(a, b, c)`, where `d` is the <see cref="D"/> property. + /// </summary> + /// <value>Equivalent to `x`, `y`, and `z`.</value> public Vector3 Normal { get { return _normal; } set { _normal = value; } } + /// <summary> + /// The X component of the plane's normal vector. + /// </summary> + /// <value>Equivalent to <see cref="Normal"/>'s X value.</value> public real_t x { get @@ -32,6 +47,10 @@ namespace Godot } } + /// <summary> + /// The Y component of the plane's normal vector. + /// </summary> + /// <value>Equivalent to <see cref="Normal"/>'s Y value.</value> public real_t y { get @@ -44,6 +63,10 @@ namespace Godot } } + /// <summary> + /// The Z component of the plane's normal vector. + /// </summary> + /// <value>Equivalent to <see cref="Normal"/>'s Z value.</value> public real_t z { get @@ -56,38 +79,71 @@ namespace Godot } } + /// <summary> + /// The distance from the origin to the plane (in the direction of + /// <see cref="Normal"/>). This value is typically non-negative. + /// In the scalar equation of the plane `ax + by + cz = d`, + /// this is `d`, while the `(a, b, c)` coordinates are represented + /// by the <see cref="Normal"/> property. + /// </summary> + /// <value>The plane's distance from the origin.</value> public real_t D { get; set; } + /// <summary> + /// The center of the plane, the point where the normal line intersects the plane. + /// </summary> + /// <value>Equivalent to <see cref="Normal"/> multiplied by `D`.</value> public Vector3 Center { get { return _normal * D; } + set + { + _normal = value.Normalized(); + D = value.Length(); + } } + /// <summary> + /// Returns the shortest distance from this plane to the position `point`. + /// </summary> + /// <param name="point">The position to use for the calcualtion.</param> + /// <returns>The shortest distance.</returns> public real_t DistanceTo(Vector3 point) { return _normal.Dot(point) - D; } - public Vector3 GetAnyPoint() - { - return _normal * D; - } - + /// <summary> + /// Returns true if point is inside the plane. + /// Comparison uses a custom minimum epsilon threshold. + /// </summary> + /// <param name="point">The point to check.</param> + /// <param name="epsilon">The tolerance threshold.</param> + /// <returns>A bool for whether or not the plane has the point.</returns> public bool HasPoint(Vector3 point, real_t epsilon = Mathf.Epsilon) { real_t dist = _normal.Dot(point) - D; return Mathf.Abs(dist) <= epsilon; } + /// <summary> + /// Returns the intersection point of the three planes: `b`, `c`, + /// and this plane. If no intersection is found, `null` is returned. + /// </summary> + /// <param name="b">One of the three planes to use in the calculation.</param> + /// <param name="c">One of the three planes to use in the calculation.</param> + /// <returns>The intersection, or `null` if none is found.</returns> public Vector3? Intersect3(Plane b, Plane c) { real_t denom = _normal.Cross(b._normal).Dot(c._normal); if (Mathf.IsZeroApprox(denom)) + { return null; + } Vector3 result = b._normal.Cross(c._normal) * D + c._normal.Cross(_normal) * b.D + @@ -96,54 +152,94 @@ namespace Godot return result / denom; } + /// <summary> + /// Returns the intersection point of a ray consisting of the + /// position `from` and the direction normal `dir` with this plane. + /// If no intersection is found, `null` is returned. + /// </summary> + /// <param name="from">The start of the ray.</param> + /// <param name="dir">The direction of the ray, normalized.</param> + /// <returns>The intersection, or `null` if none is found.</returns> public Vector3? IntersectRay(Vector3 from, Vector3 dir) { real_t den = _normal.Dot(dir); if (Mathf.IsZeroApprox(den)) + { return null; + } real_t dist = (_normal.Dot(from) - D) / den; // This is a ray, before the emitting pos (from) does not exist if (dist > Mathf.Epsilon) + { return null; + } return from + dir * -dist; } + /// <summary> + /// Returns the intersection point of a line segment from + /// position `begin` to position `end` with this plane. + /// If no intersection is found, `null` is returned. + /// </summary> + /// <param name="begin">The start of the line segment.</param> + /// <param name="end">The end of the line segment.</param> + /// <returns>The intersection, or `null` if none is found.</returns> public Vector3? IntersectSegment(Vector3 begin, Vector3 end) { Vector3 segment = begin - end; real_t den = _normal.Dot(segment); if (Mathf.IsZeroApprox(den)) + { return null; + } real_t dist = (_normal.Dot(begin) - D) / den; // Only allow dist to be in the range of 0 to 1, with tolerance. if (dist < -Mathf.Epsilon || dist > 1.0f + Mathf.Epsilon) + { return null; + } return begin + segment * -dist; } + /// <summary> + /// Returns true if `point` is located above the plane. + /// </summary> + /// <param name="point">The point to check.</param> + /// <returns>A bool for whether or not the point is above the plane.</returns> public bool IsPointOver(Vector3 point) { return _normal.Dot(point) > D; } + /// <summary> + /// Returns the plane scaled to unit length. + /// </summary> + /// <returns>A normalized version of the plane.</returns> public Plane Normalized() { real_t len = _normal.Length(); if (len == 0) + { return new Plane(0, 0, 0, 0); + } return new Plane(_normal / len, D / len); } + /// <summary> + /// Returns the orthogonal projection of `point` into the plane. + /// </summary> + /// <param name="point">The point to project.</param> + /// <returns>The projected point.</returns> public Vector3 Project(Vector3 point) { return point - _normal * DistanceTo(point); @@ -154,22 +250,56 @@ namespace Godot private static readonly Plane _planeXZ = new Plane(0, 1, 0, 0); private static readonly Plane _planeXY = new Plane(0, 0, 1, 0); + /// <summary> + /// A plane that extends in the Y and Z axes (normal vector points +X). + /// </summary> + /// <value>Equivalent to `new Plane(1, 0, 0, 0)`.</value> public static Plane PlaneYZ { get { return _planeYZ; } } + + /// <summary> + /// A plane that extends in the X and Z axes (normal vector points +Y). + /// </summary> + /// <value>Equivalent to `new Plane(0, 1, 0, 0)`.</value> public static Plane PlaneXZ { get { return _planeXZ; } } + + /// <summary> + /// A plane that extends in the X and Y axes (normal vector points +Z). + /// </summary> + /// <value>Equivalent to `new Plane(0, 0, 1, 0)`.</value> public static Plane PlaneXY { get { return _planeXY; } } - // Constructors + /// <summary> + /// Constructs a plane from four values. `a`, `b` and `c` become the + /// components of the resulting plane's <see cref="Normal"/> vector. + /// `d` becomes the plane's distance from the origin. + /// </summary> + /// <param name="a">The X component of the plane's normal vector.</param> + /// <param name="b">The Y component of the plane's normal vector.</param> + /// <param name="c">The Z component of the plane's normal vector.</param> + /// <param name="d">The plane's distance from the origin. This value is typically non-negative.</param> public Plane(real_t a, real_t b, real_t c, real_t d) { _normal = new Vector3(a, b, c); this.D = d; } + + /// <summary> + /// Constructs a plane from a normal vector and the plane's distance to the origin. + /// </summary> + /// <param name="normal">The normal of the plane, must be normalized.</param> + /// <param name="d">The plane's distance from the origin. This value is typically non-negative.</param> public Plane(Vector3 normal, real_t d) { this._normal = normal; this.D = d; } + /// <summary> + /// Constructs a plane from the three points, given in clockwise order. + /// </summary> + /// <param name="v1">The first point.</param> + /// <param name="v2">The second point.</param> + /// <param name="v3">The third point.</param> public Plane(Vector3 v1, Vector3 v2, Vector3 v3) { _normal = (v1 - v3).Cross(v1 - v2); @@ -207,6 +337,12 @@ namespace Godot return _normal == other._normal && D == other.D; } + /// <summary> + /// Returns true if this plane and `other` are approximately equal, by running + /// <see cref="Mathf.IsEqualApprox(real_t, real_t)"/> on each component. + /// </summary> + /// <param name="other">The other plane to compare.</param> + /// <returns>Whether or not the planes are approximately equal.</returns> public bool IsEqualApprox(Plane other) { return _normal.IsEqualApprox(other._normal) && Mathf.IsEqualApprox(D, other.D); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quat.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quat.cs index bbc617ea6e..7c978801bd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Quat.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Quat.cs @@ -8,15 +8,51 @@ using real_t = System.Single; namespace Godot { + /// <summary> + /// A unit quaternion used for representing 3D rotations. + /// Quaternions need to be normalized to be used for rotation. + /// + /// It is similar to Basis, which implements matrix representation of + /// rotations, and can be parametrized using both an axis-angle pair + /// or Euler angles. Basis stores rotation, scale, and shearing, + /// while Quat only stores rotation. + /// + /// Due to its compactness and the way it is stored in memory, certain + /// operations (obtaining axis-angle and performing SLERP, in particular) + /// are more efficient and robust against floating-point errors. + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Quat : IEquatable<Quat> { + /// <summary> + /// X component of the quaternion (imaginary `i` axis part). + /// Quaternion components should usually not be manipulated directly. + /// </summary> public real_t x; + + /// <summary> + /// Y component of the quaternion (imaginary `j` axis part). + /// Quaternion components should usually not be manipulated directly. + /// </summary> public real_t y; + + /// <summary> + /// Z component of the quaternion (imaginary `k` axis part). + /// Quaternion components should usually not be manipulated directly. + /// </summary> public real_t z; + + /// <summary> + /// W component of the quaternion (real part). + /// Quaternion components should usually not be manipulated directly. + /// </summary> public real_t w; + /// <summary> + /// Access quaternion components using their index. + /// </summary> + /// <value>`[0]` is equivalent to `.x`, `[1]` is equivalent to `.y`, `[2]` is equivalent to `.z`, `[3]` is equivalent to `.w`.</value> public real_t this[int index] { get @@ -57,16 +93,35 @@ namespace Godot } } + /// <summary> + /// Returns the length (magnitude) of the quaternion. + /// </summary> + /// <value>Equivalent to `Mathf.Sqrt(LengthSquared)`.</value> public real_t Length { get { return Mathf.Sqrt(LengthSquared); } } + /// <summary> + /// Returns the squared length (squared magnitude) of the quaternion. + /// This method runs faster than <see cref="Length"/>, so prefer it if + /// you need to compare quaternions or need the squared length for some formula. + /// </summary> + /// <value>Equivalent to `Dot(this)`.</value> public real_t LengthSquared { get { return Dot(this); } } + /// <summary> + /// Performs a cubic spherical interpolation between quaternions `preA`, + /// this vector, `b`, and `postB`, by the given amount `t`. + /// </summary> + /// <param name="b">The destination quaternion.</param> + /// <param name="preA">A quaternion before this quaternion.</param> + /// <param name="postB">A quaternion after `b`.</param> + /// <param name="t">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The interpolated quaternion.</returns> public Quat CubicSlerp(Quat b, Quat preA, Quat postB, real_t t) { real_t t2 = (1.0f - t) * t * 2f; @@ -75,85 +130,131 @@ namespace Godot return sp.Slerpni(sq, t2); } + /// <summary> + /// Returns the dot product of two quaternions. + /// </summary> + /// <param name="b">The other quaternion.</param> + /// <returns>The dot product.</returns> public real_t Dot(Quat b) { return x * b.x + y * b.y + z * b.z + w * b.w; } + /// <summary> + /// Returns Euler angles (in the YXZ convention: when decomposing, + /// first Z, then X, and Y last) corresponding to the rotation + /// represented by the unit quaternion. Returned vector contains + /// the rotation angles in the format (X angle, Y angle, Z angle). + /// </summary> + /// <returns>The Euler angle representation of this quaternion.</returns> public Vector3 GetEuler() { #if DEBUG if (!IsNormalized()) + { throw new InvalidOperationException("Quat is not normalized"); + } #endif var basis = new Basis(this); return basis.GetEuler(); } + /// <summary> + /// Returns the inverse of the quaternion. + /// </summary> + /// <returns>The inverse quaternion.</returns> public Quat Inverse() { #if DEBUG if (!IsNormalized()) + { throw new InvalidOperationException("Quat is not normalized"); + } #endif return new Quat(-x, -y, -z, w); } + /// <summary> + /// Returns whether the quaternion is normalized or not. + /// </summary> + /// <returns>A bool for whether the quaternion is normalized or not.</returns> + public bool IsNormalized() + { + return Mathf.Abs(LengthSquared - 1) <= Mathf.Epsilon; + } + + /// <summary> + /// Returns a copy of the quaternion, normalized to unit length. + /// </summary> + /// <returns>The normalized quaternion.</returns> public Quat Normalized() { return this / Length; } - public Quat Slerp(Quat b, real_t t) + /// <summary> + /// Returns the result of the spherical linear interpolation between + /// this quaternion and `to` by amount `weight`. + /// + /// Note: Both quaternions must be normalized. + /// </summary> + /// <param name="to">The destination quaternion for interpolation. Must be normalized.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting quaternion of the interpolation.</returns> + public Quat Slerp(Quat to, real_t weight) { #if DEBUG if (!IsNormalized()) + { throw new InvalidOperationException("Quat is not normalized"); - if (!b.IsNormalized()) - throw new ArgumentException("Argument is not normalized", nameof(b)); + } + if (!to.IsNormalized()) + { + throw new ArgumentException("Argument is not normalized", nameof(to)); + } #endif - // Calculate cosine - real_t cosom = x * b.x + y * b.y + z * b.z + w * b.w; + // Calculate cosine. + real_t cosom = x * to.x + y * to.y + z * to.z + w * to.w; var to1 = new Quat(); - // Adjust signs if necessary + // Adjust signs if necessary. if (cosom < 0.0) { cosom = -cosom; - to1.x = -b.x; - to1.y = -b.y; - to1.z = -b.z; - to1.w = -b.w; + to1.x = -to.x; + to1.y = -to.y; + to1.z = -to.z; + to1.w = -to.w; } else { - to1.x = b.x; - to1.y = b.y; - to1.z = b.z; - to1.w = b.w; + to1.x = to.x; + to1.y = to.y; + to1.z = to.z; + to1.w = to.w; } real_t sinom, scale0, scale1; - // Calculate coefficients + // Calculate coefficients. if (1.0 - cosom > Mathf.Epsilon) { - // Standard case (Slerp) + // Standard case (Slerp). real_t omega = Mathf.Acos(cosom); sinom = Mathf.Sin(omega); - scale0 = Mathf.Sin((1.0f - t) * omega) / sinom; - scale1 = Mathf.Sin(t * omega) / sinom; + scale0 = Mathf.Sin((1.0f - weight) * omega) / sinom; + scale1 = Mathf.Sin(weight * omega) / sinom; } else { - // Quaternions are very close so we can do a linear interpolation - scale0 = 1.0f - t; - scale1 = t; + // Quaternions are very close so we can do a linear interpolation. + scale0 = 1.0f - weight; + scale1 = weight; } - // Calculate final values + // Calculate final values. return new Quat ( scale0 * x + scale1 * to1.x, @@ -163,9 +264,17 @@ namespace Godot ); } - public Quat Slerpni(Quat b, real_t t) + /// <summary> + /// Returns the result of the spherical linear interpolation between + /// this quaternion and `to` by amount `weight`, but without + /// checking if the rotation path is not bigger than 90 degrees. + /// </summary> + /// <param name="to">The destination quaternion for interpolation. Must be normalized.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting quaternion of the interpolation.</returns> + public Quat Slerpni(Quat to, real_t weight) { - real_t dot = Dot(b); + real_t dot = Dot(to); if (Mathf.Abs(dot) > 0.9999f) { @@ -174,33 +283,54 @@ namespace Godot real_t theta = Mathf.Acos(dot); real_t sinT = 1.0f / Mathf.Sin(theta); - real_t newFactor = Mathf.Sin(t * theta) * sinT; - real_t invFactor = Mathf.Sin((1.0f - t) * theta) * sinT; + real_t newFactor = Mathf.Sin(weight * theta) * sinT; + real_t invFactor = Mathf.Sin((1.0f - weight) * theta) * sinT; return new Quat ( - invFactor * x + newFactor * b.x, - invFactor * y + newFactor * b.y, - invFactor * z + newFactor * b.z, - invFactor * w + newFactor * b.w + invFactor * x + newFactor * to.x, + invFactor * y + newFactor * to.y, + invFactor * z + newFactor * to.z, + invFactor * w + newFactor * to.w ); } + /// <summary> + /// Returns a vector transformed (multiplied) by this quaternion. + /// </summary> + /// <param name="v">A vector to transform.</param> + /// <returns>The transfomed vector.</returns> public Vector3 Xform(Vector3 v) { #if DEBUG if (!IsNormalized()) + { throw new InvalidOperationException("Quat is not normalized"); + } #endif var u = new Vector3(x, y, z); Vector3 uv = u.Cross(v); return v + ((uv * w) + u.Cross(uv)) * 2; } - // Static Readonly Properties - public static Quat Identity { get; } = new Quat(0f, 0f, 0f, 1f); - - // Constructors + // Constants + private static readonly Quat _identity = new Quat(0, 0, 0, 1); + + /// <summary> + /// The identity quaternion, representing no rotation. + /// Equivalent to an identity <see cref="Basis"/> matrix. If a vector is transformed by + /// an identity quaternion, it will not change. + /// </summary> + /// <value>Equivalent to `new Quat(0, 0, 0, 1)`.</value> + public static Quat Identity { get { return _identity; } } + + /// <summary> + /// Constructs a quaternion defined by the given values. + /// </summary> + /// <param name="x">X component of the quaternion (imaginary `i` axis part).</param> + /// <param name="y">Y component of the quaternion (imaginary `j` axis part).</param> + /// <param name="z">Z component of the quaternion (imaginary `k` axis part).</param> + /// <param name="w">W component of the quaternion (real part).</param> public Quat(real_t x, real_t y, real_t z, real_t w) { this.x = x; @@ -209,21 +339,31 @@ namespace Godot this.w = w; } - public bool IsNormalized() - { - return Mathf.Abs(LengthSquared - 1) <= Mathf.Epsilon; - } - + /// <summary> + /// Constructs a quaternion from the given quaternion. + /// </summary> + /// <param name="q">The existing quaternion.</param> public Quat(Quat q) { this = q; } + /// <summary> + /// Constructs a quaternion from the given <see cref="Basis"/>. + /// </summary> + /// <param name="basis">The basis to construct from.</param> public Quat(Basis basis) { this = basis.Quat(); } + /// <summary> + /// Constructs a quaternion that will perform a rotation specified by + /// Euler angles (in the YXZ convention: when decomposing, + /// first Z, then X, and Y last), + /// given in the vector format as (X angle, Y angle, Z angle). + /// </summary> + /// <param name="eulerYXZ"></param> public Quat(Vector3 eulerYXZ) { real_t half_a1 = eulerYXZ.y * 0.5f; @@ -247,11 +387,19 @@ namespace Godot w = sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3; } + /// <summary> + /// Constructs a quaternion that will rotate around the given axis + /// by the specified angle. The axis must be a normalized vector. + /// </summary> + /// <param name="axis">The axis to rotate around. Must be normalized.</param> + /// <param name="angle">The angle to rotate, in radians.</param> public Quat(Vector3 axis, real_t angle) { #if DEBUG if (!axis.IsNormalized()) + { throw new ArgumentException("Argument is not normalized", nameof(axis)); + } #endif real_t d = axis.Length(); @@ -364,6 +512,12 @@ namespace Godot return x == other.x && y == other.y && z == other.z && w == other.w; } + /// <summary> + /// Returns true if this quaternion and `other` are approximately equal, by running + /// <see cref="Mathf.IsEqualApprox(real_t, real_t)"/> on each component. + /// </summary> + /// <param name="other">The other quaternion to compare.</param> + /// <returns>Whether or not the quaternions are approximately equal.</returns> public bool IsEqualApprox(Quat other) { return Mathf.IsEqualApprox(x, other.x) && Mathf.IsEqualApprox(y, other.y) && Mathf.IsEqualApprox(z, other.z) && Mathf.IsEqualApprox(w, other.w); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs index 1098ffe4e5..f7703c77cc 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2.cs @@ -8,6 +8,10 @@ using real_t = System.Single; namespace Godot { + /// <summary> + /// 2D axis-aligned bounding box. Rect2 consists of a position, a size, and + /// several utility functions. It is typically used for fast overlap tests. + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Rect2 : IEquatable<Rect2> @@ -15,29 +19,52 @@ namespace Godot private Vector2 _position; private Vector2 _size; + /// <summary> + /// Beginning corner. Typically has values lower than End. + /// </summary> + /// <value>Directly uses a private field.</value> public Vector2 Position { get { return _position; } set { _position = value; } } + /// <summary> + /// Size from Position to End. Typically all components are positive. + /// If the size is negative, you can use <see cref="Abs"/> to fix it. + /// </summary> + /// <value>Directly uses a private field.</value> public Vector2 Size { get { return _size; } set { _size = value; } } + /// <summary> + /// Ending corner. This is calculated as <see cref="Position"/> plus + /// <see cref="Size"/>. Setting this value will change the size. + /// </summary> + /// <value>Getting is equivalent to `value = Position + Size`, setting is equivalent to `Size = value - Position`.</value> public Vector2 End { get { return _position + _size; } set { _size = value - _position; } } + /// <summary> + /// The area of this rect. + /// </summary> + /// <value>Equivalent to <see cref="GetArea()"/>.</value> public real_t Area { get { return GetArea(); } } + /// <summary> + /// Returns a Rect2 with equivalent position and size, modified so that + /// the top-left corner is the origin and width and height are positive. + /// </summary> + /// <returns>The modified rect.</returns> public Rect2 Abs() { Vector2 end = End; @@ -45,12 +72,19 @@ namespace Godot return new Rect2(topLeft, _size.Abs()); } + /// <summary> + /// Returns the intersection of this Rect2 and `b`. + /// </summary> + /// <param name="b">The other rect.</param> + /// <returns>The clipped rect.</returns> public Rect2 Clip(Rect2 b) { var newRect = b; 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); @@ -64,6 +98,11 @@ namespace Godot return newRect; } + /// <summary> + /// Returns true if this Rect2 completely encloses another one. + /// </summary> + /// <param name="b">The other rect that may be enclosed.</param> + /// <returns>A bool for whether or not this rect encloses `b`.</returns> public bool Encloses(Rect2 b) { return b._position.x >= _position.x && b._position.y >= _position.y && @@ -71,6 +110,11 @@ namespace Godot b._position.y + b._size.y < _position.y + _size.y; } + /// <summary> + /// Returns this Rect2 expanded to include a given point. + /// </summary> + /// <param name="to">The point to include.</param> + /// <returns>The expanded rect.</returns> public Rect2 Expand(Vector2 to) { var expanded = this; @@ -79,14 +123,22 @@ namespace Godot Vector2 end = expanded._position + expanded._size; if (to.x < begin.x) + { begin.x = to.x; + } if (to.y < begin.y) + { begin.y = to.y; + } if (to.x > end.x) + { end.x = to.x; + } if (to.y > end.y) + { end.y = to.y; + } expanded._position = begin; expanded._size = end - begin; @@ -94,11 +146,20 @@ namespace Godot return expanded; } + /// <summary> + /// Returns the area of the Rect2. + /// </summary> + /// <returns>The area.</returns> public real_t GetArea() { return _size.x * _size.y; } + /// <summary> + /// Returns a copy of the Rect2 grown a given amount of units towards all the sides. + /// </summary> + /// <param name="by">The amount to grow by.</param> + /// <returns>The grown rect.</returns> public Rect2 Grow(real_t by) { var g = this; @@ -111,6 +172,14 @@ namespace Godot return g; } + /// <summary> + /// Returns a copy of the Rect2 grown a given amount of units towards each direction individually. + /// </summary> + /// <param name="left">The amount to grow by on the left.</param> + /// <param name="top">The amount to grow by on the top.</param> + /// <param name="right">The amount to grow by on the right.</param> + /// <param name="bottom">The amount to grow by on the bottom.</param> + /// <returns>The grown rect.</returns> public Rect2 GrowIndividual(real_t left, real_t top, real_t right, real_t bottom) { var g = this; @@ -123,6 +192,12 @@ namespace Godot return g; } + /// <summary> + /// Returns a copy of the Rect2 grown a given amount of units towards the <see cref="Margin"/> direction. + /// </summary> + /// <param name="margin">The direction to grow in.</param> + /// <param name="by">The amount to grow by.</param> + /// <returns>The grown rect.</returns> public Rect2 GrowMargin(Margin margin, real_t by) { var g = this; @@ -135,11 +210,20 @@ namespace Godot return g; } + /// <summary> + /// Returns true if the Rect2 is flat or empty, or false otherwise. + /// </summary> + /// <returns>A bool for whether or not the rect has area.</returns> public bool HasNoArea() { return _size.x <= 0 || _size.y <= 0; } + /// <summary> + /// Returns true if the Rect2 contains a point, or false otherwise. + /// </summary> + /// <param name="point">The point to check.</param> + /// <returns>A bool for whether or not the rect contains `point`.</returns> public bool HasPoint(Vector2 point) { if (point.x < _position.x) @@ -155,20 +239,65 @@ namespace Godot return true; } - public bool Intersects(Rect2 b) + /// <summary> + /// Returns true if the Rect2 overlaps with `b` + /// (i.e. they have at least one point in common). + /// + /// If `includeBorders` is true, they will also be considered overlapping + /// if their borders touch, even without intersection. + /// </summary> + /// <param name="b">The other rect to check for intersections with.</param> + /// <param name="includeBorders">Whether or not to consider borders.</param> + /// <returns>A bool for whether or not they are intersecting.</returns> + public bool Intersects(Rect2 b, bool includeBorders = false) { - if (_position.x >= b._position.x + b._size.x) - return false; - if (_position.x + _size.x <= b._position.x) - return false; - if (_position.y >= b._position.y + b._size.y) - return false; - if (_position.y + _size.y <= b._position.y) - return false; + if (includeBorders) + { + if (_position.x > b._position.x + b._size.x) + { + return false; + } + if (_position.x + _size.x < b._position.x) + { + return false; + } + if (_position.y > b._position.y + b._size.y) + { + return false; + } + if (_position.y + _size.y < b._position.y) + { + return false; + } + } + else + { + if (_position.x >= b._position.x + b._size.x) + { + return false; + } + if (_position.x + _size.x <= b._position.x) + { + return false; + } + if (_position.y >= b._position.y + b._size.y) + { + return false; + } + if (_position.y + _size.y <= b._position.y) + { + return false; + } + } return true; } + /// <summary> + /// Returns a larger Rect2 that contains this Rect2 and `b`. + /// </summary> + /// <param name="b">The other rect.</param> + /// <returns>The merged rect.</returns> public Rect2 Merge(Rect2 b) { Rect2 newRect; @@ -179,27 +308,53 @@ namespace Godot 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 + newRect._size -= newRect._position; // Make relative again return newRect; } - // Constructors + /// <summary> + /// Constructs a Rect2 from a position and size. + /// </summary> + /// <param name="position">The position.</param> + /// <param name="size">The size.</param> public Rect2(Vector2 position, Vector2 size) { _position = position; _size = size; } + + /// <summary> + /// Constructs a Rect2 from a position, width, and height. + /// </summary> + /// <param name="position">The position.</param> + /// <param name="width">The width.</param> + /// <param name="height">The height.</param> public Rect2(Vector2 position, real_t width, real_t height) { _position = position; _size = new Vector2(width, height); } + + /// <summary> + /// Constructs a Rect2 from x, y, and size. + /// </summary> + /// <param name="x">The position's X coordinate.</param> + /// <param name="y">The position's Y coordinate.</param> + /// <param name="size">The size.</param> public Rect2(real_t x, real_t y, Vector2 size) { _position = new Vector2(x, y); _size = size; } + + /// <summary> + /// Constructs a Rect2 from x, y, width, and height. + /// </summary> + /// <param name="x">The position's X coordinate.</param> + /// <param name="y">The position's Y coordinate.</param> + /// <param name="width">The width.</param> + /// <param name="height">The height.</param> public Rect2(real_t x, real_t y, real_t width, real_t height) { _position = new Vector2(x, y); @@ -231,6 +386,12 @@ namespace Godot return _position.Equals(other._position) && _size.Equals(other._size); } + /// <summary> + /// Returns true if this rect and `other` are approximately equal, by running + /// <see cref="Vector2.IsEqualApprox(Vector2)"/> on each component. + /// </summary> + /// <param name="other">The other rect to compare.</param> + /// <returns>Whether or not the rects are approximately equal.</returns> public bool IsEqualApprox(Rect2 other) { return _position.IsEqualApprox(other._position) && _size.IsEqualApprox(other.Size); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs index c0b236c524..8f71c00d76 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Rect2i.cs @@ -3,6 +3,10 @@ using System.Runtime.InteropServices; namespace Godot { + /// <summary> + /// 2D axis-aligned bounding box using integers. Rect2i consists of a position, a size, and + /// several utility functions. It is typically used for fast overlap tests. + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Rect2i : IEquatable<Rect2i> @@ -10,29 +14,52 @@ namespace Godot private Vector2i _position; private Vector2i _size; + /// <summary> + /// Beginning corner. Typically has values lower than End. + /// </summary> + /// <value>Directly uses a private field.</value> public Vector2i Position { get { return _position; } set { _position = value; } } + /// <summary> + /// Size from Position to End. Typically all components are positive. + /// If the size is negative, you can use <see cref="Abs"/> to fix it. + /// </summary> + /// <value>Directly uses a private field.</value> public Vector2i Size { get { return _size; } set { _size = value; } } + /// <summary> + /// Ending corner. This is calculated as <see cref="Position"/> plus + /// <see cref="Size"/>. Setting this value will change the size. + /// </summary> + /// <value>Getting is equivalent to `value = Position + Size`, setting is equivalent to `Size = value - Position`.</value> public Vector2i End { get { return _position + _size; } set { _size = value - _position; } } + /// <summary> + /// The area of this rect. + /// </summary> + /// <value>Equivalent to <see cref="GetArea()"/>.</value> public int Area { get { return GetArea(); } } + /// <summary> + /// Returns a Rect2i with equivalent position and size, modified so that + /// the top-left corner is the origin and width and height are positive. + /// </summary> + /// <returns>The modified rect.</returns> public Rect2i Abs() { Vector2i end = End; @@ -40,12 +67,19 @@ namespace Godot return new Rect2i(topLeft, _size.Abs()); } + /// <summary> + /// Returns the intersection of this Rect2i and `b`. + /// </summary> + /// <param name="b">The other rect.</param> + /// <returns>The clipped rect.</returns> public Rect2i Clip(Rect2i b) { var newRect = b; if (!Intersects(newRect)) + { return new Rect2i(); + } newRect._position.x = Mathf.Max(b._position.x, _position.x); newRect._position.y = Mathf.Max(b._position.y, _position.y); @@ -59,6 +93,11 @@ namespace Godot return newRect; } + /// <summary> + /// Returns true if this Rect2i completely encloses another one. + /// </summary> + /// <param name="b">The other rect that may be enclosed.</param> + /// <returns>A bool for whether or not this rect encloses `b`.</returns> public bool Encloses(Rect2i b) { return b._position.x >= _position.x && b._position.y >= _position.y && @@ -66,6 +105,11 @@ namespace Godot b._position.y + b._size.y < _position.y + _size.y; } + /// <summary> + /// Returns this Rect2i expanded to include a given point. + /// </summary> + /// <param name="to">The point to include.</param> + /// <returns>The expanded rect.</returns> public Rect2i Expand(Vector2i to) { var expanded = this; @@ -74,14 +118,22 @@ namespace Godot Vector2i end = expanded._position + expanded._size; if (to.x < begin.x) + { begin.x = to.x; + } if (to.y < begin.y) + { begin.y = to.y; + } if (to.x > end.x) + { end.x = to.x; + } if (to.y > end.y) + { end.y = to.y; + } expanded._position = begin; expanded._size = end - begin; @@ -89,11 +141,20 @@ namespace Godot return expanded; } + /// <summary> + /// Returns the area of the Rect2. + /// </summary> + /// <returns>The area.</returns> public int GetArea() { return _size.x * _size.y; } + /// <summary> + /// Returns a copy of the Rect2i grown a given amount of units towards all the sides. + /// </summary> + /// <param name="by">The amount to grow by.</param> + /// <returns>The grown rect.</returns> public Rect2i Grow(int by) { var g = this; @@ -106,6 +167,14 @@ namespace Godot return g; } + /// <summary> + /// Returns a copy of the Rect2i grown a given amount of units towards each direction individually. + /// </summary> + /// <param name="left">The amount to grow by on the left.</param> + /// <param name="top">The amount to grow by on the top.</param> + /// <param name="right">The amount to grow by on the right.</param> + /// <param name="bottom">The amount to grow by on the bottom.</param> + /// <returns>The grown rect.</returns> public Rect2i GrowIndividual(int left, int top, int right, int bottom) { var g = this; @@ -118,6 +187,12 @@ namespace Godot return g; } + /// <summary> + /// Returns a copy of the Rect2i grown a given amount of units towards the <see cref="Margin"/> direction. + /// </summary> + /// <param name="margin">The direction to grow in.</param> + /// <param name="by">The amount to grow by.</param> + /// <returns>The grown rect.</returns> public Rect2i GrowMargin(Margin margin, int by) { var g = this; @@ -130,11 +205,20 @@ namespace Godot return g; } + /// <summary> + /// Returns true if the Rect2 is flat or empty, or false otherwise. + /// </summary> + /// <returns>A bool for whether or not the rect has area.</returns> public bool HasNoArea() { return _size.x <= 0 || _size.y <= 0; } + /// <summary> + /// Returns true if the Rect2 contains a point, or false otherwise. + /// </summary> + /// <param name="point">The point to check.</param> + /// <returns>A bool for whether or not the rect contains `point`.</returns> public bool HasPoint(Vector2i point) { if (point.x < _position.x) @@ -150,20 +234,49 @@ namespace Godot return true; } - public bool Intersects(Rect2i b) + /// <summary> + /// Returns true if the Rect2i overlaps with `b` + /// (i.e. they have at least one point in common). + /// + /// If `includeBorders` is true, they will also be considered overlapping + /// if their borders touch, even without intersection. + /// </summary> + /// <param name="b">The other rect to check for intersections with.</param> + /// <param name="includeBorders">Whether or not to consider borders.</param> + /// <returns>A bool for whether or not they are intersecting.</returns> + public bool Intersects(Rect2i b, bool includeBorders = false) { - if (_position.x >= b._position.x + b._size.x) - return false; - if (_position.x + _size.x <= b._position.x) - return false; - if (_position.y >= b._position.y + b._size.y) - return false; - if (_position.y + _size.y <= b._position.y) - return false; + if (includeBorders) + { + if (_position.x > b._position.x + b._size.x) + return false; + if (_position.x + _size.x < b._position.x) + return false; + if (_position.y > b._position.y + b._size.y) + return false; + if (_position.y + _size.y < b._position.y) + return false; + } + else + { + if (_position.x >= b._position.x + b._size.x) + return false; + if (_position.x + _size.x <= b._position.x) + return false; + if (_position.y >= b._position.y + b._size.y) + return false; + if (_position.y + _size.y <= b._position.y) + return false; + } return true; } + /// <summary> + /// Returns a larger Rect2i that contains this Rect2 and `b`. + /// </summary> + /// <param name="b">The other rect.</param> + /// <returns>The merged rect.</returns> public Rect2i Merge(Rect2i b) { Rect2i newRect; @@ -174,27 +287,53 @@ namespace Godot 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 + newRect._size -= newRect._position; // Make relative again return newRect; } - // Constructors + /// <summary> + /// Constructs a Rect2i from a position and size. + /// </summary> + /// <param name="position">The position.</param> + /// <param name="size">The size.</param> public Rect2i(Vector2i position, Vector2i size) { _position = position; _size = size; } + + /// <summary> + /// Constructs a Rect2i from a position, width, and height. + /// </summary> + /// <param name="position">The position.</param> + /// <param name="width">The width.</param> + /// <param name="height">The height.</param> public Rect2i(Vector2i position, int width, int height) { _position = position; _size = new Vector2i(width, height); } + + /// <summary> + /// Constructs a Rect2i from x, y, and size. + /// </summary> + /// <param name="x">The position's X coordinate.</param> + /// <param name="y">The position's Y coordinate.</param> + /// <param name="size">The size.</param> public Rect2i(int x, int y, Vector2i size) { _position = new Vector2i(x, y); _size = size; } + + /// <summary> + /// Constructs a Rect2i from x, y, width, and height. + /// </summary> + /// <param name="x">The position's X coordinate.</param> + /// <param name="y">The position's Y coordinate.</param> + /// <param name="width">The width.</param> + /// <param name="height">The height.</param> public Rect2i(int x, int y, int width, int height) { _position = new Vector2i(x, y); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs index 6a58b90561..98d4b92bd1 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform.cs @@ -8,11 +8,28 @@ using real_t = System.Single; namespace Godot { + /// <summary> + /// 3×4 matrix (3 rows, 4 columns) used for 3D linear transformations. + /// It can represent transformations such as translation, rotation, or scaling. + /// It consists of a <see cref="Basis"/> (first 3 columns) and a + /// <see cref="Vector3"/> for the origin (last column). + /// + /// For more information, read this documentation article: + /// https://docs.godotengine.org/en/latest/tutorials/math/matrices_and_transforms.html + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Transform : IEquatable<Transform> { + /// <summary> + /// The <see cref="Basis"/> of this transform. Contains the X, Y, and Z basis + /// vectors (columns 0 to 2) and is responsible for rotation and scale. + /// </summary> public Basis basis; + + /// <summary> + /// The origin vector (column 3, the fourth column). Equivalent to array index `[3]`. + /// </summary> public Vector3 origin; /// <summary> @@ -85,13 +102,24 @@ namespace Godot } } + /// <summary> + /// Returns the inverse of the transform, under the assumption that + /// the transformation is composed of rotation, scaling, and translation. + /// </summary> + /// <returns>The inverse transformation matrix.</returns> public Transform AffineInverse() { Basis basisInv = basis.Inverse(); return new Transform(basisInv, basisInv.Xform(-origin)); } - public Transform InterpolateWith(Transform transform, real_t c) + /// <summary> + /// Interpolates this transform to the other `transform` by `weight`. + /// </summary> + /// <param name="transform">The other transform.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The interpolated transform.</returns> + public Transform InterpolateWith(Transform transform, real_t weight) { /* not sure if very "efficient" but good enough? */ @@ -104,18 +132,37 @@ namespace Godot Vector3 destinationLocation = transform.origin; var interpolated = new Transform(); - interpolated.basis.SetQuatScale(sourceRotation.Slerp(destinationRotation, c).Normalized(), sourceScale.Lerp(destinationScale, c)); - interpolated.origin = sourceLocation.Lerp(destinationLocation, c); + interpolated.basis.SetQuatScale(sourceRotation.Slerp(destinationRotation, weight).Normalized(), sourceScale.Lerp(destinationScale, weight)); + interpolated.origin = sourceLocation.Lerp(destinationLocation, weight); return interpolated; } + /// <summary> + /// Returns the inverse of the transform, under the assumption that + /// the transformation is composed of rotation and translation + /// (no scaling, use <see cref="AffineInverse"/> for transforms with scaling). + /// </summary> + /// <returns>The inverse matrix.</returns> public Transform Inverse() { Basis basisTr = basis.Transposed(); return new Transform(basisTr, basisTr.Xform(-origin)); } + /// <summary> + /// Returns a copy of the transform rotated such that its + /// -Z axis (forward) points towards the target position. + /// + /// The transform will first be rotated around the given up vector, + /// and then fully aligned to the target by a further rotation around + /// an axis perpendicular to both the target and up vectors. + /// + /// Operations take place in global space. + /// </summary> + /// <param name="target">The object to look at.</param> + /// <param name="up">The relative up direction</param> + /// <returns>The resulting transform.</returns> public Transform LookingAt(Vector3 target, Vector3 up) { var t = this; @@ -123,22 +170,39 @@ namespace Godot return t; } + /// <summary> + /// Returns the transform with the basis orthogonal (90 degrees), + /// and normalized axis vectors (scale of 1 or -1). + /// </summary> + /// <returns>The orthonormalized transform.</returns> public Transform Orthonormalized() { return new Transform(basis.Orthonormalized(), origin); } + /// <summary> + /// Rotates the transform around the given `axis` by `phi` (in radians), + /// using matrix multiplication. The axis must be a normalized vector. + /// </summary> + /// <param name="axis">The axis to rotate around. Must be normalized.</param> + /// <param name="phi">The angle to rotate, in radians.</param> + /// <returns>The rotated transformation matrix.</returns> public Transform Rotated(Vector3 axis, real_t phi) { return new Transform(new Basis(axis, phi), new Vector3()) * this; } + /// <summary> + /// Scales the transform by the given 3D scaling factor, using matrix multiplication. + /// </summary> + /// <param name="scale">The scale to introduce.</param> + /// <returns>The scaled transformation matrix.</returns> public Transform Scaled(Vector3 scale) { return new Transform(basis.Scaled(scale), origin * scale); } - public void SetLookAt(Vector3 eye, Vector3 target, Vector3 up) + private void SetLookAt(Vector3 eye, Vector3 target, Vector3 up) { // Make rotation matrix // Z vector @@ -161,16 +225,30 @@ namespace Godot origin = eye; } - public Transform Translated(Vector3 ofs) + /// <summary> + /// Translates the transform by the given `offset`, + /// relative to the transform's basis vectors. + /// + /// Unlike <see cref="Rotated"/> and <see cref="Scaled"/>, + /// this does not use matrix multiplication. + /// </summary> + /// <param name="offset">The offset to translate by.</param> + /// <returns>The translated matrix.</returns> + public Transform Translated(Vector3 offset) { return new Transform(basis, new Vector3 ( - origin[0] += basis.Row0.Dot(ofs), - origin[1] += basis.Row1.Dot(ofs), - origin[2] += basis.Row2.Dot(ofs) + origin[0] += basis.Row0.Dot(offset), + origin[1] += basis.Row1.Dot(offset), + origin[2] += basis.Row2.Dot(offset) )); } + /// <summary> + /// Returns a vector transformed (multiplied) by this transformation matrix. + /// </summary> + /// <param name="v">A vector to transform.</param> + /// <returns>The transfomed vector.</returns> public Vector3 Xform(Vector3 v) { return new Vector3 @@ -181,6 +259,14 @@ namespace Godot ); } + /// <summary> + /// Returns a vector transformed (multiplied) by the transposed transformation matrix. + /// + /// Note: This results in a multiplication by the inverse of the + /// transformation matrix only if it represents a rotation-reflection. + /// </summary> + /// <param name="v">A vector to inversely transform.</param> + /// <returns>The inversely transfomed vector.</returns> public Vector3 XformInv(Vector3 v) { Vector3 vInv = v - origin; @@ -199,24 +285,58 @@ namespace Godot private static readonly Transform _flipY = new Transform(new Basis(1, 0, 0, 0, -1, 0, 0, 0, 1), Vector3.Zero); private static readonly Transform _flipZ = new Transform(new Basis(1, 0, 0, 0, 1, 0, 0, 0, -1), Vector3.Zero); + /// <summary> + /// The identity transform, with no translation, rotation, or scaling applied. + /// This is used as a replacement for `Transform()` in GDScript. + /// Do not use `new Transform()` with no arguments in C#, because it sets all values to zero. + /// </summary> + /// <value>Equivalent to `new Transform(Vector3.Right, Vector3.Up, Vector3.Back, Vector3.Zero)`.</value> public static Transform Identity { get { return _identity; } } + /// <summary> + /// The transform that will flip something along the X axis. + /// </summary> + /// <value>Equivalent to `new Transform(Vector3.Left, Vector3.Up, Vector3.Back, Vector3.Zero)`.</value> public static Transform FlipX { get { return _flipX; } } + /// <summary> + /// The transform that will flip something along the Y axis. + /// </summary> + /// <value>Equivalent to `new Transform(Vector3.Right, Vector3.Down, Vector3.Back, Vector3.Zero)`.</value> public static Transform FlipY { get { return _flipY; } } + /// <summary> + /// The transform that will flip something along the Z axis. + /// </summary> + /// <value>Equivalent to `new Transform(Vector3.Right, Vector3.Up, Vector3.Forward, Vector3.Zero)`.</value> public static Transform FlipZ { get { return _flipZ; } } - // Constructors + /// <summary> + /// Constructs a transformation matrix from 4 vectors (matrix columns). + /// </summary> + /// <param name="column0">The X vector, or column index 0.</param> + /// <param name="column1">The Y vector, or column index 1.</param> + /// <param name="column2">The Z vector, or column index 2.</param> + /// <param name="origin">The origin vector, or column index 3.</param> public Transform(Vector3 column0, Vector3 column1, Vector3 column2, Vector3 origin) { basis = new Basis(column0, column1, column2); this.origin = origin; } + /// <summary> + /// Constructs a transformation matrix from the given quaternion and origin vector. + /// </summary> + /// <param name="quat">The <see cref="Godot.Quat"/> to create the basis from.</param> + /// <param name="origin">The origin vector, or column index 3.</param> public Transform(Quat quat, Vector3 origin) { basis = new Basis(quat); this.origin = origin; } + /// <summary> + /// Constructs a transformation matrix from the given basis and origin vector. + /// </summary> + /// <param name="basis">The <see cref="Godot.Basis"/> to create the basis from.</param> + /// <param name="origin">The origin vector, or column index 3.</param> public Transform(Basis basis, Vector3 origin) { this.basis = basis; @@ -255,6 +375,12 @@ namespace Godot return basis.Equals(other.basis) && origin.Equals(other.origin); } + /// <summary> + /// Returns true if this transform and `other` are approximately equal, by running + /// <see cref="Vector3.IsEqualApprox(Vector3)"/> on each component. + /// </summary> + /// <param name="other">The other transform to compare.</param> + /// <returns>Whether or not the matrices are approximately equal.</returns> public bool IsEqualApprox(Transform other) { return basis.IsEqualApprox(other.basis) && origin.IsEqualApprox(other.origin); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs index 3ae96d4922..9f9ae50c59 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform2D.cs @@ -8,25 +8,44 @@ using real_t = System.Single; namespace Godot { + /// <summary> + /// 2×3 matrix (2 rows, 3 columns) used for 2D linear transformations. + /// It can represent transformations such as translation, rotation, or scaling. + /// It consists of a three <see cref="Vector2"/> values: x, y, and the origin. + /// + /// For more information, read this documentation article: + /// https://docs.godotengine.org/en/latest/tutorials/math/matrices_and_transforms.html + /// </summary> [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Transform2D : IEquatable<Transform2D> { + /// <summary> + /// The basis matrix's X vector (column 0). Equivalent to array index `[0]`. + /// </summary> + /// <value></value> public Vector2 x; + + /// <summary> + /// The basis matrix's Y vector (column 1). Equivalent to array index `[1]`. + /// </summary> public Vector2 y; + + /// <summary> + /// The origin vector (column 2, the third column). Equivalent to array index `[2]`. + /// The origin vector represents translation. + /// </summary> public Vector2 origin; + /// <summary> + /// The rotation of this transformation matrix. + /// </summary> + /// <value>Getting is equivalent to calling <see cref="Mathf.Atan2(real_t, real_t)"/> with the values of <see cref="x"/>.</value> public real_t Rotation { get { - real_t det = BasisDeterminant(); - Transform2D t = Orthonormalized(); - if (det < 0) - { - t.ScaleBasis(new Vector2(1, -1)); - } - return Mathf.Atan2(t.x.y, t.x.x); + return Mathf.Atan2(x.y, x.x); } set { @@ -38,6 +57,10 @@ namespace Godot } } + /// <summary> + /// The scale of this transformation matrix. + /// </summary> + /// <value>Equivalent to the lengths of each column vector, but Y is negative if the determinant is negative.</value> public Vector2 Scale { get @@ -47,8 +70,7 @@ namespace Godot } set { - x = x.Normalized(); - y = y.Normalized(); + value /= Scale; // Value becomes what's called "delta_scale" in core. x *= value.x; y *= value.y; } @@ -112,6 +134,11 @@ namespace Godot } } + /// <summary> + /// Returns the inverse of the transform, under the assumption that + /// the transformation is composed of rotation, scaling, and translation. + /// </summary> + /// <returns>The inverse transformation matrix.</returns> public Transform2D AffineInverse() { real_t det = BasisDeterminant(); @@ -135,28 +162,58 @@ namespace Godot return inv; } + /// <summary> + /// Returns the determinant of the basis matrix. If the basis is + /// uniformly scaled, its determinant is the square of the scale. + /// + /// A negative determinant means the Y scale is negative. + /// A zero determinant means the basis isn't invertible, + /// and is usually considered invalid. + /// </summary> + /// <returns>The determinant of the basis matrix.</returns> private real_t BasisDeterminant() { return x.x * y.y - x.y * y.x; } + /// <summary> + /// Returns a vector transformed (multiplied) by the basis matrix. + /// This method does not account for translation (the origin vector). + /// </summary> + /// <param name="v">A vector to transform.</param> + /// <returns>The transfomed vector.</returns> public Vector2 BasisXform(Vector2 v) { return new Vector2(Tdotx(v), Tdoty(v)); } + /// <summary> + /// Returns a vector transformed (multiplied) by the inverse basis matrix. + /// This method does not account for translation (the origin vector). + /// + /// Note: This results in a multiplication by the inverse of the + /// basis matrix only if it represents a rotation-reflection. + /// </summary> + /// <param name="v">A vector to inversely transform.</param> + /// <returns>The inversely transfomed vector.</returns> public Vector2 BasisXformInv(Vector2 v) { return new Vector2(x.Dot(v), y.Dot(v)); } - public Transform2D InterpolateWith(Transform2D m, real_t c) + /// <summary> + /// Interpolates this transform to the other `transform` by `weight`. + /// </summary> + /// <param name="transform">The other transform.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The interpolated transform.</returns> + public Transform2D InterpolateWith(Transform2D transform, real_t weight) { real_t r1 = Rotation; - real_t r2 = m.Rotation; + real_t r2 = transform.Rotation; Vector2 s1 = Scale; - Vector2 s2 = m.Scale; + Vector2 s2 = transform.Scale; // Slerp rotation var v1 = new Vector2(Mathf.Cos(r1), Mathf.Sin(r1)); @@ -172,28 +229,34 @@ namespace Godot if (dot > 0.9995f) { // Linearly interpolate to avoid numerical precision issues - v = v1.Lerp(v2, c).Normalized(); + v = v1.Lerp(v2, weight).Normalized(); } else { - real_t angle = c * Mathf.Acos(dot); + real_t angle = weight * Mathf.Acos(dot); Vector2 v3 = (v2 - v1 * dot).Normalized(); v = v1 * Mathf.Cos(angle) + v3 * Mathf.Sin(angle); } // Extract parameters Vector2 p1 = origin; - Vector2 p2 = m.origin; + Vector2 p2 = transform.origin; // Construct matrix - var res = new Transform2D(Mathf.Atan2(v.y, v.x), p1.Lerp(p2, c)); - Vector2 scale = s1.Lerp(s2, c); + var res = new Transform2D(Mathf.Atan2(v.y, v.x), p1.Lerp(p2, weight)); + Vector2 scale = s1.Lerp(s2, weight); res.x *= scale; res.y *= scale; return res; } + /// <summary> + /// Returns the inverse of the transform, under the assumption that + /// the transformation is composed of rotation and translation + /// (no scaling, use <see cref="AffineInverse"/> for transforms with scaling). + /// </summary> + /// <returns>The inverse matrix.</returns> public Transform2D Inverse() { var inv = this; @@ -208,6 +271,11 @@ namespace Godot return inv; } + /// <summary> + /// Returns the transform with the basis orthogonal (90 degrees), + /// and normalized axis vectors (scale of 1 or -1). + /// </summary> + /// <returns>The orthonormalized transform.</returns> public Transform2D Orthonormalized() { var on = this; @@ -225,11 +293,21 @@ namespace Godot return on; } + /// <summary> + /// Rotates the transform by `phi` (in radians), using matrix multiplication. + /// </summary> + /// <param name="phi">The angle to rotate, in radians.</param> + /// <returns>The rotated transformation matrix.</returns> public Transform2D Rotated(real_t phi) { return this * new Transform2D(phi, new Vector2()); } + /// <summary> + /// Scales the transform by the given scaling factor, using matrix multiplication. + /// </summary> + /// <param name="scale">The scale to introduce.</param> + /// <returns>The scaled transformation matrix.</returns> public Transform2D Scaled(Vector2 scale) { var copy = this; @@ -257,6 +335,15 @@ namespace Godot return this[0, 1] * with[0] + this[1, 1] * with[1]; } + /// <summary> + /// Translates the transform by the given `offset`, + /// relative to the transform's basis vectors. + /// + /// Unlike <see cref="Rotated"/> and <see cref="Scaled"/>, + /// this does not use matrix multiplication. + /// </summary> + /// <param name="offset">The offset to translate by.</param> + /// <returns>The translated matrix.</returns> public Transform2D Translated(Vector2 offset) { var copy = this; @@ -264,11 +351,21 @@ namespace Godot return copy; } + /// <summary> + /// Returns a vector transformed (multiplied) by this transformation matrix. + /// </summary> + /// <param name="v">A vector to transform.</param> + /// <returns>The transfomed vector.</returns> public Vector2 Xform(Vector2 v) { return new Vector2(Tdotx(v), Tdoty(v)) + origin; } + /// <summary> + /// Returns a vector transformed (multiplied) by the inverse transformation matrix. + /// </summary> + /// <param name="v">A vector to inversely transform.</param> + /// <returns>The inversely transfomed vector.</returns> public Vector2 XformInv(Vector2 v) { Vector2 vInv = v - origin; @@ -280,11 +377,30 @@ namespace Godot private static readonly Transform2D _flipX = new Transform2D(-1, 0, 0, 1, 0, 0); private static readonly Transform2D _flipY = new Transform2D(1, 0, 0, -1, 0, 0); - public static Transform2D Identity => _identity; - public static Transform2D FlipX => _flipX; - public static Transform2D FlipY => _flipY; + /// <summary> + /// The identity transform, with no translation, rotation, or scaling applied. + /// This is used as a replacement for `Transform2D()` in GDScript. + /// Do not use `new Transform2D()` with no arguments in C#, because it sets all values to zero. + /// </summary> + /// <value>Equivalent to `new Transform2D(Vector2.Right, Vector2.Down, Vector2.Zero)`.</value> + public static Transform2D Identity { get { return _identity; } } + /// <summary> + /// The transform that will flip something along the X axis. + /// </summary> + /// <value>Equivalent to `new Transform2D(Vector2.Left, Vector2.Down, Vector2.Zero)`.</value> + public static Transform2D FlipX { get { return _flipX; } } + /// <summary> + /// The transform that will flip something along the Y axis. + /// </summary> + /// <value>Equivalent to `new Transform2D(Vector2.Right, Vector2.Up, Vector2.Zero)`.</value> + public static Transform2D FlipY { get { return _flipY; } } - // Constructors + /// <summary> + /// Constructs a transformation matrix from 3 vectors (matrix columns). + /// </summary> + /// <param name="xAxis">The X vector, or column index 0.</param> + /// <param name="yAxis">The Y vector, or column index 1.</param> + /// <param name="originPos">The origin vector, or column index 2.</param> public Transform2D(Vector2 xAxis, Vector2 yAxis, Vector2 originPos) { x = xAxis; @@ -292,7 +408,16 @@ namespace Godot origin = originPos; } - // Arguments are named such that xy is equal to calling x.y + /// <summary> + /// Constructs a transformation matrix from the given components. + /// Arguments are named such that xy is equal to calling x.y + /// </summary> + /// <param name="xx">The X component of the X column vector, accessed via `t.x.x` or `[0][0]`</param> + /// <param name="xy">The Y component of the X column vector, accessed via `t.x.y` or `[0][1]`</param> + /// <param name="yx">The X component of the Y column vector, accessed via `t.y.x` or `[1][0]`</param> + /// <param name="yy">The Y component of the Y column vector, accessed via `t.y.y` or `[1][1]`</param> + /// <param name="ox">The X component of the origin vector, accessed via `t.origin.x` or `[2][0]`</param> + /// <param name="oy">The Y component of the origin vector, accessed via `t.origin.y` or `[2][1]`</param> public Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { x = new Vector2(xx, xy); @@ -300,6 +425,11 @@ namespace Godot origin = new Vector2(ox, oy); } + /// <summary> + /// Constructs a transformation matrix from a rotation value and origin vector. + /// </summary> + /// <param name="rot">The rotation of the new transform, in radians.</param> + /// <param name="pos">The origin vector, or column index 2.</param> public Transform2D(real_t rot, Vector2 pos) { x.x = y.y = Mathf.Cos(rot); @@ -345,6 +475,12 @@ namespace Godot return x.Equals(other.x) && y.Equals(other.y) && origin.Equals(other.origin); } + /// <summary> + /// Returns true if this transform and `other` are approximately equal, by running + /// <see cref="Vector2.IsEqualApprox(Vector2)"/> on each component. + /// </summary> + /// <param name="other">The other transform to compare.</param> + /// <returns>Whether or not the matrices are approximately equal.</returns> public bool IsEqualApprox(Transform2D other) { return x.IsEqualApprox(other.x) && y.IsEqualApprox(other.y) && origin.IsEqualApprox(other.origin); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs index 7e4804f9fd..26bd828a5b 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2.cs @@ -21,15 +21,29 @@ namespace Godot [StructLayout(LayoutKind.Sequential)] public struct Vector2 : IEquatable<Vector2> { + /// <summary> + /// Enumerated index values for the axes. + /// Returned by <see cref="MaxAxis"/> and <see cref="MinAxis"/>. + /// </summary> public enum Axis { X = 0, Y } + /// <summary> + /// The vector's X component. Also accessible by using the index position `[0]`. + /// </summary> public real_t x; + /// <summary> + /// The vector's Y component. Also accessible by using the index position `[1]`. + /// </summary> public real_t y; + /// <summary> + /// Access vector components using their index. + /// </summary> + /// <value>`[0]` is equivalent to `.x`, `[1]` is equivalent to `.y`.</value> public real_t this[int index] { get @@ -76,41 +90,80 @@ namespace Godot } } + /// <summary> + /// Returns a new vector with all components in absolute values (i.e. positive). + /// </summary> + /// <returns>A vector with <see cref="Mathf.Abs(real_t)"/> called on each component.</returns> public Vector2 Abs() { return new Vector2(Mathf.Abs(x), Mathf.Abs(y)); } + /// <summary> + /// Returns this vector's angle with respect to the X axis, or (1, 0) vector, in radians. + /// + /// Equivalent to the result of <see cref="Mathf.Atan2(real_t, real_t)"/> when + /// called with the vector's `y` and `x` as parameters: `Mathf.Atan2(v.y, v.x)`. + /// </summary> + /// <returns>The angle of this vector, in radians.</returns> public real_t Angle() { return Mathf.Atan2(y, x); } + /// <summary> + /// Returns the angle to the given vector, in radians. + /// </summary> + /// <param name="to">The other vector to compare this vector to.</param> + /// <returns>The angle between the two vectors, in radians.</returns> public real_t AngleTo(Vector2 to) { return Mathf.Atan2(Cross(to), Dot(to)); } + /// <summary> + /// Returns the angle between the line connecting the two points and the X axis, in radians. + /// </summary> + /// <param name="to">The other vector to compare this vector to.</param> + /// <returns>The angle between the two vectors, in radians.</returns> public real_t AngleToPoint(Vector2 to) { return Mathf.Atan2(y - to.y, x - to.x); } + /// <summary> + /// Returns the aspect ratio of this vector, the ratio of `x` to `y`. + /// </summary> + /// <returns>The `x` component divided by the `y` component.</returns> public real_t Aspect() { return x / y; } - public Vector2 Bounce(Vector2 n) + /// <summary> + /// Returns the vector "bounced off" from a plane defined by the given normal. + /// </summary> + /// <param name="normal">The normal vector defining the plane to bounce off. Must be normalized.</param> + /// <returns>The bounced vector.</returns> + public Vector2 Bounce(Vector2 normal) { - return -Reflect(n); + return -Reflect(normal); } + /// <summary> + /// Returns a new vector with all components rounded up (towards positive infinity). + /// </summary> + /// <returns>A vector with <see cref="Mathf.Ceil"/> called on each component.</returns> public Vector2 Ceil() { return new Vector2(Mathf.Ceil(x), Mathf.Ceil(y)); } + /// <summary> + /// Returns the vector with a maximum length by limiting its length to `length`. + /// </summary> + /// <param name="length">The length to limit to.</param> + /// <returns>The vector with its length limited.</returns> public Vector2 Clamped(real_t length) { var v = this; @@ -125,17 +178,30 @@ namespace Godot return v; } + /// <summary> + /// Returns the cross product of this vector and `b`. + /// </summary> + /// <param name="b">The other vector.</param> + /// <returns>The cross product value.</returns> public real_t Cross(Vector2 b) { return x * b.y - y * b.x; } + /// <summary> + /// Performs a cubic interpolation between vectors `preA`, this vector, `b`, and `postB`, by the given amount `t`. + /// </summary> + /// <param name="b">The destination vector.</param> + /// <param name="preA">A vector before this vector.</param> + /// <param name="postB">A vector after `b`.</param> + /// <param name="t">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The interpolated vector.</returns> public Vector2 CubicInterpolate(Vector2 b, Vector2 preA, Vector2 postB, real_t t) { - var p0 = preA; - var p1 = this; - var p2 = b; - var p3 = postB; + Vector2 p0 = preA; + Vector2 p1 = this; + Vector2 p2 = b; + Vector2 p3 = postB; real_t t2 = t * t; real_t t3 = t2 * t; @@ -146,46 +212,102 @@ namespace Godot (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t3); } + /// <summary> + /// Returns the normalized vector pointing from this vector to `b`. + /// </summary> + /// <param name="b">The other vector to point towards.</param> + /// <returns>The direction from this vector to `b`.</returns> public Vector2 DirectionTo(Vector2 b) { return new Vector2(b.x - x, b.y - y).Normalized(); } + /// <summary> + /// Returns the squared distance between this vector and `to`. + /// This method runs faster than <see cref="DistanceTo"/>, so prefer it if + /// you need to compare vectors or need the squared distance for some formula. + /// </summary> + /// <param name="to">The other vector to use.</param> + /// <returns>The squared distance between the two vectors.</returns> public real_t DistanceSquaredTo(Vector2 to) { return (x - to.x) * (x - to.x) + (y - to.y) * (y - to.y); } + /// <summary> + /// Returns the distance between this vector and `to`. + /// </summary> + /// <param name="to">The other vector to use.</param> + /// <returns>The distance between the two vectors.</returns> public real_t DistanceTo(Vector2 to) { return Mathf.Sqrt((x - to.x) * (x - to.x) + (y - to.y) * (y - to.y)); } + /// <summary> + /// Returns the dot product of this vector and `with`. + /// </summary> + /// <param name="with">The other vector to use.</param> + /// <returns>The dot product of the two vectors.</returns> public real_t Dot(Vector2 with) { return x * with.x + y * with.y; } + /// <summary> + /// Returns a new vector with all components rounded down (towards negative infinity). + /// </summary> + /// <returns>A vector with <see cref="Mathf.Floor"/> called on each component.</returns> public Vector2 Floor() { return new Vector2(Mathf.Floor(x), Mathf.Floor(y)); } + /// <summary> + /// Returns the inverse of this vector. This is the same as `new Vector2(1 / v.x, 1 / v.y)`. + /// </summary> + /// <returns>The inverse of this vector.</returns> + public Vector2 Inverse() + { + return new Vector2(1 / x, 1 / y); + } + + /// <summary> + /// Returns true if the vector is normalized, and false otherwise. + /// </summary> + /// <returns>A bool indicating whether or not the vector is normalized.</returns> public bool IsNormalized() { return Mathf.Abs(LengthSquared() - 1.0f) < Mathf.Epsilon; } + /// <summary> + /// Returns the length (magnitude) of this vector. + /// </summary> + /// <returns>The length of this vector.</returns> public real_t Length() { return Mathf.Sqrt(x * x + y * y); } + /// <summary> + /// Returns the squared length (squared magnitude) of this vector. + /// This method runs faster than <see cref="Length"/>, so prefer it if + /// you need to compare vectors or need the squared length for some formula. + /// </summary> + /// <returns>The squared length of this vector.</returns> public real_t LengthSquared() { return x * x + y * y; } + /// <summary> + /// Returns the result of the linear interpolation between + /// this vector and `to` by amount `weight`. + /// </summary> + /// <param name="to">The destination vector for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting vector of the interpolation.</returns> public Vector2 Lerp(Vector2 to, real_t weight) { return new Vector2 @@ -195,6 +317,13 @@ namespace Godot ); } + /// <summary> + /// Returns the result of the linear interpolation between + /// this vector and `to` by the vector amount `weight`. + /// </summary> + /// <param name="to">The destination vector for interpolation.</param> + /// <param name="weight">A vector with components on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting vector of the interpolation.</returns> public Vector2 Lerp(Vector2 to, Vector2 weight) { return new Vector2 @@ -204,6 +333,32 @@ namespace Godot ); } + /// <summary> + /// Returns the axis of the vector's largest value. See <see cref="Axis"/>. + /// If both components are equal, this method returns <see cref="Axis.X"/>. + /// </summary> + /// <returns>The index of the largest axis.</returns> + public Axis MaxAxis() + { + return x < y ? Axis.Y : Axis.X; + } + + /// <summary> + /// Returns the axis of the vector's smallest value. See <see cref="Axis"/>. + /// If both components are equal, this method returns <see cref="Axis.Y"/>. + /// </summary> + /// <returns>The index of the smallest axis.</returns> + public Axis MinAxis() + { + return x < y ? Axis.X : Axis.Y; + } + + /// <summary> + /// Moves this vector toward `to` by the fixed `delta` amount. + /// </summary> + /// <param name="to">The vector to move towards.</param> + /// <param name="delta">The amount to move towards by.</param> + /// <returns>The resulting vector.</returns> public Vector2 MoveToward(Vector2 to, real_t delta) { var v = this; @@ -212,6 +367,10 @@ namespace Godot return len <= delta || len < Mathf.Epsilon ? to : v + vd / len * delta; } + /// <summary> + /// Returns the vector scaled to unit length. Equivalent to `v / v.Length()`. + /// </summary> + /// <returns>A normalized version of the vector.</returns> public Vector2 Normalized() { var v = this; @@ -219,6 +378,11 @@ namespace Godot return v; } + /// <summary> + /// Returns a vector composed of the <see cref="Mathf.PosMod(real_t, real_t)"/> of this vector's components and `mod`. + /// </summary> + /// <param name="mod">A value representing the divisor of the operation.</param> + /// <returns>A vector with each component <see cref="Mathf.PosMod(real_t, real_t)"/> by `mod`.</returns> public Vector2 PosMod(real_t mod) { Vector2 v; @@ -227,6 +391,11 @@ namespace Godot return v; } + /// <summary> + /// Returns a vector composed of the <see cref="Mathf.PosMod(real_t, real_t)"/> of this vector's components and `modv`'s components. + /// </summary> + /// <param name="modv">A vector representing the divisors of the operation.</param> + /// <returns>A vector with each component <see cref="Mathf.PosMod(real_t, real_t)"/> by `modv`'s components.</returns> public Vector2 PosMod(Vector2 modv) { Vector2 v; @@ -235,27 +404,59 @@ namespace Godot return v; } + /// <summary> + /// Returns this vector projected onto another vector `b`. + /// </summary> + /// <param name="onNormal">The vector to project onto.</param> + /// <returns>The projected vector.</returns> public Vector2 Project(Vector2 onNormal) { return onNormal * (Dot(onNormal) / onNormal.LengthSquared()); } - public Vector2 Reflect(Vector2 n) + /// <summary> + /// Returns this vector reflected from a plane defined by the given `normal`. + /// </summary> + /// <param name="normal">The normal vector defining the plane to reflect from. Must be normalized.</param> + /// <returns>The reflected vector.</returns> + public Vector2 Reflect(Vector2 normal) { - return 2 * Dot(n) * n - this; +#if DEBUG + if (!normal.IsNormalized()) + { + throw new ArgumentException("Argument is not normalized", nameof(normal)); + } +#endif + return 2 * Dot(normal) * normal - this; } + /// <summary> + /// Rotates this vector by `phi` radians. + /// </summary> + /// <param name="phi">The angle to rotate by, in radians.</param> + /// <returns>The rotated vector.</returns> public Vector2 Rotated(real_t phi) { real_t rads = Angle() + phi; return new Vector2(Mathf.Cos(rads), Mathf.Sin(rads)) * Length(); } + /// <summary> + /// Returns this vector with all components rounded to the nearest integer, + /// with halfway cases rounded towards the nearest multiple of two. + /// </summary> + /// <returns>The rounded vector.</returns> public Vector2 Round() { return new Vector2(Mathf.Round(x), Mathf.Round(y)); } + /// <summary> + /// Returns a vector with each component set to one or negative one, depending + /// on the signs of this vector's components, or zero if the component is zero, + /// by calling <see cref="Mathf.Sign(real_t)"/> on each component. + /// </summary> + /// <returns>A vector with all components as either `1`, `-1`, or `0`.</returns> public Vector2 Sign() { Vector2 v; @@ -264,23 +465,57 @@ namespace Godot return v; } - public Vector2 Slerp(Vector2 b, real_t t) + /// <summary> + /// Returns the result of the spherical linear interpolation between + /// this vector and `to` by amount `weight`. + /// + /// Note: Both vectors must be normalized. + /// </summary> + /// <param name="to">The destination vector for interpolation. Must be normalized.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting vector of the interpolation.</returns> + public Vector2 Slerp(Vector2 to, real_t weight) { - real_t theta = AngleTo(b); - return Rotated(theta * t); +#if DEBUG + if (!IsNormalized()) + { + throw new InvalidOperationException("Vector2.Slerp: From vector is not normalized."); + } + if (!to.IsNormalized()) + { + throw new InvalidOperationException("Vector2.Slerp: `to` is not normalized."); + } +#endif + return Rotated(AngleTo(to) * weight); } - public Vector2 Slide(Vector2 n) + /// <summary> + /// Returns this vector slid along a plane defined by the given normal. + /// </summary> + /// <param name="normal">The normal vector defining the plane to slide on.</param> + /// <returns>The slid vector.</returns> + public Vector2 Slide(Vector2 normal) { - return this - n * Dot(n); + return this - normal * Dot(normal); } - public Vector2 Snapped(Vector2 by) + /// <summary> + /// Returns this vector with each component snapped to the nearest multiple of `step`. + /// This can also be used to round to an arbitrary number of decimals. + /// </summary> + /// <param name="step">A vector value representing the step size to snap to.</param> + /// <returns>The snapped vector.</returns> + public Vector2 Snapped(Vector2 step) { - return new Vector2(Mathf.Stepify(x, by.x), Mathf.Stepify(y, by.y)); + return new Vector2(Mathf.Stepify(x, step.x), Mathf.Stepify(y, step.y)); } - public Vector2 Tangent() + /// <summary> + /// Returns a perpendicular vector rotated 90 degrees counter-clockwise + /// compared to the original, with the same length. + /// </summary> + /// <returns>The perpendicular vector.</returns> + public Vector2 Perpendicular() { return new Vector2(y, -x); } @@ -288,7 +523,6 @@ namespace Godot // Constants private static readonly Vector2 _zero = new Vector2(0, 0); private static readonly Vector2 _one = new Vector2(1, 1); - private static readonly Vector2 _negOne = new Vector2(-1, -1); private static readonly Vector2 _inf = new Vector2(Mathf.Inf, Mathf.Inf); private static readonly Vector2 _up = new Vector2(0, -1); @@ -296,22 +530,58 @@ namespace Godot private static readonly Vector2 _right = new Vector2(1, 0); private static readonly Vector2 _left = new Vector2(-1, 0); + /// <summary> + /// Zero vector, a vector with all components set to `0`. + /// </summary> + /// <value>Equivalent to `new Vector2(0, 0)`</value> public static Vector2 Zero { get { return _zero; } } - public static Vector2 NegOne { get { return _negOne; } } + /// <summary> + /// One vector, a vector with all components set to `1`. + /// </summary> + /// <value>Equivalent to `new Vector2(1, 1)`</value> public static Vector2 One { get { return _one; } } + /// <summary> + /// Infinity vector, a vector with all components set to `Mathf.Inf`. + /// </summary> + /// <value>Equivalent to `new Vector2(Mathf.Inf, Mathf.Inf)`</value> public static Vector2 Inf { get { return _inf; } } + /// <summary> + /// Up unit vector. Y is down in 2D, so this vector points -Y. + /// </summary> + /// <value>Equivalent to `new Vector2(0, -1)`</value> public static Vector2 Up { get { return _up; } } + /// <summary> + /// Down unit vector. Y is down in 2D, so this vector points +Y. + /// </summary> + /// <value>Equivalent to `new Vector2(0, 1)`</value> public static Vector2 Down { get { return _down; } } + /// <summary> + /// Right unit vector. Represents the direction of right. + /// </summary> + /// <value>Equivalent to `new Vector2(1, 0)`</value> public static Vector2 Right { get { return _right; } } + /// <summary> + /// Left unit vector. Represents the direction of left. + /// </summary> + /// <value>Equivalent to `new Vector2(-1, 0)`</value> public static Vector2 Left { get { return _left; } } - // Constructors + /// <summary> + /// Constructs a new <see cref="Vector2"/> with the given components. + /// </summary> + /// <param name="x">The vector's X component.</param> + /// <param name="y">The vector's Y component.</param> public Vector2(real_t x, real_t y) { this.x = x; this.y = y; } + + /// <summary> + /// Constructs a new <see cref="Vector2"/> from an existing <see cref="Vector2"/>. + /// </summary> + /// <param name="v">The existing <see cref="Vector2"/>.</param> public Vector2(Vector2 v) { x = v.x; @@ -453,6 +723,12 @@ namespace Godot return x == other.x && y == other.y; } + /// <summary> + /// Returns true if this vector and `other` are approximately equal, by running + /// <see cref="Mathf.IsEqualApprox(real_t, real_t)"/> on each component. + /// </summary> + /// <param name="other">The other vector to compare.</param> + /// <returns>Whether or not the vectors are approximately equal.</returns> public bool IsEqualApprox(Vector2 other) { return Mathf.IsEqualApprox(x, other.x) && Mathf.IsEqualApprox(y, other.y); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs index 7dc22d7918..8dd9ab2f0d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector2i.cs @@ -16,15 +16,29 @@ namespace Godot [StructLayout(LayoutKind.Sequential)] public struct Vector2i : IEquatable<Vector2i> { + /// <summary> + /// Enumerated index values for the axes. + /// Returned by <see cref="MaxAxis"/> and <see cref="MinAxis"/>. + /// </summary> public enum Axis { X = 0, Y } + /// <summary> + /// The vector's X component. Also accessible by using the index position `[0]`. + /// </summary> public int x; + /// <summary> + /// The vector's Y component. Also accessible by using the index position `[1]`. + /// </summary> public int y; + /// <summary> + /// Access vector components using their index. + /// </summary> + /// <value>`[0]` is equivalent to `.x`, `[1]` is equivalent to `.y`.</value> public int this[int index] { get @@ -55,56 +69,102 @@ namespace Godot } } + /// <summary> + /// Returns a new vector with all components in absolute values (i.e. positive). + /// </summary> + /// <returns>A vector with <see cref="Mathf.Abs(int)"/> called on each component.</returns> public Vector2i Abs() { return new Vector2i(Mathf.Abs(x), Mathf.Abs(y)); } + /// <summary> + /// Returns this vector's angle with respect to the X axis, or (1, 0) vector, in radians. + /// + /// Equivalent to the result of <see cref="Mathf.Atan2(real_t, real_t)"/> when + /// called with the vector's `y` and `x` as parameters: `Mathf.Atan2(v.y, v.x)`. + /// </summary> + /// <returns>The angle of this vector, in radians.</returns> public real_t Angle() { return Mathf.Atan2(y, x); } + /// <summary> + /// Returns the angle to the given vector, in radians. + /// </summary> + /// <param name="to">The other vector to compare this vector to.</param> + /// <returns>The angle between the two vectors, in radians.</returns> public real_t AngleTo(Vector2i to) { return Mathf.Atan2(Cross(to), Dot(to)); } + /// <summary> + /// Returns the angle between the line connecting the two points and the X axis, in radians. + /// </summary> + /// <param name="to">The other vector to compare this vector to.</param> + /// <returns>The angle between the two vectors, in radians.</returns> public real_t AngleToPoint(Vector2i to) { return Mathf.Atan2(y - to.y, x - to.x); } + /// <summary> + /// Returns the aspect ratio of this vector, the ratio of `x` to `y`. + /// </summary> + /// <returns>The `x` component divided by the `y` component.</returns> public real_t Aspect() { return x / (real_t)y; } - public Vector2i Bounce(Vector2i n) - { - return -Reflect(n); - } - + /// <summary> + /// Returns the cross product of this vector and `b`. + /// </summary> + /// <param name="b">The other vector.</param> + /// <returns>The cross product vector.</returns> public int Cross(Vector2i b) { return x * b.y - y * b.x; } + /// <summary> + /// Returns the squared distance between this vector and `b`. + /// This method runs faster than <see cref="DistanceTo"/>, so prefer it if + /// you need to compare vectors or need the squared distance for some formula. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The squared distance between the two vectors.</returns> public int DistanceSquaredTo(Vector2i b) { return (b - this).LengthSquared(); } + /// <summary> + /// Returns the distance between this vector and `b`. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The distance between the two vectors.</returns> public real_t DistanceTo(Vector2i b) { return (b - this).Length(); } + /// <summary> + /// Returns the dot product of this vector and `b`. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The dot product of the two vectors.</returns> public int Dot(Vector2i b) { return x * b.x + y * b.y; } + /// <summary> + /// Returns the length (magnitude) of this vector. + /// </summary> + /// <returns>The length of this vector.</returns> public real_t Length() { int x2 = x * x; @@ -113,6 +173,12 @@ namespace Godot return Mathf.Sqrt(x2 + y2); } + /// <summary> + /// Returns the squared length (squared magnitude) of this vector. + /// This method runs faster than <see cref="Length"/>, so prefer it if + /// you need to compare vectors or need the squared length for some formula. + /// </summary> + /// <returns>The squared length of this vector.</returns> public int LengthSquared() { int x2 = x * x; @@ -121,16 +187,31 @@ namespace Godot return x2 + y2; } + /// <summary> + /// Returns the axis of the vector's largest value. See <see cref="Axis"/>. + /// If both components are equal, this method returns <see cref="Axis.X"/>. + /// </summary> + /// <returns>The index of the largest axis.</returns> public Axis MaxAxis() { return x < y ? Axis.Y : Axis.X; } + /// <summary> + /// Returns the axis of the vector's smallest value. See <see cref="Axis"/>. + /// If both components are equal, this method returns <see cref="Axis.Y"/>. + /// </summary> + /// <returns>The index of the smallest axis.</returns> public Axis MinAxis() { - return x > y ? Axis.Y : Axis.X; + return x < y ? Axis.X : Axis.Y; } + /// <summary> + /// Returns a vector composed of the <see cref="Mathf.PosMod(int, int)"/> of this vector's components and `mod`. + /// </summary> + /// <param name="mod">A value representing the divisor of the operation.</param> + /// <returns>A vector with each component <see cref="Mathf.PosMod(int, int)"/> by `mod`.</returns> public Vector2i PosMod(int mod) { Vector2i v = this; @@ -139,6 +220,11 @@ namespace Godot return v; } + /// <summary> + /// Returns a vector composed of the <see cref="Mathf.PosMod(int, int)"/> of this vector's components and `modv`'s components. + /// </summary> + /// <param name="modv">A vector representing the divisors of the operation.</param> + /// <returns>A vector with each component <see cref="Mathf.PosMod(int, int)"/> by `modv`'s components.</returns> public Vector2i PosMod(Vector2i modv) { Vector2i v = this; @@ -147,11 +233,12 @@ namespace Godot return v; } - public Vector2i Reflect(Vector2i n) - { - return 2 * Dot(n) * n - this; - } - + /// <summary> + /// Returns a vector with each component set to one or negative one, depending + /// on the signs of this vector's components, or zero if the component is zero, + /// by calling <see cref="Mathf.Sign(int)"/> on each component. + /// </summary> + /// <returns>A vector with all components as either `1`, `-1`, or `0`.</returns> public Vector2i Sign() { Vector2i v = this; @@ -160,9 +247,14 @@ namespace Godot return v; } - public Vector2i Tangent() + /// <summary> + /// Returns a vector rotated 90 degrees counter-clockwise + /// compared to the original, with the same length. + /// </summary> + /// <returns>The perpendicular vector.</returns> + public Vector2 Perpendicular() { - return new Vector2i(y, -x); + return new Vector2(y, -x); } // Constants @@ -174,25 +266,64 @@ namespace Godot private static readonly Vector2i _right = new Vector2i(1, 0); private static readonly Vector2i _left = new Vector2i(-1, 0); + /// <summary> + /// Zero vector, a vector with all components set to `0`. + /// </summary> + /// <value>Equivalent to `new Vector2i(0, 0)`</value> public static Vector2i Zero { get { return _zero; } } + /// <summary> + /// One vector, a vector with all components set to `1`. + /// </summary> + /// <value>Equivalent to `new Vector2i(1, 1)`</value> public static Vector2i One { get { return _one; } } + /// <summary> + /// Up unit vector. Y is down in 2D, so this vector points -Y. + /// </summary> + /// <value>Equivalent to `new Vector2i(0, -1)`</value> public static Vector2i Up { get { return _up; } } + /// <summary> + /// Down unit vector. Y is down in 2D, so this vector points +Y. + /// </summary> + /// <value>Equivalent to `new Vector2i(0, 1)`</value> public static Vector2i Down { get { return _down; } } + /// <summary> + /// Right unit vector. Represents the direction of right. + /// </summary> + /// <value>Equivalent to `new Vector2i(1, 0)`</value> public static Vector2i Right { get { return _right; } } + /// <summary> + /// Left unit vector. Represents the direction of left. + /// </summary> + /// <value>Equivalent to `new Vector2i(-1, 0)`</value> public static Vector2i Left { get { return _left; } } - // Constructors + /// <summary> + /// Constructs a new <see cref="Vector2i"/> with the given components. + /// </summary> + /// <param name="x">The vector's X component.</param> + /// <param name="y">The vector's Y component.</param> public Vector2i(int x, int y) { this.x = x; this.y = y; } + + /// <summary> + /// Constructs a new <see cref="Vector2i"/> from an existing <see cref="Vector2i"/>. + /// </summary> + /// <param name="vi">The existing <see cref="Vector2i"/>.</param> public Vector2i(Vector2i vi) { this.x = vi.x; this.y = vi.y; } + + /// <summary> + /// Constructs a new <see cref="Vector2i"/> from an existing <see cref="Vector2"/> + /// by rounding the components via <see cref="Mathf.RoundToInt(real_t)"/>. + /// </summary> + /// <param name="v">The <see cref="Vector2"/> to convert.</param> public Vector2i(Vector2 v) { this.x = Mathf.RoundToInt(v.x); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs index b26e17ecba..d9b16a6afd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3.cs @@ -21,6 +21,10 @@ namespace Godot [StructLayout(LayoutKind.Sequential)] public struct Vector3 : IEquatable<Vector3> { + /// <summary> + /// Enumerated index values for the axes. + /// Returned by <see cref="MaxAxis"/> and <see cref="MinAxis"/>. + /// </summary> public enum Axis { X = 0, @@ -28,10 +32,23 @@ namespace Godot Z } + /// <summary> + /// The vector's X component. Also accessible by using the index position `[0]`. + /// </summary> public real_t x; + /// <summary> + /// The vector's Y component. Also accessible by using the index position `[1]`. + /// </summary> public real_t y; + /// <summary> + /// The vector's Z component. Also accessible by using the index position `[2]`. + /// </summary> public real_t z; + /// <summary> + /// Access vector components using their index. + /// </summary> + /// <value>`[0]` is equivalent to `.x`, `[1]` is equivalent to `.y`, `[2]` is equivalent to `.z`.</value> public real_t this[int index] { get @@ -84,26 +101,49 @@ namespace Godot } } + /// <summary> + /// Returns a new vector with all components in absolute values (i.e. positive). + /// </summary> + /// <returns>A vector with <see cref="Mathf.Abs(real_t)"/> called on each component.</returns> public Vector3 Abs() { return new Vector3(Mathf.Abs(x), Mathf.Abs(y), Mathf.Abs(z)); } + /// <summary> + /// Returns the minimum angle to the given vector, in radians. + /// </summary> + /// <param name="to">The other vector to compare this vector to.</param> + /// <returns>The angle between the two vectors, in radians.</returns> public real_t AngleTo(Vector3 to) { return Mathf.Atan2(Cross(to).Length(), Dot(to)); } - public Vector3 Bounce(Vector3 n) + /// <summary> + /// Returns this vector "bounced off" from a plane defined by the given normal. + /// </summary> + /// <param name="normal">The normal vector defining the plane to bounce off. Must be normalized.</param> + /// <returns>The bounced vector.</returns> + public Vector3 Bounce(Vector3 normal) { - return -Reflect(n); + return -Reflect(normal); } + /// <summary> + /// Returns a new vector with all components rounded up (towards positive infinity). + /// </summary> + /// <returns>A vector with <see cref="Mathf.Ceil"/> called on each component.</returns> public Vector3 Ceil() { return new Vector3(Mathf.Ceil(x), Mathf.Ceil(y), Mathf.Ceil(z)); } + /// <summary> + /// Returns the cross product of this vector and `b`. + /// </summary> + /// <param name="b">The other vector.</param> + /// <returns>The cross product vector.</returns> public Vector3 Cross(Vector3 b) { return new Vector3 @@ -114,12 +154,21 @@ namespace Godot ); } + /// <summary> + /// Performs a cubic interpolation between vectors `preA`, this vector, + /// `b`, and `postB`, by the given amount `t`. + /// </summary> + /// <param name="b">The destination vector.</param> + /// <param name="preA">A vector before this vector.</param> + /// <param name="postB">A vector after `b`.</param> + /// <param name="t">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The interpolated vector.</returns> public Vector3 CubicInterpolate(Vector3 b, Vector3 preA, Vector3 postB, real_t t) { - var p0 = preA; - var p1 = this; - var p2 = b; - var p3 = postB; + Vector3 p0 = preA; + Vector3 p1 = this; + Vector3 p2 = b; + Vector3 p3 = postB; real_t t2 = t * t; real_t t3 = t2 * t; @@ -131,41 +180,79 @@ namespace Godot ); } + /// <summary> + /// Returns the normalized vector pointing from this vector to `b`. + /// </summary> + /// <param name="b">The other vector to point towards.</param> + /// <returns>The direction from this vector to `b`.</returns> public Vector3 DirectionTo(Vector3 b) { return new Vector3(b.x - x, b.y - y, b.z - z).Normalized(); } + /// <summary> + /// Returns the squared distance between this vector and `b`. + /// This method runs faster than <see cref="DistanceTo"/>, so prefer it if + /// you need to compare vectors or need the squared distance for some formula. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The squared distance between the two vectors.</returns> public real_t DistanceSquaredTo(Vector3 b) { return (b - this).LengthSquared(); } + /// <summary> + /// Returns the distance between this vector and `b`. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The distance between the two vectors.</returns> public real_t DistanceTo(Vector3 b) { return (b - this).Length(); } + /// <summary> + /// Returns the dot product of this vector and `b`. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The dot product of the two vectors.</returns> public real_t Dot(Vector3 b) { return x * b.x + y * b.y + z * b.z; } + /// <summary> + /// Returns a new vector with all components rounded down (towards negative infinity). + /// </summary> + /// <returns>A vector with <see cref="Mathf.Floor"/> called on each component.</returns> public Vector3 Floor() { return new Vector3(Mathf.Floor(x), Mathf.Floor(y), Mathf.Floor(z)); } + /// <summary> + /// Returns the inverse of this vector. This is the same as `new Vector3(1 / v.x, 1 / v.y, 1 / v.z)`. + /// </summary> + /// <returns>The inverse of this vector.</returns> public Vector3 Inverse() { - return new Vector3(1.0f / x, 1.0f / y, 1.0f / z); + return new Vector3(1 / x, 1 / y, 1 / z); } + /// <summary> + /// Returns true if the vector is normalized, and false otherwise. + /// </summary> + /// <returns>A bool indicating whether or not the vector is normalized.</returns> public bool IsNormalized() { return Mathf.Abs(LengthSquared() - 1.0f) < Mathf.Epsilon; } + /// <summary> + /// Returns the length (magnitude) of this vector. + /// </summary> + /// <returns>The length of this vector.</returns> public real_t Length() { real_t x2 = x * x; @@ -175,6 +262,12 @@ namespace Godot return Mathf.Sqrt(x2 + y2 + z2); } + /// <summary> + /// Returns the squared length (squared magnitude) of this vector. + /// This method runs faster than <see cref="Length"/>, so prefer it if + /// you need to compare vectors or need the squared length for some formula. + /// </summary> + /// <returns>The squared length of this vector.</returns> public real_t LengthSquared() { real_t x2 = x * x; @@ -184,6 +277,13 @@ namespace Godot return x2 + y2 + z2; } + /// <summary> + /// Returns the result of the linear interpolation between + /// this vector and `to` by amount `weight`. + /// </summary> + /// <param name="to">The destination vector for interpolation.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting vector of the interpolation.</returns> public Vector3 Lerp(Vector3 to, real_t weight) { return new Vector3 @@ -194,6 +294,13 @@ namespace Godot ); } + /// <summary> + /// Returns the result of the linear interpolation between + /// this vector and `to` by the vector amount `weight`. + /// </summary> + /// <param name="to">The destination vector for interpolation.</param> + /// <param name="weight">A vector with components on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting vector of the interpolation.</returns> public Vector3 Lerp(Vector3 to, Vector3 weight) { return new Vector3 @@ -204,24 +311,44 @@ namespace Godot ); } - public Vector3 MoveToward(Vector3 to, real_t delta) - { - var v = this; - var vd = to - v; - var len = vd.Length(); - return len <= delta || len < Mathf.Epsilon ? to : v + vd / len * delta; - } - + /// <summary> + /// Returns the axis of the vector's largest value. See <see cref="Axis"/>. + /// If all components are equal, this method returns <see cref="Axis.X"/>. + /// </summary> + /// <returns>The index of the largest axis.</returns> public Axis MaxAxis() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); } + /// <summary> + /// Returns the axis of the vector's smallest value. See <see cref="Axis"/>. + /// If all components are equal, this method returns <see cref="Axis.Z"/>. + /// </summary> + /// <returns>The index of the smallest axis.</returns> public Axis MinAxis() { return x < y ? (x < z ? Axis.X : Axis.Z) : (y < z ? Axis.Y : Axis.Z); } + /// <summary> + /// Moves this vector toward `to` by the fixed `delta` amount. + /// </summary> + /// <param name="to">The vector to move towards.</param> + /// <param name="delta">The amount to move towards by.</param> + /// <returns>The resulting vector.</returns> + public Vector3 MoveToward(Vector3 to, real_t delta) + { + var v = this; + var vd = to - v; + var len = vd.Length(); + return len <= delta || len < Mathf.Epsilon ? to : v + vd / len * delta; + } + + /// <summary> + /// Returns the vector scaled to unit length. Equivalent to `v / v.Length()`. + /// </summary> + /// <returns>A normalized version of the vector.</returns> public Vector3 Normalized() { var v = this; @@ -229,6 +356,11 @@ namespace Godot return v; } + /// <summary> + /// Returns the outer product with `b`. + /// </summary> + /// <param name="b">The other vector.</param> + /// <returns>A <see cref="Basis"/> representing the outer product matrix.</returns> public Basis Outer(Vector3 b) { return new Basis( @@ -238,6 +370,11 @@ namespace Godot ); } + /// <summary> + /// Returns a vector composed of the <see cref="Mathf.PosMod(real_t, real_t)"/> of this vector's components and `mod`. + /// </summary> + /// <param name="mod">A value representing the divisor of the operation.</param> + /// <returns>A vector with each component <see cref="Mathf.PosMod(real_t, real_t)"/> by `mod`.</returns> public Vector3 PosMod(real_t mod) { Vector3 v; @@ -247,6 +384,11 @@ namespace Godot return v; } + /// <summary> + /// Returns a vector composed of the <see cref="Mathf.PosMod(real_t, real_t)"/> of this vector's components and `modv`'s components. + /// </summary> + /// <param name="modv">A vector representing the divisors of the operation.</param> + /// <returns>A vector with each component <see cref="Mathf.PosMod(real_t, real_t)"/> by `modv`'s components.</returns> public Vector3 PosMod(Vector3 modv) { Vector3 v; @@ -256,30 +398,66 @@ namespace Godot return v; } + /// <summary> + /// Returns this vector projected onto another vector `b`. + /// </summary> + /// <param name="onNormal">The vector to project onto.</param> + /// <returns>The projected vector.</returns> public Vector3 Project(Vector3 onNormal) { return onNormal * (Dot(onNormal) / onNormal.LengthSquared()); } - public Vector3 Reflect(Vector3 n) + /// <summary> + /// Returns this vector reflected from a plane defined by the given `normal`. + /// </summary> + /// <param name="normal">The normal vector defining the plane to reflect from. Must be normalized.</param> + /// <returns>The reflected vector.</returns> + public Vector3 Reflect(Vector3 normal) { #if DEBUG - if (!n.IsNormalized()) - throw new ArgumentException("Argument is not normalized", nameof(n)); + if (!normal.IsNormalized()) + { + throw new ArgumentException("Argument is not normalized", nameof(normal)); + } #endif - return 2.0f * n * Dot(n) - this; + return 2.0f * Dot(normal) * normal - this; } - public Vector3 Round() + /// <summary> + /// Rotates this vector around a given `axis` vector by `phi` radians. + /// The `axis` vector must be a normalized vector. + /// </summary> + /// <param name="axis">The vector to rotate around. Must be normalized.</param> + /// <param name="phi">The angle to rotate by, in radians.</param> + /// <returns>The rotated vector.</returns> + public Vector3 Rotated(Vector3 axis, real_t phi) { - return new Vector3(Mathf.Round(x), Mathf.Round(y), Mathf.Round(z)); +#if DEBUG + if (!axis.IsNormalized()) + { + throw new ArgumentException("Argument is not normalized", nameof(axis)); + } +#endif + return new Basis(axis, phi).Xform(this); } - public Vector3 Rotated(Vector3 axis, real_t phi) + /// <summary> + /// Returns this vector with all components rounded to the nearest integer, + /// with halfway cases rounded towards the nearest multiple of two. + /// </summary> + /// <returns>The rounded vector.</returns> + public Vector3 Round() { - return new Basis(axis, phi).Xform(this); + return new Vector3(Mathf.Round(x), Mathf.Round(y), Mathf.Round(z)); } + /// <summary> + /// Returns a vector with each component set to one or negative one, depending + /// on the signs of this vector's components, or zero if the component is zero, + /// by calling <see cref="Mathf.Sign(real_t)"/> on each component. + /// </summary> + /// <returns>A vector with all components as either `1`, `-1`, or `0`.</returns> public Vector3 Sign() { Vector3 v; @@ -289,44 +467,76 @@ namespace Godot return v; } - public Vector3 Slerp(Vector3 b, real_t t) + /// <summary> + /// Returns the result of the spherical linear interpolation between + /// this vector and `to` by amount `weight`. + /// + /// Note: Both vectors must be normalized. + /// </summary> + /// <param name="to">The destination vector for interpolation. Must be normalized.</param> + /// <param name="weight">A value on the range of 0.0 to 1.0, representing the amount of interpolation.</param> + /// <returns>The resulting vector of the interpolation.</returns> + public Vector3 Slerp(Vector3 to, real_t weight) { #if DEBUG if (!IsNormalized()) - throw new InvalidOperationException("Vector3 is not normalized"); + { + throw new InvalidOperationException("Vector3.Slerp: From vector is not normalized."); + } + if (!to.IsNormalized()) + { + throw new InvalidOperationException("Vector3.Slerp: `to` is not normalized."); + } #endif - real_t theta = AngleTo(b); - return Rotated(Cross(b), theta * t); + real_t theta = AngleTo(to); + return Rotated(Cross(to), theta * weight); } - public Vector3 Slide(Vector3 n) + /// <summary> + /// Returns this vector slid along a plane defined by the given normal. + /// </summary> + /// <param name="normal">The normal vector defining the plane to slide on.</param> + /// <returns>The slid vector.</returns> + public Vector3 Slide(Vector3 normal) { - return this - n * Dot(n); + return this - normal * Dot(normal); } - public Vector3 Snapped(Vector3 by) + /// <summary> + /// Returns this vector with each component snapped to the nearest multiple of `step`. + /// This can also be used to round to an arbitrary number of decimals. + /// </summary> + /// <param name="step">A vector value representing the step size to snap to.</param> + /// <returns>The snapped vector.</returns> + public Vector3 Snapped(Vector3 step) { return new Vector3 ( - Mathf.Stepify(x, by.x), - Mathf.Stepify(y, by.y), - Mathf.Stepify(z, by.z) + Mathf.Stepify(x, step.x), + Mathf.Stepify(y, step.y), + Mathf.Stepify(z, step.z) ); } + /// <summary> + /// Returns a diagonal matrix with the vector as main diagonal. + /// + /// This is equivalent to a Basis with no rotation or shearing and + /// this vector's components set as the scale. + /// </summary> + /// <returns>A Basis with the vector as its main diagonal.</returns> public Basis ToDiagonalMatrix() { return new Basis( - x, 0f, 0f, - 0f, y, 0f, - 0f, 0f, z + x, 0, 0, + 0, y, 0, + 0, 0, z ); } // Constants private static readonly Vector3 _zero = new Vector3(0, 0, 0); private static readonly Vector3 _one = new Vector3(1, 1, 1); - private static readonly Vector3 _negOne = new Vector3(-1, -1, -1); private static readonly Vector3 _inf = new Vector3(Mathf.Inf, Mathf.Inf, Mathf.Inf); private static readonly Vector3 _up = new Vector3(0, 1, 0); @@ -336,25 +546,74 @@ namespace Godot private static readonly Vector3 _forward = new Vector3(0, 0, -1); private static readonly Vector3 _back = new Vector3(0, 0, 1); + /// <summary> + /// Zero vector, a vector with all components set to `0`. + /// </summary> + /// <value>Equivalent to `new Vector3(0, 0, 0)`</value> public static Vector3 Zero { get { return _zero; } } + /// <summary> + /// One vector, a vector with all components set to `1`. + /// </summary> + /// <value>Equivalent to `new Vector3(1, 1, 1)`</value> public static Vector3 One { get { return _one; } } - public static Vector3 NegOne { get { return _negOne; } } + /// <summary> + /// Infinity vector, a vector with all components set to `Mathf.Inf`. + /// </summary> + /// <value>Equivalent to `new Vector3(Mathf.Inf, Mathf.Inf, Mathf.Inf)`</value> public static Vector3 Inf { get { return _inf; } } + /// <summary> + /// Up unit vector. + /// </summary> + /// <value>Equivalent to `new Vector3(0, 1, 0)`</value> public static Vector3 Up { get { return _up; } } + /// <summary> + /// Down unit vector. + /// </summary> + /// <value>Equivalent to `new Vector3(0, -1, 0)`</value> public static Vector3 Down { get { return _down; } } + /// <summary> + /// Right unit vector. Represents the local direction of right, + /// and the global direction of east. + /// </summary> + /// <value>Equivalent to `new Vector3(1, 0, 0)`</value> public static Vector3 Right { get { return _right; } } + /// <summary> + /// Left unit vector. Represents the local direction of left, + /// and the global direction of west. + /// </summary> + /// <value>Equivalent to `new Vector3(-1, 0, 0)`</value> public static Vector3 Left { get { return _left; } } + /// <summary> + /// Forward unit vector. Represents the local direction of forward, + /// and the global direction of north. + /// </summary> + /// <value>Equivalent to `new Vector3(0, 0, -1)`</value> public static Vector3 Forward { get { return _forward; } } + /// <summary> + /// Back unit vector. Represents the local direction of back, + /// and the global direction of south. + /// </summary> + /// <value>Equivalent to `new Vector3(0, 0, 1)`</value> public static Vector3 Back { get { return _back; } } - // Constructors + /// <summary> + /// Constructs a new <see cref="Vector3"/> with the given components. + /// </summary> + /// <param name="x">The vector's X component.</param> + /// <param name="y">The vector's Y component.</param> + /// <param name="z">The vector's Z component.</param> public Vector3(real_t x, real_t y, real_t z) { this.x = x; this.y = y; this.z = z; } + + /// <summary> + /// Constructs a new <see cref="Vector3"/> from an existing <see cref="Vector3"/>. + /// </summary> + /// <param name="v">The existing <see cref="Vector3"/>.</param> public Vector3(Vector3 v) { x = v.x; @@ -515,6 +774,12 @@ namespace Godot return x == other.x && y == other.y && z == other.z; } + /// <summary> + /// Returns true if this vector and `other` are approximately equal, by running + /// <see cref="Mathf.IsEqualApprox(real_t, real_t)"/> on each component. + /// </summary> + /// <param name="other">The other vector to compare.</param> + /// <returns>Whether or not the vectors are approximately equal.</returns> public bool IsEqualApprox(Vector3 other) { return Mathf.IsEqualApprox(x, other.x) && Mathf.IsEqualApprox(y, other.y) && Mathf.IsEqualApprox(z, other.z); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs index c17f900131..bf25ba9cb3 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs @@ -16,6 +16,10 @@ namespace Godot [StructLayout(LayoutKind.Sequential)] public struct Vector3i : IEquatable<Vector3i> { + /// <summary> + /// Enumerated index values for the axes. + /// Returned by <see cref="MaxAxis"/> and <see cref="MinAxis"/>. + /// </summary> public enum Axis { X = 0, @@ -23,10 +27,23 @@ namespace Godot Z } + /// <summary> + /// The vector's X component. Also accessible by using the index position `[0]`. + /// </summary> public int x; + /// <summary> + /// The vector's Y component. Also accessible by using the index position `[1]`. + /// </summary> public int y; + /// <summary> + /// The vector's Z component. Also accessible by using the index position `[2]`. + /// </summary> public int z; + /// <summary> + /// Access vector components using their index. + /// </summary> + /// <value>`[0]` is equivalent to `.x`, `[1]` is equivalent to `.y`, `[2]` is equivalent to `.z`.</value> public int this[int index] { get @@ -62,39 +79,51 @@ namespace Godot } } + /// <summary> + /// Returns a new vector with all components in absolute values (i.e. positive). + /// </summary> + /// <returns>A vector with <see cref="Mathf.Abs(int)"/> called on each component.</returns> public Vector3i Abs() { - Vector3i v = this; - if (v.x < 0) - { - v.x = -v.x; - } - if (v.y < 0) - { - v.y = -v.y; - } - if (v.z < 0) - { - v.z = -v.z; - } - return v; + return new Vector3i(Mathf.Abs(x), Mathf.Abs(y), Mathf.Abs(z)); } + /// <summary> + /// Returns the squared distance between this vector and `b`. + /// This method runs faster than <see cref="DistanceTo"/>, so prefer it if + /// you need to compare vectors or need the squared distance for some formula. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The squared distance between the two vectors.</returns> public int DistanceSquaredTo(Vector3i b) { return (b - this).LengthSquared(); } + /// <summary> + /// Returns the distance between this vector and `b`. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The distance between the two vectors.</returns> public real_t DistanceTo(Vector3i b) { return (b - this).Length(); } + /// <summary> + /// Returns the dot product of this vector and `b`. + /// </summary> + /// <param name="b">The other vector to use.</param> + /// <returns>The dot product of the two vectors.</returns> public int Dot(Vector3i b) { return x * b.x + y * b.y + z * b.z; } + /// <summary> + /// Returns the length (magnitude) of this vector. + /// </summary> + /// <returns>The length of this vector.</returns> public real_t Length() { int x2 = x * x; @@ -104,6 +133,12 @@ namespace Godot return Mathf.Sqrt(x2 + y2 + z2); } + /// <summary> + /// Returns the squared length (squared magnitude) of this vector. + /// This method runs faster than <see cref="Length"/>, so prefer it if + /// you need to compare vectors or need the squared length for some formula. + /// </summary> + /// <returns>The squared length of this vector.</returns> public int LengthSquared() { int x2 = x * x; @@ -113,16 +148,31 @@ namespace Godot return x2 + y2 + z2; } + /// <summary> + /// Returns the axis of the vector's largest value. See <see cref="Axis"/>. + /// If all components are equal, this method returns <see cref="Axis.X"/>. + /// </summary> + /// <returns>The index of the largest axis.</returns> public Axis MaxAxis() { return x < y ? (y < z ? Axis.Z : Axis.Y) : (x < z ? Axis.Z : Axis.X); } + /// <summary> + /// Returns the axis of the vector's smallest value. See <see cref="Axis"/>. + /// If all components are equal, this method returns <see cref="Axis.Z"/>. + /// </summary> + /// <returns>The index of the smallest axis.</returns> public Axis MinAxis() { return x < y ? (x < z ? Axis.X : Axis.Z) : (y < z ? Axis.Y : Axis.Z); } + /// <summary> + /// Returns a vector composed of the <see cref="Mathf.PosMod(int, int)"/> of this vector's components and `mod`. + /// </summary> + /// <param name="mod">A value representing the divisor of the operation.</param> + /// <returns>A vector with each component <see cref="Mathf.PosMod(int, int)"/> by `mod`.</returns> public Vector3i PosMod(int mod) { Vector3i v = this; @@ -132,6 +182,11 @@ namespace Godot return v; } + /// <summary> + /// Returns a vector composed of the <see cref="Mathf.PosMod(int, int)"/> of this vector's components and `modv`'s components. + /// </summary> + /// <param name="modv">A vector representing the divisors of the operation.</param> + /// <returns>A vector with each component <see cref="Mathf.PosMod(int, int)"/> by `modv`'s components.</returns> public Vector3i PosMod(Vector3i modv) { Vector3i v = this; @@ -141,6 +196,12 @@ namespace Godot return v; } + /// <summary> + /// Returns a vector with each component set to one or negative one, depending + /// on the signs of this vector's components, or zero if the component is zero, + /// by calling <see cref="Mathf.Sign(int)"/> on each component. + /// </summary> + /// <returns>A vector with all components as either `1`, `-1`, or `0`.</returns> public Vector3i Sign() { Vector3i v = this; @@ -161,29 +222,81 @@ namespace Godot private static readonly Vector3i _forward = new Vector3i(0, 0, -1); private static readonly Vector3i _back = new Vector3i(0, 0, 1); + /// <summary> + /// Zero vector, a vector with all components set to `0`. + /// </summary> + /// <value>Equivalent to `new Vector3i(0, 0, 0)`</value> public static Vector3i Zero { get { return _zero; } } + /// <summary> + /// One vector, a vector with all components set to `1`. + /// </summary> + /// <value>Equivalent to `new Vector3i(1, 1, 1)`</value> public static Vector3i One { get { return _one; } } + /// <summary> + /// Up unit vector. + /// </summary> + /// <value>Equivalent to `new Vector3i(0, 1, 0)`</value> public static Vector3i Up { get { return _up; } } + /// <summary> + /// Down unit vector. + /// </summary> + /// <value>Equivalent to `new Vector3i(0, -1, 0)`</value> public static Vector3i Down { get { return _down; } } + /// <summary> + /// Right unit vector. Represents the local direction of right, + /// and the global direction of east. + /// </summary> + /// <value>Equivalent to `new Vector3i(1, 0, 0)`</value> public static Vector3i Right { get { return _right; } } + /// <summary> + /// Left unit vector. Represents the local direction of left, + /// and the global direction of west. + /// </summary> + /// <value>Equivalent to `new Vector3i(-1, 0, 0)`</value> public static Vector3i Left { get { return _left; } } + /// <summary> + /// Forward unit vector. Represents the local direction of forward, + /// and the global direction of north. + /// </summary> + /// <value>Equivalent to `new Vector3i(0, 0, -1)`</value> public static Vector3i Forward { get { return _forward; } } + /// <summary> + /// Back unit vector. Represents the local direction of back, + /// and the global direction of south. + /// </summary> + /// <value>Equivalent to `new Vector3i(0, 0, 1)`</value> public static Vector3i Back { get { return _back; } } - // Constructors + /// <summary> + /// Constructs a new <see cref="Vector3i"/> with the given components. + /// </summary> + /// <param name="x">The vector's X component.</param> + /// <param name="y">The vector's Y component.</param> + /// <param name="z">The vector's Z component.</param> public Vector3i(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } + + /// <summary> + /// Constructs a new <see cref="Vector3i"/> from an existing <see cref="Vector3i"/>. + /// </summary> + /// <param name="vi">The existing <see cref="Vector3i"/>.</param> public Vector3i(Vector3i vi) { this.x = vi.x; this.y = vi.y; this.z = vi.z; } + + /// <summary> + /// Constructs a new <see cref="Vector3i"/> from an existing <see cref="Vector3"/> + /// by rounding the components via <see cref="Mathf.RoundToInt(real_t)"/>. + /// </summary> + /// <param name="v">The <see cref="Vector3"/> to convert.</param> public Vector3i(Vector3 v) { this.x = Mathf.RoundToInt(v.x); diff --git a/modules/mono/glue/arguments_vector.h b/modules/mono/glue/arguments_vector.h index 4ee553fc11..ab48904571 100644 --- a/modules/mono/glue/arguments_vector.h +++ b/modules/mono/glue/arguments_vector.h @@ -40,8 +40,8 @@ private: T *_ptr; int size; - ArgumentsVector(); - ArgumentsVector(const ArgumentsVector &); + ArgumentsVector() = delete; + ArgumentsVector(const ArgumentsVector &) = delete; public: T *ptr() { return _ptr; } diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index f370883320..ebcd6d5e9c 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -28,10 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "base_object_glue.h" - #ifdef MONO_GLUE_ENABLED +#include "core/class_db.h" +#include "core/object.h" #include "core/reference.h" #include "core/string_name.h" @@ -39,6 +39,7 @@ #include "../mono_gd/gd_mono_cache.h" #include "../mono_gd/gd_mono_class.h" #include "../mono_gd/gd_mono_internals.h" +#include "../mono_gd/gd_mono_marshal.h" #include "../mono_gd/gd_mono_utils.h" #include "../signal_awaiter_utils.h" #include "arguments_vector.h" @@ -140,16 +141,18 @@ MethodBind *godot_icall_Object_ClassDB_get_method(StringName *p_type, MonoString } MonoObject *godot_icall_Object_weakref(Object *p_ptr) { - if (!p_ptr) + if (!p_ptr) { return nullptr; + } Ref<WeakRef> wref; Reference *ref = Object::cast_to<Reference>(p_ptr); if (ref) { REF r = ref; - if (!r.is_valid()) + if (!r.is_valid()) { return nullptr; + } wref.instance(); wref->set_ref(r); @@ -241,6 +244,7 @@ void godot_register_object_icalls() { mono_add_internal_call("Godot.Object::godot_icall_Object_Ctor", (void *)godot_icall_Object_Ctor); mono_add_internal_call("Godot.Object::godot_icall_Object_Disposed", (void *)godot_icall_Object_Disposed); mono_add_internal_call("Godot.Object::godot_icall_Reference_Disposed", (void *)godot_icall_Reference_Disposed); + mono_add_internal_call("Godot.Object::godot_icall_Object_ConnectEventSignals", (void *)godot_icall_Object_ConnectEventSignals); mono_add_internal_call("Godot.Object::godot_icall_Object_ClassDB_get_method", (void *)godot_icall_Object_ClassDB_get_method); mono_add_internal_call("Godot.Object::godot_icall_Object_ToString", (void *)godot_icall_Object_ToString); mono_add_internal_call("Godot.Object::godot_icall_Object_weakref", (void *)godot_icall_Object_weakref); diff --git a/modules/mono/glue/base_object_glue.h b/modules/mono/glue/base_object_glue.h deleted file mode 100644 index 67769f3061..0000000000 --- a/modules/mono/glue/base_object_glue.h +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************/ -/* base_object_glue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 BASE_OBJECT_GLUE_H -#define BASE_OBJECT_GLUE_H - -#ifdef MONO_GLUE_ENABLED - -#include "core/class_db.h" -#include "core/object.h" - -#include "../mono_gd/gd_mono_marshal.h" - -Object *godot_icall_Object_Ctor(MonoObject *p_obj); - -void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr); - -void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, MonoBoolean p_is_finalizer); - -void godot_icall_Object_ConnectEventSignals(Object *p_ptr); - -MethodBind *godot_icall_Object_ClassDB_get_method(StringName *p_type, MonoString *p_method); - -MonoObject *godot_icall_Object_weakref(Object *p_ptr); - -Error godot_icall_SignalAwaiter_connect(Object *p_source, StringName *p_signal, Object *p_target, MonoObject *p_awaiter); - -// DynamicGodotObject - -MonoArray *godot_icall_DynamicGodotObject_SetMemberList(Object *p_ptr); - -MonoBoolean godot_icall_DynamicGodotObject_InvokeMember(Object *p_ptr, MonoString *p_name, MonoArray *p_args, MonoObject **r_result); - -MonoBoolean godot_icall_DynamicGodotObject_GetMember(Object *p_ptr, MonoString *p_name, MonoObject **r_result); - -MonoBoolean godot_icall_DynamicGodotObject_SetMember(Object *p_ptr, MonoString *p_name, MonoObject *p_value); - -MonoString *godot_icall_Object_ToString(Object *p_ptr); - -// Register internal calls - -void godot_register_object_icalls(); - -#endif // MONO_GLUE_ENABLED - -#endif // BASE_OBJECT_GLUE_H diff --git a/modules/mono/glue/collections_glue.cpp b/modules/mono/glue/collections_glue.cpp index 4e3dc9c4ea..766b00d612 100644 --- a/modules/mono/glue/collections_glue.cpp +++ b/modules/mono/glue/collections_glue.cpp @@ -28,14 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "collections_glue.h" - #ifdef MONO_GLUE_ENABLED #include <mono/metadata/exception.h> +#include "core/array.h" + #include "../mono_gd/gd_mono_cache.h" #include "../mono_gd/gd_mono_class.h" +#include "../mono_gd/gd_mono_marshal.h" #include "../mono_gd/gd_mono_utils.h" Array *godot_icall_Array_Ctor() { diff --git a/modules/mono/glue/collections_glue.h b/modules/mono/glue/collections_glue.h deleted file mode 100644 index f8351a1fc7..0000000000 --- a/modules/mono/glue/collections_glue.h +++ /dev/null @@ -1,124 +0,0 @@ -/*************************************************************************/ -/* collections_glue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 COLLECTIONS_GLUE_H -#define COLLECTIONS_GLUE_H - -#ifdef MONO_GLUE_ENABLED - -#include "core/array.h" - -#include "../mono_gd/gd_mono_marshal.h" - -// Array - -Array *godot_icall_Array_Ctor(); - -void godot_icall_Array_Dtor(Array *ptr); - -MonoObject *godot_icall_Array_At(Array *ptr, int index); - -MonoObject *godot_icall_Array_At_Generic(Array *ptr, int index, uint32_t type_encoding, GDMonoClass *type_class); - -void godot_icall_Array_SetAt(Array *ptr, int index, MonoObject *value); - -int godot_icall_Array_Count(Array *ptr); - -int godot_icall_Array_Add(Array *ptr, MonoObject *item); - -void godot_icall_Array_Clear(Array *ptr); - -MonoBoolean godot_icall_Array_Contains(Array *ptr, MonoObject *item); - -void godot_icall_Array_CopyTo(Array *ptr, MonoArray *array, int array_index); - -Array *godot_icall_Array_Duplicate(Array *ptr, MonoBoolean deep); - -int godot_icall_Array_IndexOf(Array *ptr, MonoObject *item); - -void godot_icall_Array_Insert(Array *ptr, int index, MonoObject *item); - -MonoBoolean godot_icall_Array_Remove(Array *ptr, MonoObject *item); - -void godot_icall_Array_RemoveAt(Array *ptr, int index); - -Error godot_icall_Array_Resize(Array *ptr, int new_size); - -void godot_icall_Array_Generic_GetElementTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class); - -MonoString *godot_icall_Array_ToString(Array *ptr); - -// Dictionary - -Dictionary *godot_icall_Dictionary_Ctor(); - -void godot_icall_Dictionary_Dtor(Dictionary *ptr); - -MonoObject *godot_icall_Dictionary_GetValue(Dictionary *ptr, MonoObject *key); - -MonoObject *godot_icall_Dictionary_GetValue_Generic(Dictionary *ptr, MonoObject *key, uint32_t type_encoding, GDMonoClass *type_class); - -void godot_icall_Dictionary_SetValue(Dictionary *ptr, MonoObject *key, MonoObject *value); - -Array *godot_icall_Dictionary_Keys(Dictionary *ptr); - -Array *godot_icall_Dictionary_Values(Dictionary *ptr); - -int godot_icall_Dictionary_Count(Dictionary *ptr); - -void godot_icall_Dictionary_Add(Dictionary *ptr, MonoObject *key, MonoObject *value); - -void godot_icall_Dictionary_Clear(Dictionary *ptr); - -MonoBoolean godot_icall_Dictionary_Contains(Dictionary *ptr, MonoObject *key, MonoObject *value); - -MonoBoolean godot_icall_Dictionary_ContainsKey(Dictionary *ptr, MonoObject *key); - -Dictionary *godot_icall_Dictionary_Duplicate(Dictionary *ptr, MonoBoolean deep); - -MonoBoolean godot_icall_Dictionary_RemoveKey(Dictionary *ptr, MonoObject *key); - -MonoBoolean godot_icall_Dictionary_Remove(Dictionary *ptr, MonoObject *key, MonoObject *value); - -MonoBoolean godot_icall_Dictionary_TryGetValue(Dictionary *ptr, MonoObject *key, MonoObject **value); - -MonoBoolean godot_icall_Dictionary_TryGetValue_Generic(Dictionary *ptr, MonoObject *key, MonoObject **value, uint32_t type_encoding, GDMonoClass *type_class); - -void godot_icall_Dictionary_Generic_GetValueTypeInfo(MonoReflectionType *refltype, uint32_t *type_encoding, GDMonoClass **type_class); - -MonoString *godot_icall_Dictionary_ToString(Dictionary *ptr); - -// Register internal calls - -void godot_register_collections_icalls(); - -#endif // MONO_GLUE_ENABLED - -#endif // COLLECTIONS_GLUE_H diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp index e43b06d18e..5e892b616b 100644 --- a/modules/mono/glue/gd_glue.cpp +++ b/modules/mono/glue/gd_glue.cpp @@ -28,8 +28,6 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "gd_glue.h" - #ifdef MONO_GLUE_ENABLED #include "core/array.h" @@ -40,6 +38,7 @@ #include "core/variant_parser.h" #include "../mono_gd/gd_mono_cache.h" +#include "../mono_gd/gd_mono_marshal.h" #include "../mono_gd/gd_mono_utils.h" MonoObject *godot_icall_GD_bytes2var(MonoArray *p_bytes, MonoBoolean p_allow_objects) { @@ -147,8 +146,9 @@ void godot_icall_GD_prints(MonoArray *p_what) { return; } - if (i) + if (i) { str += " "; + } str += elem_str; } @@ -171,8 +171,9 @@ void godot_icall_GD_printt(MonoArray *p_what) { return; } - if (i) + if (i) { str += "\t"; + } str += elem_str; } @@ -197,7 +198,7 @@ double godot_icall_GD_rand_range(double from, double to) { } uint32_t godot_icall_GD_rand_seed(uint64_t seed, uint64_t *newSeed) { - int ret = Math::rand_from_seed(&seed); + uint32_t ret = Math::rand_from_seed(&seed); *newSeed = seed; return ret; } @@ -213,10 +214,11 @@ MonoString *godot_icall_GD_str(MonoArray *p_what) { for (int i = 0; i < what.size(); i++) { String os = what[i].operator String(); - if (i == 0) + if (i == 0) { str = os; - else + } else { str += os; + } } return GDMonoMarshal::mono_string_from_godot(str); diff --git a/modules/mono/glue/gd_glue.h b/modules/mono/glue/gd_glue.h deleted file mode 100644 index 3ad6058205..0000000000 --- a/modules/mono/glue/gd_glue.h +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************/ -/* gd_glue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 GD_GLUE_H -#define GD_GLUE_H - -#ifdef MONO_GLUE_ENABLED - -#include "../mono_gd/gd_mono_marshal.h" - -MonoObject *godot_icall_GD_bytes2var(MonoArray *p_bytes, MonoBoolean p_allow_objects); - -MonoObject *godot_icall_GD_convert(MonoObject *p_what, int32_t p_type); - -int godot_icall_GD_hash(MonoObject *p_var); - -MonoObject *godot_icall_GD_instance_from_id(uint64_t p_instance_id); - -void godot_icall_GD_print(MonoArray *p_what); - -void godot_icall_GD_printerr(MonoArray *p_what); - -void godot_icall_GD_printraw(MonoArray *p_what); - -void godot_icall_GD_prints(MonoArray *p_what); - -void godot_icall_GD_printt(MonoArray *p_what); - -float godot_icall_GD_randf(); - -uint32_t godot_icall_GD_randi(); - -void godot_icall_GD_randomize(); - -double godot_icall_GD_rand_range(double from, double to); - -uint32_t godot_icall_GD_rand_seed(uint64_t seed, uint64_t *newSeed); - -void godot_icall_GD_seed(uint64_t p_seed); - -MonoString *godot_icall_GD_str(MonoArray *p_what); - -MonoObject *godot_icall_GD_str2var(MonoString *p_str); - -MonoBoolean godot_icall_GD_type_exists(StringName *p_type); - -MonoArray *godot_icall_GD_var2bytes(MonoObject *p_var, MonoBoolean p_full_objects); - -MonoString *godot_icall_GD_var2str(MonoObject *p_var); - -MonoObject *godot_icall_DefaultGodotTaskScheduler(); - -// Register internal calls - -void godot_register_gd_icalls(); - -#endif // MONO_GLUE_ENABLED - -#endif // GD_GLUE_H diff --git a/modules/mono/glue/glue_header.h b/modules/mono/glue/glue_header.h index f6999d01fb..c1f1936711 100644 --- a/modules/mono/glue/glue_header.h +++ b/modules/mono/glue/glue_header.h @@ -30,14 +30,16 @@ #ifdef MONO_GLUE_ENABLED -#include "base_object_glue.h" -#include "collections_glue.h" -#include "gd_glue.h" -#include "nodepath_glue.h" -#include "rid_glue.h" -#include "scene_tree_glue.h" -#include "string_glue.h" -#include "string_name_glue.h" +#include "../mono_gd/gd_mono_marshal.h" + +void godot_register_collections_icalls(); +void godot_register_gd_icalls(); +void godot_register_string_name_icalls(); +void godot_register_nodepath_icalls(); +void godot_register_object_icalls(); +void godot_register_rid_icalls(); +void godot_register_string_icalls(); +void godot_register_scene_tree_icalls(); /** * Registers internal calls that were not generated. This function is called diff --git a/modules/mono/glue/nodepath_glue.cpp b/modules/mono/glue/nodepath_glue.cpp index e413f404d8..2aa75dd309 100644 --- a/modules/mono/glue/nodepath_glue.cpp +++ b/modules/mono/glue/nodepath_glue.cpp @@ -28,12 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "nodepath_glue.h" - #ifdef MONO_GLUE_ENABLED +#include "core/node_path.h" #include "core/ustring.h" +#include "../mono_gd/gd_mono_marshal.h" + NodePath *godot_icall_NodePath_Ctor(MonoString *p_path) { return memnew(NodePath(GDMonoMarshal::mono_string_to_godot(p_path))); } @@ -51,7 +52,7 @@ MonoBoolean godot_icall_NodePath_is_absolute(NodePath *p_ptr) { return (MonoBoolean)p_ptr->is_absolute(); } -uint32_t godot_icall_NodePath_get_name_count(NodePath *p_ptr) { +int32_t godot_icall_NodePath_get_name_count(NodePath *p_ptr) { return p_ptr->get_name_count(); } @@ -59,7 +60,7 @@ MonoString *godot_icall_NodePath_get_name(NodePath *p_ptr, uint32_t p_idx) { return GDMonoMarshal::mono_string_from_godot(p_ptr->get_name(p_idx)); } -uint32_t godot_icall_NodePath_get_subname_count(NodePath *p_ptr) { +int32_t godot_icall_NodePath_get_subname_count(NodePath *p_ptr) { return p_ptr->get_subname_count(); } diff --git a/modules/mono/glue/nodepath_glue.h b/modules/mono/glue/nodepath_glue.h deleted file mode 100644 index 727679c278..0000000000 --- a/modules/mono/glue/nodepath_glue.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************/ -/* nodepath_glue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 NODEPATH_GLUE_H -#define NODEPATH_GLUE_H - -#ifdef MONO_GLUE_ENABLED - -#include "core/node_path.h" - -#include "../mono_gd/gd_mono_marshal.h" - -NodePath *godot_icall_NodePath_Ctor(MonoString *p_path); - -void godot_icall_NodePath_Dtor(NodePath *p_ptr); - -MonoString *godot_icall_NodePath_operator_String(NodePath *p_np); - -MonoBoolean godot_icall_NodePath_is_absolute(NodePath *p_ptr); - -uint32_t godot_icall_NodePath_get_name_count(NodePath *p_ptr); - -MonoString *godot_icall_NodePath_get_name(NodePath *p_ptr, uint32_t p_idx); - -uint32_t godot_icall_NodePath_get_subname_count(NodePath *p_ptr); - -MonoString *godot_icall_NodePath_get_subname(NodePath *p_ptr, uint32_t p_idx); - -MonoString *godot_icall_NodePath_get_concatenated_subnames(NodePath *p_ptr); - -NodePath *godot_icall_NodePath_get_as_property_path(NodePath *p_ptr); - -MonoBoolean godot_icall_NodePath_is_empty(NodePath *p_ptr); - -// Register internal calls - -void godot_register_nodepath_icalls(); - -#endif // MONO_GLUE_ENABLED - -#endif // NODEPATH_GLUE_H diff --git a/modules/mono/glue/rid_glue.cpp b/modules/mono/glue/rid_glue.cpp index 66a49d8fec..6d2e6b559f 100644 --- a/modules/mono/glue/rid_glue.cpp +++ b/modules/mono/glue/rid_glue.cpp @@ -28,17 +28,20 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "rid_glue.h" - #ifdef MONO_GLUE_ENABLED +#include "core/object.h" #include "core/resource.h" +#include "core/rid.h" + +#include "../mono_gd/gd_mono_marshal.h" RID *godot_icall_RID_Ctor(Object *p_from) { Resource *res_from = Object::cast_to<Resource>(p_from); - if (res_from) + if (res_from) { return memnew(RID(res_from->get_rid())); + } return memnew(RID); } diff --git a/modules/mono/glue/rid_glue.h b/modules/mono/glue/rid_glue.h deleted file mode 100644 index 506d715451..0000000000 --- a/modules/mono/glue/rid_glue.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************/ -/* rid_glue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 RID_GLUE_H -#define RID_GLUE_H - -#ifdef MONO_GLUE_ENABLED - -#include "core/object.h" -#include "core/rid.h" - -#include "../mono_gd/gd_mono_marshal.h" - -RID *godot_icall_RID_Ctor(Object *p_from); - -void godot_icall_RID_Dtor(RID *p_ptr); - -uint32_t godot_icall_RID_get_id(RID *p_ptr); - -// Register internal calls - -void godot_register_rid_icalls(); - -#endif // MONO_GLUE_ENABLED - -#endif // RID_GLUE_H diff --git a/modules/mono/glue/scene_tree_glue.cpp b/modules/mono/glue/scene_tree_glue.cpp index bea9544b08..b43daccc1b 100644 --- a/modules/mono/glue/scene_tree_glue.cpp +++ b/modules/mono/glue/scene_tree_glue.cpp @@ -28,14 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "scene_tree_glue.h" - #ifdef MONO_GLUE_ENABLED +#include "core/array.h" #include "core/class_db.h" -#include "modules/mono/csharp_script.h" -#include "modules/mono/mono_gd/gd_mono_utils.h" +#include "core/string_name.h" #include "scene/main/node.h" +#include "scene/main/scene_tree.h" + +#include "../csharp_script.h" +#include "../mono_gd/gd_mono_marshal.h" +#include "../mono_gd/gd_mono_utils.h" Array *godot_icall_SceneTree_get_nodes_in_group_Generic(SceneTree *ptr, StringName *group, MonoReflectionType *refltype) { List<Node *> nodes; @@ -54,8 +57,9 @@ Array *godot_icall_SceneTree_get_nodes_in_group_Generic(SceneTree *ptr, StringNa // If we're trying to get native objects, just check the inheritance list StringName native_class_name = GDMonoUtils::get_native_godot_class_name(klass); for (int i = 0; i < nodes.size(); ++i) { - if (ClassDB::is_parent_class(nodes[i]->get_class(), native_class_name)) + if (ClassDB::is_parent_class(nodes[i]->get_class(), native_class_name)) { ret.push_back(nodes[i]); + } } } else { // If we're trying to get csharpscript instances, get the mono object and compare the classes diff --git a/modules/mono/glue/scene_tree_glue.h b/modules/mono/glue/scene_tree_glue.h deleted file mode 100644 index e9af35a30b..0000000000 --- a/modules/mono/glue/scene_tree_glue.h +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************/ -/* scene_tree_glue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 SCENE_TREE_GLUE_H -#define SCENE_TREE_GLUE_H - -#ifdef MONO_GLUE_ENABLED - -#include "core/array.h" -#include "core/string_name.h" -#include "scene/main/scene_tree.h" - -#include "../mono_gd/gd_mono_marshal.h" - -Array *godot_icall_SceneTree_get_nodes_in_group_Generic(SceneTree *ptr, StringName *group, MonoReflectionType *refltype); - -// Register internal calls - -void godot_register_scene_tree_icalls(); - -#endif // MONO_GLUE_ENABLED - -#endif // SCENE_TREE_GLUE_H diff --git a/modules/mono/glue/string_glue.cpp b/modules/mono/glue/string_glue.cpp index e407a70db9..595b8d71f1 100644 --- a/modules/mono/glue/string_glue.cpp +++ b/modules/mono/glue/string_glue.cpp @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "string_glue.h" - #ifdef MONO_GLUE_ENABLED #include "core/ustring.h" #include "core/variant.h" #include "core/vector.h" +#include "../mono_gd/gd_mono_marshal.h" + MonoArray *godot_icall_String_md5_buffer(MonoString *p_str) { Vector<uint8_t> ret = GDMonoMarshal::mono_string_to_godot(p_str).md5_buffer(); // TODO Check possible Array/Vector<uint8_t> problem? diff --git a/modules/mono/glue/string_glue.h b/modules/mono/glue/string_glue.h deleted file mode 100644 index a5e833ba61..0000000000 --- a/modules/mono/glue/string_glue.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************/ -/* string_glue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 STRING_GLUE_H -#define STRING_GLUE_H - -#ifdef MONO_GLUE_ENABLED - -#include "../mono_gd/gd_mono_marshal.h" - -MonoArray *godot_icall_String_md5_buffer(MonoString *p_str); - -MonoString *godot_icall_String_md5_text(MonoString *p_str); - -int godot_icall_String_rfind(MonoString *p_str, MonoString *p_what, int p_from); - -int godot_icall_String_rfindn(MonoString *p_str, MonoString *p_what, int p_from); - -MonoArray *godot_icall_String_sha256_buffer(MonoString *p_str); - -MonoString *godot_icall_String_sha256_text(MonoString *p_str); - -// Register internal calls - -void godot_register_string_icalls(); - -#endif // MONO_GLUE_ENABLED - -#endif // STRING_GLUE_H diff --git a/modules/mono/glue/string_name_glue.cpp b/modules/mono/glue/string_name_glue.cpp index 81006e5849..4b2e88569b 100644 --- a/modules/mono/glue/string_name_glue.cpp +++ b/modules/mono/glue/string_name_glue.cpp @@ -28,12 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "string_name_glue.h" - #ifdef MONO_GLUE_ENABLED +#include "core/string_name.h" #include "core/ustring.h" +#include "../mono_gd/gd_mono_marshal.h" + StringName *godot_icall_StringName_Ctor(MonoString *p_path) { return memnew(StringName(GDMonoMarshal::mono_string_to_godot(p_path))); } @@ -48,7 +49,7 @@ MonoString *godot_icall_StringName_operator_String(StringName *p_np) { } MonoBoolean godot_icall_StringName_is_empty(StringName *p_ptr) { - return (MonoBoolean)(p_ptr == StringName()); + return (MonoBoolean)(*p_ptr == StringName()); } void godot_register_string_name_icalls() { diff --git a/modules/mono/glue/string_name_glue.h b/modules/mono/glue/string_name_glue.h deleted file mode 100644 index 88354ddd84..0000000000 --- a/modules/mono/glue/string_name_glue.h +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************/ -/* string_name_glue.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 STRING_NAME_GLUE_H -#define STRING_NAME_GLUE_H - -#ifdef MONO_GLUE_ENABLED - -#include "core/string_name.h" - -#include "../mono_gd/gd_mono_marshal.h" - -StringName *godot_icall_StringName_Ctor(MonoString *p_path); - -void godot_icall_StringName_Dtor(StringName *p_ptr); - -MonoString *godot_icall_StringName_operator_String(StringName *p_np); - -MonoBoolean godot_icall_StringName_is_empty(StringName *p_ptr); - -// Register internal calls - -void godot_register_string_name_icalls(); - -#endif // MONO_GLUE_ENABLED - -#endif // STRING_NAME_GLUE_H diff --git a/modules/mono/managed_callable.cpp b/modules/mono/managed_callable.cpp index 26347e9162..dbe9c7fc5d 100644 --- a/modules/mono/managed_callable.cpp +++ b/modules/mono/managed_callable.cpp @@ -48,8 +48,9 @@ bool ManagedCallable::compare_equal(const CallableCustom *p_a, const CallableCus MonoDelegate *delegate_b = (MonoDelegate *)b->delegate_handle.get_target(); if (!delegate_a || !delegate_b) { - if (!delegate_a && !delegate_b) + if (!delegate_a && !delegate_b) { return true; + } return false; } @@ -58,8 +59,9 @@ bool ManagedCallable::compare_equal(const CallableCustom *p_a, const CallableCus } bool ManagedCallable::compare_less(const CallableCustom *p_a, const CallableCustom *p_b) { - if (compare_equal(p_a, p_b)) + if (compare_equal(p_a, p_b)) { return false; + } return p_a < p_b; } diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index 39c3bd8934..cf5ac33d20 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -144,8 +144,9 @@ void gd_mono_debug_init() { if (Engine::get_singleton()->is_editor_hint() || ProjectSettings::get_singleton()->get_resource_path().empty() || Main::is_project_manager()) { - if (da_args.size() == 0) + if (da_args.size() == 0) { return; + } } if (da_args.length() == 0) { @@ -423,24 +424,27 @@ void GDMono::initialize_load_assemblies() { bool tool_assemblies_loaded = _load_tools_assemblies(); CRASH_COND_MSG(!tool_assemblies_loaded, "Mono: Failed to load '" TOOLS_ASM_NAME "' assemblies."); - if (Main::is_project_manager()) + if (Main::is_project_manager()) { return; + } #endif // Load the project's main assembly. This doesn't necessarily need to succeed. // The game may not be using .NET at all, or if the project does use .NET and // we're running in the editor, it may just happen to be it wasn't built yet. if (!_load_project_assembly()) { - if (OS::get_singleton()->is_stdout_verbose()) + if (OS::get_singleton()->is_stdout_verbose()) { print_error("Mono: Failed to load project assembly"); + } } } bool GDMono::_are_api_assemblies_out_of_sync() { bool out_of_sync = core_api_assembly.assembly && (core_api_assembly.out_of_sync || !GDMonoCache::cached_data.godot_api_cache_updated); #ifdef TOOLS_ENABLED - if (!out_of_sync) + if (!out_of_sync) { out_of_sync = editor_api_assembly.assembly && editor_api_assembly.out_of_sync; + } #endif return out_of_sync; } @@ -512,16 +516,17 @@ void GDMono::_init_exception_policy() { } } -void GDMono::add_assembly(uint32_t p_domain_id, GDMonoAssembly *p_assembly) { +void GDMono::add_assembly(int32_t p_domain_id, GDMonoAssembly *p_assembly) { assemblies[p_domain_id][p_assembly->get_name()] = p_assembly; } GDMonoAssembly *GDMono::get_loaded_assembly(const String &p_name) { - if (p_name == "mscorlib" && corlib_assembly) + if (p_name == "mscorlib" && corlib_assembly) { return corlib_assembly; + } MonoDomain *domain = mono_domain_get(); - uint32_t domain_id = domain ? mono_domain_get_id(domain) : 0; + int32_t domain_id = domain ? mono_domain_get_id(domain) : 0; GDMonoAssembly **result = assemblies[domain_id].getptr(p_name); return result ? *result : nullptr; } @@ -556,8 +561,9 @@ bool GDMono::load_assembly(const String &p_name, MonoAssemblyName *p_aname, GDMo GDMonoAssembly *assembly = GDMonoAssembly::load(p_name, p_aname, p_refonly, p_search_dirs); - if (!assembly) + if (!assembly) { return false; + } *r_assembly = assembly; @@ -573,8 +579,9 @@ bool GDMono::load_assembly_from(const String &p_name, const String &p_path, GDMo GDMonoAssembly *assembly = GDMonoAssembly::load_from(p_name, p_path, p_refonly); - if (!assembly) + if (!assembly) { return false; + } *r_assembly = assembly; @@ -594,16 +601,19 @@ ApiAssemblyInfo::Version ApiAssemblyInfo::Version::get_from_loaded_assembly(GDMo if (nativecalls_klass) { GDMonoField *api_hash_field = nativecalls_klass->get_field("godot_api_hash"); - if (api_hash_field) + if (api_hash_field) { api_assembly_version.godot_api_hash = GDMonoMarshal::unbox<uint64_t>(api_hash_field->get_value(nullptr)); + } GDMonoField *binds_ver_field = nativecalls_klass->get_field("bindings_version"); - if (binds_ver_field) + if (binds_ver_field) { api_assembly_version.bindings_version = GDMonoMarshal::unbox<uint32_t>(binds_ver_field->get_value(nullptr)); + } GDMonoField *cs_glue_ver_field = nativecalls_klass->get_field("cs_glue_version"); - if (cs_glue_ver_field) + if (cs_glue_ver_field) { api_assembly_version.cs_glue_version = GDMonoMarshal::unbox<uint32_t>(cs_glue_ver_field->get_value(nullptr)); + } } return api_assembly_version; @@ -614,13 +624,15 @@ String ApiAssemblyInfo::to_string(ApiAssemblyInfo::Type p_type) { } bool GDMono::_load_corlib_assembly() { - if (corlib_assembly) + if (corlib_assembly) { return true; + } bool success = load_assembly("mscorlib", &corlib_assembly); - if (success) + if (success) { GDMonoCache::update_corlib_cache(); + } return success; } @@ -647,12 +659,14 @@ bool GDMono::copy_prebuilt_api_assembly(ApiAssemblyInfo::Type p_api_type, const DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); String xml_file = assembly_name + ".xml"; - if (da->copy(src_dir.plus_file(xml_file), dst_dir.plus_file(xml_file)) != OK) + if (da->copy(src_dir.plus_file(xml_file), dst_dir.plus_file(xml_file)) != OK) { WARN_PRINT("Failed to copy '" + xml_file + "'."); + } String pdb_file = assembly_name + ".pdb"; - if (da->copy(src_dir.plus_file(pdb_file), dst_dir.plus_file(pdb_file)) != OK) + if (da->copy(src_dir.plus_file(pdb_file), dst_dir.plus_file(pdb_file)) != OK) { WARN_PRINT("Failed to copy '" + pdb_file + "'."); + } String assembly_file = assembly_name + ".dll"; if (da->copy(src_dir.plus_file(assembly_file), dst_dir.plus_file(assembly_file)) != OK) { @@ -667,13 +681,15 @@ static bool try_get_cached_api_hash_for(const String &p_api_assemblies_dir, bool String core_api_assembly_path = p_api_assemblies_dir.plus_file(CORE_API_ASSEMBLY_NAME ".dll"); String editor_api_assembly_path = p_api_assemblies_dir.plus_file(EDITOR_API_ASSEMBLY_NAME ".dll"); - if (!FileAccess::exists(core_api_assembly_path) || !FileAccess::exists(editor_api_assembly_path)) + if (!FileAccess::exists(core_api_assembly_path) || !FileAccess::exists(editor_api_assembly_path)) { return false; + } String cached_api_hash_path = p_api_assemblies_dir.plus_file("api_hash_cache.cfg"); - if (!FileAccess::exists(cached_api_hash_path)) + if (!FileAccess::exists(cached_api_hash_path)) { return false; + } Ref<ConfigFile> cfg; cfg.instance(); @@ -766,8 +782,9 @@ String GDMono::update_api_assemblies_from_prebuilt(const String &p_config, const // Note: Even if only one of the assemblies if missing or out of sync, we update both - if (!api_assemblies_out_of_sync && FileAccess::exists(core_assembly_path) && FileAccess::exists(editor_assembly_path)) + if (!api_assemblies_out_of_sync && FileAccess::exists(core_assembly_path) && FileAccess::exists(editor_assembly_path)) { return String(); // No update needed + } print_verbose("Updating '" + p_config + "' API assemblies"); @@ -795,8 +812,9 @@ String GDMono::update_api_assemblies_from_prebuilt(const String &p_config, const #endif bool GDMono::_load_core_api_assembly(LoadedApiAssembly &r_loaded_api_assembly, const String &p_config, bool p_refonly) { - if (r_loaded_api_assembly.assembly) + if (r_loaded_api_assembly.assembly) { return true; + } #ifdef TOOLS_ENABLED // For the editor and the editor player we want to load it from a specific path to make sure we can keep it up to date @@ -828,8 +846,9 @@ bool GDMono::_load_core_api_assembly(LoadedApiAssembly &r_loaded_api_assembly, c #ifdef TOOLS_ENABLED bool GDMono::_load_editor_api_assembly(LoadedApiAssembly &r_loaded_api_assembly, const String &p_config, bool p_refonly) { - if (r_loaded_api_assembly.assembly) + if (r_loaded_api_assembly.assembly) { return true; + } // For the editor and the editor player we want to load it from a specific path to make sure we can keep it up to date @@ -859,30 +878,35 @@ bool GDMono::_load_editor_api_assembly(LoadedApiAssembly &r_loaded_api_assembly, bool GDMono::_try_load_api_assemblies(LoadedApiAssembly &r_core_api_assembly, LoadedApiAssembly &r_editor_api_assembly, const String &p_config, bool p_refonly, CoreApiAssemblyLoadedCallback p_callback) { if (!_load_core_api_assembly(r_core_api_assembly, p_config, p_refonly)) { - if (OS::get_singleton()->is_stdout_verbose()) + if (OS::get_singleton()->is_stdout_verbose()) { print_error("Mono: Failed to load Core API assembly"); + } return false; } #ifdef TOOLS_ENABLED if (!_load_editor_api_assembly(r_editor_api_assembly, p_config, p_refonly)) { - if (OS::get_singleton()->is_stdout_verbose()) + if (OS::get_singleton()->is_stdout_verbose()) { print_error("Mono: Failed to load Editor API assembly"); + } return false; } - if (r_editor_api_assembly.out_of_sync) + if (r_editor_api_assembly.out_of_sync) { return false; + } #endif // Check if the core API assembly is out of sync only after trying to load the // editor API assembly. Otherwise, if both assemblies are out of sync, we would // only update the former as we won't know the latter also needs to be updated. - if (r_core_api_assembly.out_of_sync) + if (r_core_api_assembly.out_of_sync) { return false; + } - if (p_callback) + if (p_callback) { return p_callback(); + } return true; } @@ -890,8 +914,9 @@ bool GDMono::_try_load_api_assemblies(LoadedApiAssembly &r_core_api_assembly, Lo bool GDMono::_on_core_api_assembly_loaded() { GDMonoCache::update_godot_api_cache(); - if (!GDMonoCache::cached_data.godot_api_cache_updated) + if (!GDMonoCache::cached_data.godot_api_cache_updated) { return false; + } get_singleton()->_install_trace_listener(); @@ -956,8 +981,9 @@ void GDMono::_load_api_assemblies() { #ifdef TOOLS_ENABLED bool GDMono::_load_tools_assemblies() { - if (tools_assembly && tools_project_editor_assembly) + if (tools_assembly && tools_project_editor_assembly) { return true; + } bool success = load_assembly(TOOLS_ASM_NAME, &tools_assembly) && load_assembly(TOOLS_PROJECT_EDITOR_ASM_NAME, &tools_project_editor_assembly); @@ -967,8 +993,9 @@ bool GDMono::_load_tools_assemblies() { #endif bool GDMono::_load_project_assembly() { - if (project_assembly) + if (project_assembly) { return true; + } String appname = ProjectSettings::get_singleton()->get("application/config/name"); String appname_safe = OS::get_singleton()->get_safe_dir_name(appname); @@ -1020,8 +1047,9 @@ Error GDMono::_unload_scripts_domain() { print_verbose("Mono: Finalizing scripts domain..."); - if (mono_domain_get() != root_domain) + if (mono_domain_get() != root_domain) { mono_domain_set(root_domain, true); + } finalizing_scripts_domain = true; @@ -1111,8 +1139,9 @@ Error GDMono::finalize_and_unload_domain(MonoDomain *p_domain) { print_verbose("Mono: Unloading domain '" + domain_name + "'..."); - if (mono_domain_get() == p_domain) + if (mono_domain_get() == p_domain) { mono_domain_set(root_domain, true); + } if (!mono_domain_finalize(p_domain, 2000)) { ERR_PRINT("Mono: Domain finalization timeout."); @@ -1138,10 +1167,11 @@ Error GDMono::finalize_and_unload_domain(MonoDomain *p_domain) { GDMonoClass *GDMono::get_class(MonoClass *p_raw_class) { MonoImage *image = mono_class_get_image(p_raw_class); - if (image == corlib_assembly->get_image()) + if (image == corlib_assembly->get_image()) { return corlib_assembly->get_class(p_raw_class); + } - uint32_t domain_id = mono_domain_get_id(mono_domain_get()); + int32_t domain_id = mono_domain_get_id(mono_domain_get()); HashMap<String, GDMonoAssembly *> &domain_assemblies = assemblies[domain_id]; const String *k = nullptr; @@ -1149,9 +1179,9 @@ GDMonoClass *GDMono::get_class(MonoClass *p_raw_class) { GDMonoAssembly *assembly = domain_assemblies.get(*k); if (assembly->get_image() == image) { GDMonoClass *klass = assembly->get_class(p_raw_class); - - if (klass) + if (klass) { return klass; + } } } @@ -1160,24 +1190,26 @@ GDMonoClass *GDMono::get_class(MonoClass *p_raw_class) { GDMonoClass *GDMono::get_class(const StringName &p_namespace, const StringName &p_name) { GDMonoClass *klass = corlib_assembly->get_class(p_namespace, p_name); - if (klass) + if (klass) { return klass; + } - uint32_t domain_id = mono_domain_get_id(mono_domain_get()); + int32_t domain_id = mono_domain_get_id(mono_domain_get()); HashMap<String, GDMonoAssembly *> &domain_assemblies = assemblies[domain_id]; const String *k = nullptr; while ((k = domain_assemblies.next(k))) { GDMonoAssembly *assembly = domain_assemblies.get(*k); klass = assembly->get_class(p_namespace, p_name); - if (klass) + if (klass) { return klass; + } } return nullptr; } -void GDMono::_domain_assemblies_cleanup(uint32_t p_domain_id) { +void GDMono::_domain_assemblies_cleanup(int32_t p_domain_id) { HashMap<String, GDMonoAssembly *> &domain_assemblies = assemblies[p_domain_id]; const String *k = nullptr; @@ -1195,8 +1227,9 @@ void GDMono::unhandled_exception_hook(MonoObject *p_exc, void *) { #ifdef DEBUG_ENABLED GDMonoUtils::debug_send_unhandled_exception_error((MonoException *)p_exc); - if (EngineDebugger::is_active()) + if (EngineDebugger::is_active()) { EngineDebugger::get_singleton()->poll_events(false); + } #endif exit(mono_environment_exitcode_get()); @@ -1271,7 +1304,7 @@ GDMono::~GDMono() { // Leave the rest to 'mono_jit_cleanup' #endif - const uint32_t *k = nullptr; + const int32_t *k = nullptr; while ((k = assemblies.next(k))) { HashMap<String, GDMonoAssembly *> &domain_assemblies = assemblies.get(*k); @@ -1295,8 +1328,9 @@ GDMono::~GDMono() { gdmono::android::support::cleanup(); #endif - if (gdmono_log) + if (gdmono_log) { memdelete(gdmono_log); + } singleton = nullptr; } @@ -1313,37 +1347,44 @@ void _GodotSharp::detach_thread() { int32_t _GodotSharp::get_domain_id() { MonoDomain *domain = mono_domain_get(); - CRASH_COND(!domain); // User must check if runtime is initialized before calling this method + ERR_FAIL_NULL_V(domain, -1); return mono_domain_get_id(domain); } int32_t _GodotSharp::get_scripts_domain_id() { + ERR_FAIL_NULL_V_MSG(GDMono::get_singleton(), + -1, "The Mono runtime is not initialized"); MonoDomain *domain = GDMono::get_singleton()->get_scripts_domain(); - CRASH_COND(!domain); // User must check if scripts domain is loaded before calling this method + ERR_FAIL_NULL_V(domain, -1); return mono_domain_get_id(domain); } bool _GodotSharp::is_scripts_domain_loaded() { - return GDMono::get_singleton()->is_runtime_initialized() && GDMono::get_singleton()->get_scripts_domain() != nullptr; + return GDMono::get_singleton() != nullptr && + GDMono::get_singleton()->is_runtime_initialized() && + GDMono::get_singleton()->get_scripts_domain() != nullptr; } bool _GodotSharp::_is_domain_finalizing_for_unload(int32_t p_domain_id) { return is_domain_finalizing_for_unload(p_domain_id); } -bool _GodotSharp::is_domain_finalizing_for_unload() { - return is_domain_finalizing_for_unload(mono_domain_get()); -} - bool _GodotSharp::is_domain_finalizing_for_unload(int32_t p_domain_id) { return is_domain_finalizing_for_unload(mono_domain_get_by_id(p_domain_id)); } bool _GodotSharp::is_domain_finalizing_for_unload(MonoDomain *p_domain) { - if (!p_domain) - return true; - if (p_domain == GDMono::get_singleton()->get_scripts_domain() && GDMono::get_singleton()->is_finalizing_scripts_domain()) + GDMono *gd_mono = GDMono::get_singleton(); + + ERR_FAIL_COND_V_MSG(!gd_mono || !gd_mono->is_runtime_initialized(), + false, "The Mono runtime is not initialized"); + + ERR_FAIL_NULL_V(p_domain, true); + + if (p_domain == gd_mono->get_scripts_domain() && gd_mono->is_finalizing_scripts_domain()) { return true; + } + return mono_domain_is_unloading(p_domain); } @@ -1352,15 +1393,17 @@ bool _GodotSharp::is_runtime_shutting_down() { } bool _GodotSharp::is_runtime_initialized() { - return GDMono::get_singleton()->is_runtime_initialized(); + return GDMono::get_singleton() != nullptr && GDMono::get_singleton()->is_runtime_initialized(); } void _GodotSharp::_reload_assemblies(bool p_soft_reload) { #ifdef GD_MONO_HOT_RELOAD + CRASH_COND(CSharpLanguage::get_singleton() == nullptr); // This method may be called more than once with `call_deferred`, so we need to check // again if reloading is needed to avoid reloading multiple times unnecessarily. - if (CSharpLanguage::get_singleton()->is_assembly_reloading_needed()) + if (CSharpLanguage::get_singleton()->is_assembly_reloading_needed()) { CSharpLanguage::get_singleton()->reload_assemblies(p_soft_reload); + } #endif } diff --git a/modules/mono/mono_gd/gd_mono.h b/modules/mono/mono_gd/gd_mono.h index 833855b371..18f7418049 100644 --- a/modules/mono/mono_gd/gd_mono.h +++ b/modules/mono/mono_gd/gd_mono.h @@ -97,7 +97,7 @@ private: MonoDomain *root_domain; MonoDomain *scripts_domain; - HashMap<uint32_t, HashMap<String, GDMonoAssembly *>> assemblies; + HashMap<int32_t, HashMap<String, GDMonoAssembly *>> assemblies; GDMonoAssembly *corlib_assembly; GDMonoAssembly *project_assembly; @@ -141,7 +141,7 @@ private: Error _unload_scripts_domain(); #endif - void _domain_assemblies_cleanup(uint32_t p_domain_id); + void _domain_assemblies_cleanup(int32_t p_domain_id); uint64_t api_core_hash; #ifdef TOOLS_ENABLED @@ -165,14 +165,16 @@ protected: public: #ifdef DEBUG_METHODS_ENABLED uint64_t get_api_core_hash() { - if (api_core_hash == 0) + if (api_core_hash == 0) { api_core_hash = ClassDB::get_api_hash(ClassDB::API_CORE); + } return api_core_hash; } #ifdef TOOLS_ENABLED uint64_t get_api_editor_hash() { - if (api_editor_hash == 0) + if (api_editor_hash == 0) { api_editor_hash = ClassDB::get_api_hash(ClassDB::API_EDITOR); + } return api_editor_hash; } #endif // TOOLS_ENABLED @@ -202,7 +204,7 @@ public: UnhandledExceptionPolicy get_unhandled_exception_policy() const { return unhandled_exception_policy; } // Do not use these, unless you know what you're doing - void add_assembly(uint32_t p_domain_id, GDMonoAssembly *p_assembly); + void add_assembly(int32_t p_domain_id, GDMonoAssembly *p_assembly); GDMonoAssembly *get_loaded_assembly(const String &p_name); _FORCE_INLINE_ bool is_runtime_initialized() const { return runtime_initialized && !mono_runtime_is_shutting_down() /* stays true after shutdown finished */; } @@ -252,18 +254,18 @@ class ScopeDomain { public: ScopeDomain(MonoDomain *p_domain) { - MonoDomain *prev_domain = mono_domain_get(); + prev_domain = mono_domain_get(); if (prev_domain != p_domain) { - this->prev_domain = prev_domain; mono_domain_set(p_domain, false); } else { - this->prev_domain = nullptr; + prev_domain = nullptr; } } ~ScopeDomain() { - if (prev_domain) + if (prev_domain) { mono_domain_set(prev_domain, false); + } } }; @@ -276,8 +278,9 @@ public: } ~ScopeExitDomainUnload() { - if (domain) + if (domain) { GDMono::get_singleton()->finalize_and_unload_domain(domain); + } } }; @@ -298,9 +301,6 @@ class _GodotSharp : public Object { bool _is_domain_finalizing_for_unload(int32_t p_domain_id); - List<NodePath *> np_delete_queue; - List<RID *> rid_delete_queue; - void _reload_assemblies(bool p_soft_reload); protected: @@ -318,7 +318,6 @@ public: bool is_scripts_domain_loaded(); - bool is_domain_finalizing_for_unload(); bool is_domain_finalizing_for_unload(int32_t p_domain_id); bool is_domain_finalizing_for_unload(MonoDomain *p_domain); diff --git a/modules/mono/mono_gd/gd_mono_assembly.cpp b/modules/mono/mono_gd/gd_mono_assembly.cpp index 073c9a5214..a170fd36e7 100644 --- a/modules/mono/mono_gd/gd_mono_assembly.cpp +++ b/modules/mono/mono_gd/gd_mono_assembly.cpp @@ -108,8 +108,9 @@ void GDMonoAssembly::assembly_load_hook(MonoAssembly *assembly, [[maybe_unused]] #ifdef GD_MONO_HOT_RELOAD const char *path = mono_image_get_filename(image); - if (FileAccess::exists(path)) + if (FileAccess::exists(path)) { gdassembly->modified_time = FileAccess::get_modified_time(path); + } #endif MonoDomain *domain = mono_domain_get(); @@ -137,8 +138,9 @@ MonoAssembly *GDMonoAssembly::_search_hook(MonoAssemblyName *aname, [[maybe_unus bool has_extension = name.ends_with(".dll") || name.ends_with(".exe"); GDMonoAssembly *loaded_asm = GDMono::get_singleton()->get_loaded_assembly(has_extension ? name.get_basename() : name); - if (loaded_asm) + if (loaded_asm) { return loaded_asm->get_assembly(); + } return nullptr; } @@ -161,22 +163,25 @@ MonoAssembly *GDMonoAssembly::_load_assembly_search(const String &p_name, MonoAs path = search_dir.plus_file(p_name); if (FileAccess::exists(path)) { res = _real_load_assembly_from(path, p_refonly, p_aname); - if (res != nullptr) + if (res != nullptr) { return res; + } } } else { path = search_dir.plus_file(p_name + ".dll"); if (FileAccess::exists(path)) { res = _real_load_assembly_from(path, p_refonly, p_aname); - if (res != nullptr) + if (res != nullptr) { return res; + } } path = search_dir.plus_file(p_name + ".exe"); if (FileAccess::exists(path)) { res = _real_load_assembly_from(path, p_refonly, p_aname); - if (res != nullptr) + if (res != nullptr) { return res; + } } } } @@ -194,16 +199,19 @@ String GDMonoAssembly::find_assembly(const String &p_name) { if (has_extension) { path = search_dir.plus_file(p_name); - if (FileAccess::exists(path)) + if (FileAccess::exists(path)) { return path; + } } else { path = search_dir.plus_file(p_name + ".dll"); - if (FileAccess::exists(path)) + if (FileAccess::exists(path)) { return path; + } path = search_dir.plus_file(p_name + ".exe"); - if (FileAccess::exists(path)) + if (FileAccess::exists(path)) { return path; + } } } @@ -279,8 +287,9 @@ MonoAssembly *GDMonoAssembly::_real_load_assembly_from(const String &p_path, boo if (!FileAccess::exists(pdb_path)) { pdb_path = p_path.get_basename() + ".pdb"; // without .dll - if (!FileAccess::exists(pdb_path)) + if (!FileAccess::exists(pdb_path)) { goto no_pdb; + } } pdb_data = FileAccess::get_file_as_array(pdb_path); @@ -307,8 +316,9 @@ no_pdb: String name = String::utf8(mono_assembly_name_get_name(mono_assembly_get_name(assembly))); bool has_extension = name.ends_with(".dll") || name.ends_with(".exe"); GDMonoAssembly *loaded_asm = GDMono::get_singleton()->get_loaded_assembly(has_extension ? name.get_basename() : name); - if (!loaded_asm) + if (!loaded_asm) { assembly_load_hook(assembly, nullptr); + } } // Decrement refcount which was previously incremented by mono_image_open_from_data_with_name @@ -342,13 +352,15 @@ GDMonoClass *GDMonoAssembly::get_class(const StringName &p_namespace, const Stri GDMonoClass **match = cached_classes.getptr(key); - if (match) + if (match) { return *match; + } MonoClass *mono_class = mono_class_from_name(image, String(p_namespace).utf8(), String(p_name).utf8()); - if (!mono_class) + if (!mono_class) { return nullptr; + } GDMonoClass *wrapped_class = memnew(GDMonoClass(p_namespace, p_name, mono_class, this)); @@ -363,8 +375,9 @@ GDMonoClass *GDMonoAssembly::get_class(MonoClass *p_mono_class) { Map<MonoClass *, GDMonoClass *>::Element *match = cached_raw.find(p_mono_class); - if (match) + if (match) { return match->value(); + } StringName namespace_name = mono_class_get_namespace(p_mono_class); StringName class_name = mono_class_get_name(p_mono_class); @@ -383,8 +396,9 @@ GDMonoClass *GDMonoAssembly::get_object_derived_class(const StringName &p_class) if (gdobject_class_cache_updated) { Map<StringName, GDMonoClass *>::Element *result = gdobject_class_cache.find(p_class); - if (result) + if (result) { match = result->get(); + } } else { List<GDMonoClass *> nested_classes; @@ -393,18 +407,21 @@ GDMonoClass *GDMonoAssembly::get_object_derived_class(const StringName &p_class) for (int i = 1; i < rows; i++) { MonoClass *mono_class = mono_class_get(image, (i + 1) | MONO_TOKEN_TYPE_DEF); - if (!mono_class_is_assignable_from(CACHED_CLASS_RAW(GodotObject), mono_class)) + if (!mono_class_is_assignable_from(CACHED_CLASS_RAW(GodotObject), mono_class)) { continue; + } GDMonoClass *current = get_class(mono_class); - if (!current) + if (!current) { continue; + } nested_classes.push_back(current); - if (!match && current->get_name() == p_class) + if (!match && current->get_name() == p_class) { match = current; + } while (!nested_classes.empty()) { GDMonoClass *current_nested = nested_classes.front()->get(); @@ -415,8 +432,9 @@ GDMonoClass *GDMonoAssembly::get_object_derived_class(const StringName &p_class) while (true) { MonoClass *raw_nested = mono_class_get_nested_types(current_nested->get_mono_ptr(), &iter); - if (!raw_nested) + if (!raw_nested) { break; + } GDMonoClass *nested_class = get_class(raw_nested); @@ -437,8 +455,9 @@ GDMonoClass *GDMonoAssembly::get_object_derived_class(const StringName &p_class) } GDMonoAssembly *GDMonoAssembly::load(const String &p_name, MonoAssemblyName *p_aname, bool p_refonly, const Vector<String> &p_search_dirs) { - if (GDMono::get_singleton()->get_corlib_assembly() && (p_name == "mscorlib" || p_name == "mscorlib.dll")) + if (GDMono::get_singleton()->get_corlib_assembly() && (p_name == "mscorlib" || p_name == "mscorlib.dll")) { return GDMono::get_singleton()->get_corlib_assembly(); + } // We need to manually call the search hook in this case, as it won't be called in the next step MonoAssembly *assembly = mono_assembly_invoke_search_hook(p_aname); @@ -456,8 +475,9 @@ GDMonoAssembly *GDMonoAssembly::load(const String &p_name, MonoAssemblyName *p_a } GDMonoAssembly *GDMonoAssembly::load_from(const String &p_name, const String &p_path, bool p_refonly) { - if (p_name == "mscorlib" || p_name == "mscorlib.dll") + if (p_name == "mscorlib" || p_name == "mscorlib.dll") { return GDMono::get_singleton()->get_corlib_assembly(); + } // We need to manually call the search hook in this case, as it won't be called in the next step MonoAssemblyName *aname = mono_assembly_name_new(p_name.utf8()); @@ -477,6 +497,7 @@ GDMonoAssembly *GDMonoAssembly::load_from(const String &p_name, const String &p_ } GDMonoAssembly::~GDMonoAssembly() { - if (image) + if (image) { unload(); + } } diff --git a/modules/mono/mono_gd/gd_mono_cache.cpp b/modules/mono/mono_gd/gd_mono_cache.cpp index c002ad2139..29aef6e609 100644 --- a/modules/mono/mono_gd/gd_mono_cache.cpp +++ b/modules/mono/mono_gd/gd_mono_cache.cpp @@ -217,7 +217,7 @@ void update_corlib_cache() { CACHE_METHOD_AND_CHECK(System_Diagnostics_StackTrace, ctor_Exception_bool, CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_with_desc("System.Diagnostics.StackTrace:.ctor(System.Exception,bool)", true)); #endif - CACHE_METHOD_THUNK_AND_CHECK(Delegate, Equals, GDMono::get_singleton()->get_corlib_assembly()->get_class("System", "Delegate")->get_method_with_desc("System.Delegate:Equals(object)", 1)); + CACHE_METHOD_THUNK_AND_CHECK(Delegate, Equals, GDMono::get_singleton()->get_corlib_assembly()->get_class("System", "Delegate")->get_method_with_desc("System.Delegate:Equals(object)", true)); CACHE_CLASS_AND_CHECK(KeyNotFoundException, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections.Generic", "KeyNotFoundException")); diff --git a/modules/mono/mono_gd/gd_mono_class.cpp b/modules/mono/mono_gd/gd_mono_class.cpp index 691da55b10..6575cbc1c8 100644 --- a/modules/mono/mono_gd/gd_mono_class.cpp +++ b/modules/mono/mono_gd/gd_mono_class.cpp @@ -81,15 +81,17 @@ bool GDMonoClass::is_assignable_from(GDMonoClass *p_from) const { StringName GDMonoClass::get_namespace() const { GDMonoClass *nesting_class = get_nesting_class(); - if (!nesting_class) + if (!nesting_class) { return namespace_name; + } return nesting_class->get_namespace(); } String GDMonoClass::get_name_for_lookup() const { GDMonoClass *nesting_class = get_nesting_class(); - if (!nesting_class) + if (!nesting_class) { return class_name; + } return nesting_class->get_name_for_lookup() + "/" + class_name; } @@ -131,11 +133,13 @@ bool GDMonoClass::has_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, false); #endif - if (!attrs_fetched) + if (!attrs_fetched) { fetch_attributes(); + } - if (!attributes) + if (!attributes) { return false; + } return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr()); } @@ -145,11 +149,13 @@ MonoObject *GDMonoClass::get_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, nullptr); #endif - if (!attrs_fetched) + if (!attrs_fetched) { fetch_attributes(); + } - if (!attributes) + if (!attributes) { return nullptr; + } return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr()); } @@ -164,8 +170,9 @@ void GDMonoClass::fetch_attributes() { void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base) { CRASH_COND(!CACHED_CLASS(GodotObject)->is_assignable_from(this)); - if (methods_fetched) + if (methods_fetched) { return; + } void *iter = nullptr; MonoMethod *raw_method = nullptr; @@ -202,8 +209,9 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base break; } - if (native_top == CACHED_CLASS(GodotObject)) + if (native_top == CACHED_CLASS(GodotObject)) { break; + } native_top = native_top->get_parent_class(); } @@ -212,8 +220,9 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base uint32_t flags = mono_method_get_flags(method->mono_method, nullptr); - if (!(flags & MONO_METHOD_ATTR_VIRTUAL)) + if (!(flags & MONO_METHOD_ATTR_VIRTUAL)) { continue; + } // Virtual method of Godot Object derived type, let's try to find GodotMethod attribute @@ -235,15 +244,17 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base #endif MethodKey key = MethodKey(godot_method_name, method->get_parameters_count()); GDMonoMethod **existing_method = methods.getptr(key); - if (existing_method) + if (existing_method) { memdelete(*existing_method); // Must delete old one + } methods.set(key, method); break; } - if (top == CACHED_CLASS(GodotObject)) + if (top == CACHED_CLASS(GodotObject)) { break; + } top = top->get_parent_class(); } @@ -258,8 +269,9 @@ GDMonoMethod *GDMonoClass::get_fetched_method_unknown_params(const StringName &p const MethodKey *k = nullptr; while ((k = methods.next(k))) { - if (k->name == p_name) + if (k->name == p_name) { return methods.get(*k); + } } return nullptr; @@ -283,11 +295,13 @@ GDMonoMethod *GDMonoClass::get_method(const StringName &p_name, int p_params_cou GDMonoMethod **match = methods.getptr(key); - if (match) + if (match) { return *match; + } - if (methods_fetched) + if (methods_fetched) { return nullptr; + } MonoMethod *raw_method = mono_class_get_method_from_name(mono_class, String(p_name).utf8().get_data(), p_params_count); @@ -323,8 +337,9 @@ GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method, const StringName GDMonoMethod **match = methods.getptr(key); - if (match) + if (match) { return *match; + } GDMonoMethod *method = memnew(GDMonoMethod(p_name, p_raw_method)); methods.set(key, method); @@ -337,8 +352,9 @@ GDMonoMethod *GDMonoClass::get_method_with_desc(const String &p_description, boo MonoMethod *method = mono_method_desc_search_in_class(desc, mono_class); mono_method_desc_free(desc); - if (!method) + if (!method) { return nullptr; + } ERR_FAIL_COND_V(mono_method_get_class(method) != mono_class, nullptr); @@ -348,11 +364,13 @@ GDMonoMethod *GDMonoClass::get_method_with_desc(const String &p_description, boo GDMonoField *GDMonoClass::get_field(const StringName &p_name) { Map<StringName, GDMonoField *>::Element *result = fields.find(p_name); - if (result) + if (result) { return result->value(); + } - if (fields_fetched) + if (fields_fetched) { return nullptr; + } MonoClassField *raw_field = mono_class_get_field_from_name(mono_class, String(p_name).utf8().get_data()); @@ -367,8 +385,9 @@ GDMonoField *GDMonoClass::get_field(const StringName &p_name) { } const Vector<GDMonoField *> &GDMonoClass::get_all_fields() { - if (fields_fetched) + if (fields_fetched) { return fields_list; + } void *iter = nullptr; MonoClassField *raw_field = nullptr; @@ -394,11 +413,13 @@ const Vector<GDMonoField *> &GDMonoClass::get_all_fields() { GDMonoProperty *GDMonoClass::get_property(const StringName &p_name) { Map<StringName, GDMonoProperty *>::Element *result = properties.find(p_name); - if (result) + if (result) { return result->value(); + } - if (properties_fetched) + if (properties_fetched) { return nullptr; + } MonoProperty *raw_property = mono_class_get_property_from_name(mono_class, String(p_name).utf8().get_data()); @@ -413,8 +434,9 @@ GDMonoProperty *GDMonoClass::get_property(const StringName &p_name) { } const Vector<GDMonoProperty *> &GDMonoClass::get_all_properties() { - if (properties_fetched) + if (properties_fetched) { return properties_list; + } void *iter = nullptr; MonoProperty *raw_property = nullptr; @@ -438,8 +460,9 @@ const Vector<GDMonoProperty *> &GDMonoClass::get_all_properties() { } const Vector<GDMonoClass *> &GDMonoClass::get_all_delegates() { - if (delegates_fetched) + if (delegates_fetched) { return delegates_list; + } void *iter = nullptr; MonoClass *raw_class = nullptr; diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp index 948170f51c..563c45e71f 100644 --- a/modules/mono/mono_gd/gd_mono_field.cpp +++ b/modules/mono/mono_gd/gd_mono_field.cpp @@ -597,11 +597,13 @@ String GDMonoField::get_string_value(MonoObject *p_object) { bool GDMonoField::has_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, false); - if (!attrs_fetched) + if (!attrs_fetched) { fetch_attributes(); + } - if (!attributes) + if (!attributes) { return false; + } return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr()); } @@ -609,11 +611,13 @@ bool GDMonoField::has_attribute(GDMonoClass *p_attr_class) { MonoObject *GDMonoField::get_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, nullptr); - if (!attrs_fetched) + if (!attrs_fetched) { fetch_attributes(); + } - if (!attributes) + if (!attributes) { return nullptr; + } return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr()); } diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index abb2761909..fe1c2d28dd 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -122,9 +122,10 @@ void unhandled_exception(MonoException *p_exc) { GD_UNREACHABLE(); } else { #ifdef DEBUG_ENABLED - GDMonoUtils::debug_send_unhandled_exception_error((MonoException *)p_exc); - if (EngineDebugger::is_active()) + GDMonoUtils::debug_send_unhandled_exception_error(p_exc); + if (EngineDebugger::is_active()) { EngineDebugger::get_singleton()->poll_events(false); + } #endif } } diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp index 04728be725..c5a988b8c3 100644 --- a/modules/mono/mono_gd/gd_mono_log.cpp +++ b/modules/mono/mono_gd/gd_mono_log.cpp @@ -55,8 +55,9 @@ static int get_log_level_id(const char *p_log_level) { int i = 0; while (valid_log_levels[i]) { - if (!strcmp(valid_log_levels[i], p_log_level)) + if (!strcmp(valid_log_levels[i], p_log_level)) { return i; + } i++; } @@ -115,10 +116,12 @@ void GDMonoLog::_delete_old_log_files(const String &p_logs_dir) { String current; while ((current = da->get_next()).length()) { - if (da->current_is_dir()) + if (da->current_is_dir()) { continue; - if (!current.ends_with(".txt")) + } + if (!current.ends_with(".txt")) { continue; + } uint64_t modified_time = FileAccess::get_modified_time(da->get_current_dir().plus_file(current)); diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 92734a0792..6d7d5f76cd 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -72,92 +72,119 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type, bool *r_nil_is_ case MONO_TYPE_VALUETYPE: { GDMonoClass *vtclass = p_type.type_class; - if (vtclass == CACHED_CLASS(Vector2)) + if (vtclass == CACHED_CLASS(Vector2)) { return Variant::VECTOR2; + } - if (vtclass == CACHED_CLASS(Vector2i)) + if (vtclass == CACHED_CLASS(Vector2i)) { return Variant::VECTOR2I; + } - if (vtclass == CACHED_CLASS(Rect2)) + if (vtclass == CACHED_CLASS(Rect2)) { return Variant::RECT2; + } - if (vtclass == CACHED_CLASS(Rect2i)) + if (vtclass == CACHED_CLASS(Rect2i)) { return Variant::RECT2I; + } - if (vtclass == CACHED_CLASS(Transform2D)) + if (vtclass == CACHED_CLASS(Transform2D)) { return Variant::TRANSFORM2D; + } - if (vtclass == CACHED_CLASS(Vector3)) + if (vtclass == CACHED_CLASS(Vector3)) { return Variant::VECTOR3; + } - if (vtclass == CACHED_CLASS(Vector3i)) + if (vtclass == CACHED_CLASS(Vector3i)) { return Variant::VECTOR3I; + } - if (vtclass == CACHED_CLASS(Basis)) + if (vtclass == CACHED_CLASS(Basis)) { return Variant::BASIS; + } - if (vtclass == CACHED_CLASS(Quat)) + if (vtclass == CACHED_CLASS(Quat)) { return Variant::QUAT; + } - if (vtclass == CACHED_CLASS(Transform)) + if (vtclass == CACHED_CLASS(Transform)) { return Variant::TRANSFORM; + } - if (vtclass == CACHED_CLASS(AABB)) + if (vtclass == CACHED_CLASS(AABB)) { return Variant::AABB; + } - if (vtclass == CACHED_CLASS(Color)) + if (vtclass == CACHED_CLASS(Color)) { return Variant::COLOR; + } - if (vtclass == CACHED_CLASS(Plane)) + if (vtclass == CACHED_CLASS(Plane)) { return Variant::PLANE; + } - if (vtclass == CACHED_CLASS(Callable)) + if (vtclass == CACHED_CLASS(Callable)) { return Variant::CALLABLE; + } - if (vtclass == CACHED_CLASS(SignalInfo)) + if (vtclass == CACHED_CLASS(SignalInfo)) { return Variant::SIGNAL; + } - if (mono_class_is_enum(vtclass->get_mono_ptr())) + if (mono_class_is_enum(vtclass->get_mono_ptr())) { return Variant::INT; + } } break; case MONO_TYPE_ARRAY: case MONO_TYPE_SZARRAY: { MonoArrayType *array_type = mono_type_get_array_type(p_type.type_class->get_mono_type()); - if (array_type->eklass == CACHED_CLASS_RAW(MonoObject)) + if (array_type->eklass == CACHED_CLASS_RAW(MonoObject)) { return Variant::ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) + if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) { return Variant::PACKED_BYTE_ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) + if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) { return Variant::PACKED_INT32_ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(int64_t)) + if (array_type->eklass == CACHED_CLASS_RAW(int64_t)) { return Variant::PACKED_INT64_ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(float)) + if (array_type->eklass == CACHED_CLASS_RAW(float)) { return Variant::PACKED_FLOAT32_ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(double)) + if (array_type->eklass == CACHED_CLASS_RAW(double)) { return Variant::PACKED_FLOAT64_ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(String)) + if (array_type->eklass == CACHED_CLASS_RAW(String)) { return Variant::PACKED_STRING_ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) + if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) { return Variant::PACKED_VECTOR2_ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) + if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) { return Variant::PACKED_VECTOR3_ARRAY; + } - if (array_type->eklass == CACHED_CLASS_RAW(Color)) + if (array_type->eklass == CACHED_CLASS_RAW(Color)) { return Variant::PACKED_COLOR_ARRAY; + } GDMonoClass *array_type_class = GDMono::get_singleton()->get_class(array_type->eklass); - if (CACHED_CLASS(GodotObject)->is_assignable_from(array_type_class)) + if (CACHED_CLASS(GodotObject)->is_assignable_from(array_type_class)) { return Variant::ARRAY; + } } break; case MONO_TYPE_CLASS: { @@ -201,8 +228,9 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type, bool *r_nil_is_ } break; case MONO_TYPE_OBJECT: { - if (r_nil_is_variant) + if (r_nil_is_variant) { *r_nil_is_variant = true; + } return Variant::NIL; } break; @@ -244,8 +272,9 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type, bool *r_nil_is_ } break; } - if (r_nil_is_variant) + if (r_nil_is_variant) { *r_nil_is_variant = false; + } // Unknown return Variant::NIL; @@ -282,31 +311,6 @@ bool try_get_array_element_type(const ManagedType &p_array_type, ManagedType &r_ return false; } -bool try_get_dictionary_key_value_types(const ManagedType &p_dictionary_type, ManagedType &r_key_type, ManagedType &r_value_type) { - switch (p_dictionary_type.type_encoding) { - case MONO_TYPE_GENERICINST: { - MonoReflectionType *dict_reftype = mono_type_get_object(mono_domain_get(), p_dictionary_type.type_class->get_mono_type()); - - if (GDMonoUtils::Marshal::type_is_generic_dictionary(dict_reftype) || - GDMonoUtils::Marshal::type_is_system_generic_dictionary(dict_reftype) || - GDMonoUtils::Marshal::type_is_generic_idictionary(dict_reftype)) { - MonoReflectionType *key_reftype; - MonoReflectionType *value_reftype; - - GDMonoUtils::Marshal::dictionary_get_key_value_types(dict_reftype, &key_reftype, &value_reftype); - - r_key_type = ManagedType::from_reftype(key_reftype); - r_value_type = ManagedType::from_reftype(value_reftype); - return true; - } - } break; - default: { - } break; - } - - return false; -} - String mono_to_utf8_string(MonoString *p_mono_string) { MonoError error; char *utf8 = mono_string_to_utf8_checked(p_mono_string, &error); @@ -328,8 +332,9 @@ String mono_to_utf16_string(MonoString *p_mono_string) { int len = mono_string_length(p_mono_string); String ret; - if (len == 0) + if (len == 0) { return ret; + } ret.resize(len + 1); ret.set(len, 0); @@ -409,8 +414,9 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty } case MONO_TYPE_STRING: { - if (p_var->get_type() == Variant::NIL) + if (p_var->get_type() == Variant::NIL) { return nullptr; // Otherwise, Variant -> String would return the string "Null" + } return (MonoObject *)mono_string_from_godot(p_var->operator String()); } break; @@ -547,39 +553,50 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty case MONO_TYPE_SZARRAY: { MonoArrayType *array_type = mono_type_get_array_type(p_type.type_class->get_mono_type()); - if (array_type->eklass == CACHED_CLASS_RAW(MonoObject)) + if (array_type->eklass == CACHED_CLASS_RAW(MonoObject)) { return (MonoObject *)Array_to_mono_array(p_var->operator Array()); + } - if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) + if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) { return (MonoObject *)PackedByteArray_to_mono_array(p_var->operator PackedByteArray()); + } - if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) + if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) { return (MonoObject *)PackedInt32Array_to_mono_array(p_var->operator PackedInt32Array()); + } - if (array_type->eklass == CACHED_CLASS_RAW(int64_t)) + if (array_type->eklass == CACHED_CLASS_RAW(int64_t)) { return (MonoObject *)PackedInt64Array_to_mono_array(p_var->operator PackedInt64Array()); + } - if (array_type->eklass == CACHED_CLASS_RAW(float)) + if (array_type->eklass == CACHED_CLASS_RAW(float)) { return (MonoObject *)PackedFloat32Array_to_mono_array(p_var->operator PackedFloat32Array()); + } - if (array_type->eklass == CACHED_CLASS_RAW(double)) + if (array_type->eklass == CACHED_CLASS_RAW(double)) { return (MonoObject *)PackedFloat64Array_to_mono_array(p_var->operator PackedFloat64Array()); + } - if (array_type->eklass == CACHED_CLASS_RAW(String)) + if (array_type->eklass == CACHED_CLASS_RAW(String)) { return (MonoObject *)PackedStringArray_to_mono_array(p_var->operator PackedStringArray()); + } - if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) + if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) { return (MonoObject *)PackedVector2Array_to_mono_array(p_var->operator PackedVector2Array()); + } - if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) + if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) { return (MonoObject *)PackedVector3Array_to_mono_array(p_var->operator PackedVector3Array()); + } - if (array_type->eklass == CACHED_CLASS_RAW(Color)) + if (array_type->eklass == CACHED_CLASS_RAW(Color)) { return (MonoObject *)PackedColorArray_to_mono_array(p_var->operator PackedColorArray()); + } GDMonoClass *array_type_class = GDMono::get_singleton()->get_class(array_type->eklass); - if (CACHED_CLASS(GodotObject)->is_assignable_from(array_type_class)) + if (CACHED_CLASS(GodotObject)->is_assignable_from(array_type_class)) { return (MonoObject *)Array_to_mono_array(p_var->operator Array(), array_type_class); + } ERR_FAIL_V_MSG(nullptr, "Attempted to convert Variant to a managed array of unmarshallable element type."); } break; @@ -820,100 +837,128 @@ Variant mono_object_to_variant_impl(MonoObject *p_obj, const ManagedType &p_type return unbox<double>(p_obj); case MONO_TYPE_STRING: { - if (p_obj == nullptr) + if (p_obj == nullptr) { return Variant(); // NIL + } return mono_string_to_godot_not_null((MonoString *)p_obj); } break; case MONO_TYPE_VALUETYPE: { GDMonoClass *vtclass = p_type.type_class; - if (vtclass == CACHED_CLASS(Vector2)) + if (vtclass == CACHED_CLASS(Vector2)) { return MARSHALLED_IN(Vector2, unbox_addr<GDMonoMarshal::M_Vector2>(p_obj)); + } - if (vtclass == CACHED_CLASS(Vector2i)) + if (vtclass == CACHED_CLASS(Vector2i)) { return MARSHALLED_IN(Vector2i, unbox_addr<GDMonoMarshal::M_Vector2i>(p_obj)); + } - if (vtclass == CACHED_CLASS(Rect2)) + if (vtclass == CACHED_CLASS(Rect2)) { return MARSHALLED_IN(Rect2, unbox_addr<GDMonoMarshal::M_Rect2>(p_obj)); + } - if (vtclass == CACHED_CLASS(Rect2i)) + if (vtclass == CACHED_CLASS(Rect2i)) { return MARSHALLED_IN(Rect2i, unbox_addr<GDMonoMarshal::M_Rect2i>(p_obj)); + } - if (vtclass == CACHED_CLASS(Transform2D)) + if (vtclass == CACHED_CLASS(Transform2D)) { return MARSHALLED_IN(Transform2D, unbox_addr<GDMonoMarshal::M_Transform2D>(p_obj)); + } - if (vtclass == CACHED_CLASS(Vector3)) + if (vtclass == CACHED_CLASS(Vector3)) { return MARSHALLED_IN(Vector3, unbox_addr<GDMonoMarshal::M_Vector3>(p_obj)); + } - if (vtclass == CACHED_CLASS(Vector3i)) + if (vtclass == CACHED_CLASS(Vector3i)) { return MARSHALLED_IN(Vector3i, unbox_addr<GDMonoMarshal::M_Vector3i>(p_obj)); + } - if (vtclass == CACHED_CLASS(Basis)) + if (vtclass == CACHED_CLASS(Basis)) { return MARSHALLED_IN(Basis, unbox_addr<GDMonoMarshal::M_Basis>(p_obj)); + } - if (vtclass == CACHED_CLASS(Quat)) + if (vtclass == CACHED_CLASS(Quat)) { return MARSHALLED_IN(Quat, unbox_addr<GDMonoMarshal::M_Quat>(p_obj)); + } - if (vtclass == CACHED_CLASS(Transform)) + if (vtclass == CACHED_CLASS(Transform)) { return MARSHALLED_IN(Transform, unbox_addr<GDMonoMarshal::M_Transform>(p_obj)); + } - if (vtclass == CACHED_CLASS(AABB)) + if (vtclass == CACHED_CLASS(AABB)) { return MARSHALLED_IN(AABB, unbox_addr<GDMonoMarshal::M_AABB>(p_obj)); + } - if (vtclass == CACHED_CLASS(Color)) + if (vtclass == CACHED_CLASS(Color)) { return MARSHALLED_IN(Color, unbox_addr<GDMonoMarshal::M_Color>(p_obj)); + } - if (vtclass == CACHED_CLASS(Plane)) + if (vtclass == CACHED_CLASS(Plane)) { return MARSHALLED_IN(Plane, unbox_addr<GDMonoMarshal::M_Plane>(p_obj)); + } - if (vtclass == CACHED_CLASS(Callable)) + if (vtclass == CACHED_CLASS(Callable)) { return managed_to_callable(unbox<GDMonoMarshal::M_Callable>(p_obj)); + } - if (vtclass == CACHED_CLASS(SignalInfo)) + if (vtclass == CACHED_CLASS(SignalInfo)) { return managed_to_signal_info(unbox<GDMonoMarshal::M_SignalInfo>(p_obj)); + } - if (mono_class_is_enum(vtclass->get_mono_ptr())) + if (mono_class_is_enum(vtclass->get_mono_ptr())) { return unbox<int32_t>(p_obj); + } } break; case MONO_TYPE_ARRAY: case MONO_TYPE_SZARRAY: { MonoArrayType *array_type = mono_type_get_array_type(p_type.type_class->get_mono_type()); - if (array_type->eklass == CACHED_CLASS_RAW(MonoObject)) + if (array_type->eklass == CACHED_CLASS_RAW(MonoObject)) { return mono_array_to_Array((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) + if (array_type->eklass == CACHED_CLASS_RAW(uint8_t)) { return mono_array_to_PackedByteArray((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) + if (array_type->eklass == CACHED_CLASS_RAW(int32_t)) { return mono_array_to_PackedInt32Array((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(int64_t)) + if (array_type->eklass == CACHED_CLASS_RAW(int64_t)) { return mono_array_to_PackedInt64Array((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(float)) + if (array_type->eklass == CACHED_CLASS_RAW(float)) { return mono_array_to_PackedFloat32Array((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(double)) + if (array_type->eklass == CACHED_CLASS_RAW(double)) { return mono_array_to_PackedFloat64Array((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(String)) + if (array_type->eklass == CACHED_CLASS_RAW(String)) { return mono_array_to_PackedStringArray((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) + if (array_type->eklass == CACHED_CLASS_RAW(Vector2)) { return mono_array_to_PackedVector2Array((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) + if (array_type->eklass == CACHED_CLASS_RAW(Vector3)) { return mono_array_to_PackedVector3Array((MonoArray *)p_obj); + } - if (array_type->eklass == CACHED_CLASS_RAW(Color)) + if (array_type->eklass == CACHED_CLASS_RAW(Color)) { return mono_array_to_PackedColorArray((MonoArray *)p_obj); + } GDMonoClass *array_type_class = GDMono::get_singleton()->get_class(array_type->eklass); - if (CACHED_CLASS(GodotObject)->is_assignable_from(array_type_class)) + if (CACHED_CLASS(GodotObject)->is_assignable_from(array_type_class)) { return mono_array_to_Array((MonoArray *)p_obj); + } if (p_fail_with_err) { ERR_FAIL_V_MSG(Variant(), "Attempted to convert a managed array of unmarshallable element type to Variant."); @@ -1012,8 +1057,9 @@ Variant mono_object_to_variant_impl(MonoObject *p_obj, const ManagedType &p_type } Variant mono_object_to_variant(MonoObject *p_obj) { - if (!p_obj) + if (!p_obj) { return Variant(); + } ManagedType type = ManagedType::from_class(mono_object_get_class(p_obj)); @@ -1021,15 +1067,17 @@ Variant mono_object_to_variant(MonoObject *p_obj) { } Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) { - if (!p_obj) + if (!p_obj) { return Variant(); + } return mono_object_to_variant_impl(p_obj, p_type); } Variant mono_object_to_variant_no_err(MonoObject *p_obj, const ManagedType &p_type) { - if (!p_obj) + if (!p_obj) { return Variant(); + } return mono_object_to_variant_impl(p_obj, p_type, /* fail_with_err: */ false); } @@ -1048,8 +1096,9 @@ String mono_object_to_variant_string(MonoObject *p_obj, MonoException **r_exc) { MonoString *mono_str = GDMonoUtils::object_to_string(p_obj, &exc); if (exc) { - if (r_exc) + if (r_exc) { *r_exc = exc; + } return String(); } @@ -1159,8 +1208,9 @@ MonoArray *Array_to_mono_array(const Array &p_array, GDMonoClass *p_array_type_c Array mono_array_to_Array(MonoArray *p_array) { Array ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); @@ -1178,22 +1228,23 @@ MonoArray *PackedInt32Array_to_mono_array(const PackedInt32Array &p_array) { MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(int32_t), length); - int32_t *dst = (int32_t *)mono_array_addr(ret, int32_t, 0); - memcpy(dst, src, length); + int32_t *dst = mono_array_addr(ret, int32_t, 0); + memcpy(dst, src, length * sizeof(int32_t)); return ret; } PackedInt32Array mono_array_to_PackedInt32Array(MonoArray *p_array) { PackedInt32Array ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); int32_t *dst = ret.ptrw(); - const int32_t *src = (const int32_t *)mono_array_addr(p_array, int32_t, 0); - memcpy(dst, src, length); + const int32_t *src = mono_array_addr(p_array, int32_t, 0); + memcpy(dst, src, length * sizeof(int32_t)); return ret; } @@ -1204,22 +1255,23 @@ MonoArray *PackedInt64Array_to_mono_array(const PackedInt64Array &p_array) { MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(int64_t), length); - int64_t *dst = (int64_t *)mono_array_addr(ret, int64_t, 0); - memcpy(dst, src, length); + int64_t *dst = mono_array_addr(ret, int64_t, 0); + memcpy(dst, src, length * sizeof(int64_t)); return ret; } PackedInt64Array mono_array_to_PackedInt64Array(MonoArray *p_array) { PackedInt64Array ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); int64_t *dst = ret.ptrw(); - const int64_t *src = (const int64_t *)mono_array_addr(p_array, int64_t, 0); - memcpy(dst, src, length); + const int64_t *src = mono_array_addr(p_array, int64_t, 0); + memcpy(dst, src, length * sizeof(int64_t)); return ret; } @@ -1230,22 +1282,23 @@ MonoArray *PackedByteArray_to_mono_array(const PackedByteArray &p_array) { MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(uint8_t), length); - uint8_t *dst = (uint8_t *)mono_array_addr(ret, uint8_t, 0); - memcpy(dst, src, length); + uint8_t *dst = mono_array_addr(ret, uint8_t, 0); + memcpy(dst, src, length * sizeof(uint8_t)); return ret; } PackedByteArray mono_array_to_PackedByteArray(MonoArray *p_array) { PackedByteArray ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); uint8_t *dst = ret.ptrw(); - const uint8_t *src = (const uint8_t *)mono_array_addr(p_array, uint8_t, 0); - memcpy(dst, src, length); + const uint8_t *src = mono_array_addr(p_array, uint8_t, 0); + memcpy(dst, src, length * sizeof(uint8_t)); return ret; } @@ -1256,22 +1309,23 @@ MonoArray *PackedFloat32Array_to_mono_array(const PackedFloat32Array &p_array) { MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(float), length); - float *dst = (float *)mono_array_addr(ret, float, 0); - memcpy(dst, src, length); + float *dst = mono_array_addr(ret, float, 0); + memcpy(dst, src, length * sizeof(float)); return ret; } PackedFloat32Array mono_array_to_PackedFloat32Array(MonoArray *p_array) { PackedFloat32Array ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); float *dst = ret.ptrw(); - const float *src = (const float *)mono_array_addr(p_array, float, 0); - memcpy(dst, src, length); + const float *src = mono_array_addr(p_array, float, 0); + memcpy(dst, src, length * sizeof(float)); return ret; } @@ -1282,22 +1336,23 @@ MonoArray *PackedFloat64Array_to_mono_array(const PackedFloat64Array &p_array) { MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(double), length); - double *dst = (double *)mono_array_addr(ret, double, 0); - memcpy(dst, src, length); + double *dst = mono_array_addr(ret, double, 0); + memcpy(dst, src, length * sizeof(double)); return ret; } PackedFloat64Array mono_array_to_PackedFloat64Array(MonoArray *p_array) { PackedFloat64Array ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); double *dst = ret.ptrw(); - const double *src = (const double *)mono_array_addr(p_array, double, 0); - memcpy(dst, src, length); + const double *src = mono_array_addr(p_array, double, 0); + memcpy(dst, src, length * sizeof(double)); return ret; } @@ -1318,8 +1373,9 @@ MonoArray *PackedStringArray_to_mono_array(const PackedStringArray &p_array) { PackedStringArray mono_array_to_PackedStringArray(MonoArray *p_array) { PackedStringArray ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); String *w = ret.ptrw(); @@ -1339,8 +1395,8 @@ MonoArray *PackedColorArray_to_mono_array(const PackedColorArray &p_array) { MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(Color), length); if constexpr (InteropLayout::MATCHES_Color) { - Color *dst = (Color *)mono_array_addr(ret, Color, 0); - memcpy(dst, src, length); + Color *dst = mono_array_addr(ret, Color, 0); + memcpy(dst, src, length * sizeof(Color)); } else { for (int i = 0; i < length; i++) { M_Color *raw = (M_Color *)mono_array_addr_with_size(ret, sizeof(M_Color), i); @@ -1353,15 +1409,16 @@ MonoArray *PackedColorArray_to_mono_array(const PackedColorArray &p_array) { PackedColorArray mono_array_to_PackedColorArray(MonoArray *p_array) { PackedColorArray ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); Color *dst = ret.ptrw(); if constexpr (InteropLayout::MATCHES_Color) { - const Color *src = (const Color *)mono_array_addr(p_array, Color, 0); - memcpy(dst, src, length); + const Color *src = mono_array_addr(p_array, Color, 0); + memcpy(dst, src, length * sizeof(Color)); } else { for (int i = 0; i < length; i++) { dst[i] = MARSHALLED_IN(Color, (M_Color *)mono_array_addr_with_size(p_array, sizeof(M_Color), i)); @@ -1378,8 +1435,8 @@ MonoArray *PackedVector2Array_to_mono_array(const PackedVector2Array &p_array) { MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(Vector2), length); if constexpr (InteropLayout::MATCHES_Vector2) { - Vector2 *dst = (Vector2 *)mono_array_addr(ret, Vector2, 0); - memcpy(dst, src, length); + Vector2 *dst = mono_array_addr(ret, Vector2, 0); + memcpy(dst, src, length * sizeof(Vector2)); } else { for (int i = 0; i < length; i++) { M_Vector2 *raw = (M_Vector2 *)mono_array_addr_with_size(ret, sizeof(M_Vector2), i); @@ -1392,15 +1449,16 @@ MonoArray *PackedVector2Array_to_mono_array(const PackedVector2Array &p_array) { PackedVector2Array mono_array_to_PackedVector2Array(MonoArray *p_array) { PackedVector2Array ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); Vector2 *dst = ret.ptrw(); if constexpr (InteropLayout::MATCHES_Vector2) { - const Vector2 *src = (const Vector2 *)mono_array_addr(p_array, Vector2, 0); - memcpy(dst, src, length); + const Vector2 *src = mono_array_addr(p_array, Vector2, 0); + memcpy(dst, src, length * sizeof(Vector2)); } else { for (int i = 0; i < length; i++) { dst[i] = MARSHALLED_IN(Vector2, (M_Vector2 *)mono_array_addr_with_size(p_array, sizeof(M_Vector2), i)); @@ -1417,8 +1475,8 @@ MonoArray *PackedVector3Array_to_mono_array(const PackedVector3Array &p_array) { MonoArray *ret = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(Vector3), length); if constexpr (InteropLayout::MATCHES_Vector3) { - Vector3 *dst = (Vector3 *)mono_array_addr(ret, Vector3, 0); - memcpy(dst, src, length); + Vector3 *dst = mono_array_addr(ret, Vector3, 0); + memcpy(dst, src, length * sizeof(Vector3)); } else { for (int i = 0; i < length; i++) { M_Vector3 *raw = (M_Vector3 *)mono_array_addr_with_size(ret, sizeof(M_Vector3), i); @@ -1431,15 +1489,16 @@ MonoArray *PackedVector3Array_to_mono_array(const PackedVector3Array &p_array) { PackedVector3Array mono_array_to_PackedVector3Array(MonoArray *p_array) { PackedVector3Array ret; - if (!p_array) + if (!p_array) { return ret; + } int length = mono_array_length(p_array); ret.resize(length); Vector3 *dst = ret.ptrw(); if constexpr (InteropLayout::MATCHES_Vector3) { - const Vector3 *src = (const Vector3 *)mono_array_addr(p_array, Vector3, 0); - memcpy(dst, src, length); + const Vector3 *src = mono_array_addr(p_array, Vector3, 0); + memcpy(dst, src, length * sizeof(Vector3)); } else { for (int i = 0; i < length; i++) { dst[i] = MARSHALLED_IN(Vector3, (M_Vector3 *)mono_array_addr_with_size(p_array, sizeof(M_Vector3), i)); diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h index f2d887e6d6..4ff330fd43 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.h +++ b/modules/mono/mono_gd/gd_mono_marshal.h @@ -66,7 +66,6 @@ T *unbox_addr(MonoObject *p_obj) { Variant::Type managed_to_variant_type(const ManagedType &p_type, bool *r_nil_is_variant = nullptr); bool try_get_array_element_type(const ManagedType &p_array_type, ManagedType &r_elem_type); -bool try_get_dictionary_key_value_types(const ManagedType &p_dictionary_type, ManagedType &r_key_type, ManagedType &r_value_type); // String @@ -74,15 +73,17 @@ String mono_to_utf8_string(MonoString *p_mono_string); String mono_to_utf16_string(MonoString *p_mono_string); _FORCE_INLINE_ String mono_string_to_godot_not_null(MonoString *p_mono_string) { - if (sizeof(CharType) == 2) + if constexpr (sizeof(CharType) == 2) { return mono_to_utf16_string(p_mono_string); + } return mono_to_utf8_string(p_mono_string); } _FORCE_INLINE_ String mono_string_to_godot(MonoString *p_mono_string) { - if (p_mono_string == nullptr) + if (p_mono_string == nullptr) { return String(); + } return mono_string_to_godot_not_null(p_mono_string); } @@ -96,8 +97,9 @@ _FORCE_INLINE_ MonoString *mono_from_utf16_string(const String &p_string) { } _FORCE_INLINE_ MonoString *mono_string_from_godot(const String &p_string) { - if (sizeof(CharType) == 2) + if constexpr (sizeof(CharType) == 2) { return mono_from_utf16_string(p_string); + } return mono_from_utf8_string(p_string); } diff --git a/modules/mono/mono_gd/gd_mono_method.cpp b/modules/mono/mono_gd/gd_mono_method.cpp index e601bb12ad..04f3b25a70 100644 --- a/modules/mono/mono_gd/gd_mono_method.cpp +++ b/modules/mono/mono_gd/gd_mono_method.cpp @@ -155,11 +155,13 @@ MonoObject *GDMonoMethod::invoke_raw(MonoObject *p_object, void **p_params, Mono bool GDMonoMethod::has_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, false); - if (!attrs_fetched) + if (!attrs_fetched) { fetch_attributes(); + } - if (!attributes) + if (!attributes) { return false; + } return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr()); } @@ -167,11 +169,13 @@ bool GDMonoMethod::has_attribute(GDMonoClass *p_attr_class) { MonoObject *GDMonoMethod::get_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, nullptr); - if (!attrs_fetched) + if (!attrs_fetched) { fetch_attributes(); + } - if (!attributes) + if (!attributes) { return nullptr; + } return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr()); } @@ -250,8 +254,9 @@ const MethodInfo &GDMonoMethod::get_method_info() { bool nil_is_variant = false; method_info.return_val = PropertyInfo(GDMonoMarshal::managed_to_variant_type(return_type, &nil_is_variant), ""); - if (method_info.return_val.type == Variant::NIL && nil_is_variant) + if (method_info.return_val.type == Variant::NIL && nil_is_variant) { method_info.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + } Vector<StringName> names; get_parameter_names(names); @@ -259,8 +264,9 @@ const MethodInfo &GDMonoMethod::get_method_info() { for (int i = 0; i < params_count; ++i) { nil_is_variant = false; PropertyInfo arg_info = PropertyInfo(GDMonoMarshal::managed_to_variant_type(param_types[i], &nil_is_variant), names[i]); - if (arg_info.type == Variant::NIL && nil_is_variant) + if (arg_info.type == Variant::NIL && nil_is_variant) { arg_info.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + } method_info.arguments.push_back(arg_info); } diff --git a/modules/mono/mono_gd/gd_mono_property.cpp b/modules/mono/mono_gd/gd_mono_property.cpp index c3e7598f2d..bc3be97102 100644 --- a/modules/mono/mono_gd/gd_mono_property.cpp +++ b/modules/mono/mono_gd/gd_mono_property.cpp @@ -77,15 +77,17 @@ GDMonoProperty::~GDMonoProperty() { bool GDMonoProperty::is_static() { MonoMethod *prop_method = mono_property_get_get_method(mono_property); - if (prop_method == nullptr) + if (prop_method == nullptr) { prop_method = mono_property_get_set_method(mono_property); + } return mono_method_get_flags(prop_method, nullptr) & MONO_METHOD_ATTR_STATIC; } IMonoClassMember::Visibility GDMonoProperty::get_visibility() { MonoMethod *prop_method = mono_property_get_get_method(mono_property); - if (prop_method == nullptr) + if (prop_method == nullptr) { prop_method = mono_property_get_set_method(mono_property); + } switch (mono_method_get_flags(prop_method, nullptr) & MONO_METHOD_ATTR_ACCESS_MASK) { case MONO_METHOD_ATTR_PRIVATE: @@ -106,11 +108,13 @@ IMonoClassMember::Visibility GDMonoProperty::get_visibility() { bool GDMonoProperty::has_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, false); - if (!attrs_fetched) + if (!attrs_fetched) { fetch_attributes(); + } - if (!attributes) + if (!attributes) { return false; + } return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr()); } @@ -118,11 +122,13 @@ bool GDMonoProperty::has_attribute(GDMonoClass *p_attr_class) { MonoObject *GDMonoProperty::get_attribute(GDMonoClass *p_attr_class) { ERR_FAIL_NULL_V(p_attr_class, nullptr); - if (!attrs_fetched) + if (!attrs_fetched) { fetch_attributes(); + } - if (!attributes) + if (!attributes) { return nullptr; + } return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr()); } diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp index 332744ae6e..3f1155f430 100644 --- a/modules/mono/mono_gd/gd_mono_utils.cpp +++ b/modules/mono/mono_gd/gd_mono_utils.cpp @@ -38,7 +38,6 @@ #include "core/os/dir_access.h" #include "core/os/mutex.h" #include "core/os/os.h" -#include "core/project_settings.h" #include "core/reference.h" #ifdef TOOLS_ENABLED @@ -51,13 +50,13 @@ #include "gd_mono_cache.h" #include "gd_mono_class.h" #include "gd_mono_marshal.h" -#include "gd_mono_method_thunk.h" namespace GDMonoUtils { MonoObject *unmanaged_get_managed(Object *unmanaged) { - if (!unmanaged) + if (!unmanaged) { return nullptr; + } if (unmanaged->get_script_instance()) { CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(unmanaged->get_script_instance()); @@ -90,8 +89,9 @@ MonoObject *unmanaged_get_managed(Object *unmanaged) { MonoObject *target = gchandle.get_target(); - if (target) + if (target) { return target; + } CSharpLanguage::get_singleton()->release_script_gchandle(gchandle); @@ -196,8 +196,9 @@ GDMonoClass *get_object_class(MonoObject *p_object) { GDMonoClass *type_get_proxy_class(const StringName &p_type) { String class_name = p_type; - if (class_name[0] == '_') + if (class_name[0] == '_') { class_name = class_name.substr(1, class_name.length()); + } GDMonoClass *klass = GDMono::get_singleton()->get_core_api_assembly()->get_class(BINDINGS_NAMESPACE, class_name); @@ -220,11 +221,14 @@ GDMonoClass *get_class_native_base(GDMonoClass *p_class) { do { const GDMonoAssembly *assembly = klass->get_assembly(); - if (assembly == GDMono::get_singleton()->get_core_api_assembly()) + + if (assembly == GDMono::get_singleton()->get_core_api_assembly()) { return klass; + } #ifdef TOOLS_ENABLED - if (assembly == GDMono::get_singleton()->get_editor_api_assembly()) + if (assembly == GDMono::get_singleton()->get_editor_api_assembly()) { return klass; + } #endif } while ((klass = klass->get_parent_class()) != nullptr); @@ -385,14 +389,6 @@ String get_exception_name_and_message(MonoException *p_exc) { return res; } -void set_exception_message(MonoException *p_exc, String message) { - MonoClass *klass = mono_object_get_class((MonoObject *)p_exc); - MonoProperty *prop = mono_class_get_property_from_name(klass, "Message"); - MonoString *msg = GDMonoMarshal::mono_string_from_godot(message); - void *params[1] = { msg }; - property_set_value(prop, (MonoObject *)p_exc, params, nullptr); -} - void debug_print_unhandled_exception(MonoException *p_exc) { print_unhandled_exception(p_exc); debug_send_unhandled_exception_error(p_exc); @@ -410,8 +406,9 @@ void debug_send_unhandled_exception_error(MonoException *p_exc) { } static thread_local bool _recursion_flag_ = false; - if (_recursion_flag_) + if (_recursion_flag_) { return; + } _recursion_flag_ = true; SCOPE_EXIT { _recursion_flag_ = false; }; @@ -441,8 +438,9 @@ void debug_send_unhandled_exception_error(MonoException *p_exc) { Vector<ScriptLanguage::StackInfo> _si; if (stack_trace != nullptr) { _si = CSharpLanguage::get_singleton()->stack_trace_get_info(stack_trace); - for (int i = _si.size() - 1; i >= 0; i--) + for (int i = _si.size() - 1; i >= 0; i--) { si.insert(0, _si[i]); + } } exc_msg += (exc_msg.length() > 0 ? " ---> " : "") + GDMonoUtils::get_exception_name_and_message(p_exc); @@ -452,8 +450,9 @@ void debug_send_unhandled_exception_error(MonoException *p_exc) { CRASH_COND(inner_exc_prop == nullptr); MonoObject *inner_exc = inner_exc_prop->get_value((MonoObject *)p_exc); - if (inner_exc != nullptr) + if (inner_exc != nullptr) { si.insert(0, separator); + } p_exc = (MonoException *)inner_exc; } diff --git a/modules/mono/mono_gd/gd_mono_utils.h b/modules/mono/mono_gd/gd_mono_utils.h index a7ca46f012..9db4a5f3f0 100644 --- a/modules/mono/mono_gd/gd_mono_utils.h +++ b/modules/mono/mono_gd/gd_mono_utils.h @@ -84,10 +84,6 @@ void detach_current_thread(MonoThread *p_mono_thread); MonoThread *get_current_thread(); bool is_thread_attached(); -_FORCE_INLINE_ bool is_main_thread() { - return mono_domain_get() != nullptr && mono_thread_get_main() == mono_thread_current(); -} - uint32_t new_strong_gchandle(MonoObject *p_object); uint32_t new_strong_gchandle_pinned(MonoObject *p_object); uint32_t new_weak_gchandle(MonoObject *p_object); @@ -115,7 +111,6 @@ String get_type_desc(MonoType *p_type); String get_type_desc(MonoReflectionType *p_reftype); String get_exception_name_and_message(MonoException *p_exc); -void set_exception_message(MonoException *p_exc, String message); void debug_print_unhandled_exception(MonoException *p_exc); void debug_send_unhandled_exception_error(MonoException *p_exc); diff --git a/modules/mono/register_types.cpp b/modules/mono/register_types.cpp index 94431e7c30..98c3ba1324 100644 --- a/modules/mono/register_types.cpp +++ b/modules/mono/register_types.cpp @@ -62,8 +62,9 @@ void register_mono_types() { void unregister_mono_types() { ScriptServer::unregister_language(script_language_cs); - if (script_language_cs) + if (script_language_cs) { memdelete(script_language_cs); + } ResourceLoader::remove_resource_format_loader(resource_loader_cs); resource_loader_cs.unref(); @@ -71,6 +72,7 @@ void unregister_mono_types() { ResourceSaver::remove_resource_format_saver(resource_saver_cs); resource_saver_cs.unref(); - if (_godotsharp) + if (_godotsharp) { memdelete(_godotsharp); + } } diff --git a/modules/mono/signal_awaiter_utils.cpp b/modules/mono/signal_awaiter_utils.cpp index ed0dc5cc28..bd67b03c8e 100644 --- a/modules/mono/signal_awaiter_utils.cpp +++ b/modules/mono/signal_awaiter_utils.cpp @@ -51,18 +51,21 @@ bool SignalAwaiterCallable::compare_equal(const CallableCustom *p_a, const Calla const SignalAwaiterCallable *a = static_cast<const SignalAwaiterCallable *>(p_a); const SignalAwaiterCallable *b = static_cast<const SignalAwaiterCallable *>(p_b); - if (a->target_id != b->target_id) + if (a->target_id != b->target_id) { return false; + } - if (a->signal != b->signal) + if (a->signal != b->signal) { return false; + } return true; } bool SignalAwaiterCallable::compare_less(const CallableCustom *p_a, const CallableCustom *p_b) { - if (compare_equal(p_a, p_b)) + if (compare_equal(p_a, p_b)) { return false; + } return p_a < p_b; } @@ -145,18 +148,21 @@ bool EventSignalCallable::compare_equal(const CallableCustom *p_a, const Callabl const EventSignalCallable *a = static_cast<const EventSignalCallable *>(p_a); const EventSignalCallable *b = static_cast<const EventSignalCallable *>(p_b); - if (a->owner != b->owner) + if (a->owner != b->owner) { return false; + } - if (a->event_signal != b->event_signal) + if (a->event_signal != b->event_signal) { return false; + } return true; } bool EventSignalCallable::compare_less(const CallableCustom *p_a, const CallableCustom *p_b) { - if (compare_equal(p_a, p_b)) + if (compare_equal(p_a, p_b)) { return false; + } return p_a < p_b; } diff --git a/modules/mono/utils/osx_utils.cpp b/modules/mono/utils/osx_utils.cpp index 8e3e51e688..e68466b1cf 100644 --- a/modules/mono/utils/osx_utils.cpp +++ b/modules/mono/utils/osx_utils.cpp @@ -38,24 +38,21 @@ #include <CoreServices/CoreServices.h> bool osx_is_app_bundle_installed(const String &p_bundle_id) { - CFURLRef app_url = nullptr; CFStringRef bundle_id = CFStringCreateWithCString(nullptr, p_bundle_id.utf8(), kCFStringEncodingUTF8); - OSStatus result = LSFindApplicationForInfo(kLSUnknownCreator, bundle_id, nullptr, nullptr, &app_url); + CFArrayRef result = LSCopyApplicationURLsForBundleIdentifier(bundle_id, nullptr); CFRelease(bundle_id); - if (app_url) - CFRelease(app_url); - - switch (result) { - case noErr: + if (result) { + if (CFArrayGetCount(result) > 0) { + CFRelease(result); return true; - case kLSApplicationNotFoundErr: - break; - default: - break; + } else { + CFRelease(result); + return false; + } + } else { + return false; } - - return false; } #endif diff --git a/modules/mono/utils/path_utils.cpp b/modules/mono/utils/path_utils.cpp index 973375a471..ccfaf5aba7 100644 --- a/modules/mono/utils/path_utils.cpp +++ b/modules/mono/utils/path_utils.cpp @@ -50,34 +50,6 @@ namespace path { -String find_executable(const String &p_name) { -#ifdef WINDOWS_ENABLED - Vector<String> exts = OS::get_singleton()->get_environment("PATHEXT").split(ENV_PATH_SEP, false); -#endif - Vector<String> env_path = OS::get_singleton()->get_environment("PATH").split(ENV_PATH_SEP, false); - - if (env_path.empty()) - return String(); - - for (int i = 0; i < env_path.size(); i++) { - String p = path::join(env_path[i], p_name); - -#ifdef WINDOWS_ENABLED - for (int j = 0; j < exts.size(); j++) { - String p2 = p + exts[j].to_lower(); // lowercase to reduce risk of case mismatch warning - - if (FileAccess::exists(p2)) - return p2; - } -#else - if (FileAccess::exists(p)) - return p; -#endif - } - - return String(); -} - String cwd() { #ifdef WINDOWS_ENABLED const DWORD expected_size = ::GetCurrentDirectoryW(0, nullptr); @@ -90,12 +62,14 @@ String cwd() { return buffer.simplify_path(); #else char buffer[PATH_MAX]; - if (::getcwd(buffer, sizeof(buffer)) == nullptr) + if (::getcwd(buffer, sizeof(buffer)) == nullptr) { return "."; + } String result; - if (result.parse_utf8(buffer)) + if (result.parse_utf8(buffer)) { return "."; + } return result.simplify_path(); #endif @@ -135,23 +109,26 @@ String realpath(const String &p_path) { #elif UNIX_ENABLED char *resolved_path = ::realpath(p_path.utf8().get_data(), nullptr); - if (!resolved_path) + if (!resolved_path) { return p_path; + } String result; bool parse_ok = result.parse_utf8(resolved_path); ::free(resolved_path); - if (parse_ok) + if (parse_ok) { return p_path; + } return result.simplify_path(); #endif } String join(const String &p_a, const String &p_b) { - if (p_a.empty()) + if (p_a.empty()) { return p_b; + } const CharType a_last = p_a[p_a.length() - 1]; if ((a_last == '/' || a_last == '\\') || @@ -178,8 +155,9 @@ String relative_to_impl(const String &p_path, const String &p_relative_to) { } else { String base_dir = p_relative_to.get_base_dir(); - if (base_dir.length() <= 2 && (base_dir.empty() || base_dir.ends_with(":"))) + if (base_dir.length() <= 2 && (base_dir.empty() || base_dir.ends_with(":"))) { return p_path; + } return String("..").plus_file(relative_to_impl(p_path, base_dir)); } diff --git a/modules/mono/utils/path_utils.h b/modules/mono/utils/path_utils.h index 9965f58b0a..bcd8af8bb9 100644 --- a/modules/mono/utils/path_utils.h +++ b/modules/mono/utils/path_utils.h @@ -40,8 +40,6 @@ String join(const String &p_a, const String &p_b); String join(const String &p_a, const String &p_b, const String &p_c); String join(const String &p_a, const String &p_b, const String &p_c, const String &p_d); -String find_executable(const String &p_name); - /// Returns a normalized absolute path to the current working directory String cwd(); diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp index da1b719d99..f8d9804de4 100644 --- a/modules/mono/utils/string_utils.cpp +++ b/modules/mono/utils/string_utils.cpp @@ -38,14 +38,16 @@ namespace { int sfind(const String &p_text, int p_from) { - if (p_from < 0) + if (p_from < 0) { return -1; + } int src_len = 2; int len = p_text.length(); - if (len == 0) + if (len == 0) { return -1; + } const CharType *src = p_text.c_str(); @@ -75,8 +77,9 @@ int sfind(const String &p_text, int p_from) { } } - if (found) + if (found) { return i; + } } return -1; @@ -85,8 +88,9 @@ int sfind(const String &p_text, int p_from) { } // namespace String sformat(const String &p_text, const Variant &p1, const Variant &p2, const Variant &p3, const Variant &p4, const Variant &p5) { - if (p_text.length() < 2) + if (p_text.length() < 2) { return p_text; + } Array args; diff --git a/modules/opensimplex/noise_texture.h b/modules/opensimplex/noise_texture.h index b1d7d3fac9..7357e54e35 100644 --- a/modules/opensimplex/noise_texture.h +++ b/modules/opensimplex/noise_texture.h @@ -70,7 +70,7 @@ private: protected: static void _bind_methods(); - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; public: void set_noise(Ref<OpenSimplexNoise> p_noise); @@ -88,13 +88,13 @@ public: void set_bump_strength(float p_bump_strength); float get_bump_strength(); - int get_width() const; - int get_height() const; + int get_width() const override; + int get_height() const override; - virtual RID get_rid() const; - virtual bool has_alpha() const { return false; } + virtual RID get_rid() const override; + virtual bool has_alpha() const override { return false; } - virtual Ref<Image> get_data() const; + virtual Ref<Image> get_data() const override; NoiseTexture(); virtual ~NoiseTexture(); diff --git a/modules/stb_vorbis/audio_stream_ogg_vorbis.h b/modules/stb_vorbis/audio_stream_ogg_vorbis.h index 3002134651..5070f2a078 100644 --- a/modules/stb_vorbis/audio_stream_ogg_vorbis.h +++ b/modules/stb_vorbis/audio_stream_ogg_vorbis.h @@ -52,18 +52,18 @@ class AudioStreamPlaybackOGGVorbis : public AudioStreamPlaybackResampled { Ref<AudioStreamOGGVorbis> vorbis_stream; protected: - virtual void _mix_internal(AudioFrame *p_buffer, int p_frames); - virtual float get_stream_sampling_rate(); + virtual void _mix_internal(AudioFrame *p_buffer, int p_frames) override; + virtual float get_stream_sampling_rate() override; public: - virtual void start(float p_from_pos = 0.0); - virtual void stop(); - virtual bool is_playing() const; + virtual void start(float p_from_pos = 0.0) override; + virtual void stop() override; + virtual bool is_playing() const override; - virtual int get_loop_count() const; //times it looped + virtual int get_loop_count() const override; //times it looped - virtual float get_playback_position() const; - virtual void seek(float p_time); + virtual float get_playback_position() const override; + virtual void seek(float p_time) override; AudioStreamPlaybackOGGVorbis() {} ~AudioStreamPlaybackOGGVorbis(); @@ -97,13 +97,13 @@ public: void set_loop_offset(float p_seconds); float get_loop_offset() const; - virtual Ref<AudioStreamPlayback> instance_playback(); - virtual String get_stream_name() const; + virtual Ref<AudioStreamPlayback> instance_playback() override; + virtual String get_stream_name() const override; void set_data(const Vector<uint8_t> &p_data); Vector<uint8_t> get_data() const; - virtual float get_length() const; //if supported, otherwise return 0 + virtual float get_length() const override; //if supported, otherwise return 0 AudioStreamOGGVorbis(); virtual ~AudioStreamOGGVorbis(); diff --git a/modules/stb_vorbis/resource_importer_ogg_vorbis.h b/modules/stb_vorbis/resource_importer_ogg_vorbis.h index 8d6f71a456..47f0039328 100644 --- a/modules/stb_vorbis/resource_importer_ogg_vorbis.h +++ b/modules/stb_vorbis/resource_importer_ogg_vorbis.h @@ -38,19 +38,19 @@ class ResourceImporterOGGVorbis : public ResourceImporter { GDCLASS(ResourceImporterOGGVorbis, 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 String get_importer_name() const override; + virtual String get_visible_name() const override; + virtual void get_recognized_extensions(List<String> *p_extensions) const override; + virtual String get_save_extension() const override; + virtual String get_resource_type() const override; - virtual int get_preset_count() const; - virtual String get_preset_name(int p_idx) const; + virtual int get_preset_count() const override; + virtual String get_preset_name(int p_idx) const override; - 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 void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const override; + virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override; - 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 = nullptr, Variant *r_metadata = nullptr); + 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 = nullptr, Variant *r_metadata = nullptr) override; ResourceImporterOGGVorbis(); }; diff --git a/modules/theora/video_stream_theora.h b/modules/theora/video_stream_theora.h index f90c2465b4..84f816acf8 100644 --- a/modules/theora/video_stream_theora.h +++ b/modules/theora/video_stream_theora.h @@ -125,35 +125,35 @@ protected: void clear(); public: - virtual void play(); - virtual void stop(); - virtual bool is_playing() const; + virtual void play() override; + virtual void stop() override; + virtual bool is_playing() const override; - virtual void set_paused(bool p_paused); - virtual bool is_paused() const; + virtual void set_paused(bool p_paused) override; + virtual bool is_paused() const override; - virtual void set_loop(bool p_enable); - virtual bool has_loop() const; + virtual void set_loop(bool p_enable) override; + virtual bool has_loop() const override; - virtual float get_length() const; + virtual float get_length() const override; virtual String get_stream_name() const; virtual int get_loop_count() const; - virtual float get_playback_position() const; - virtual void seek(float p_time); + virtual float get_playback_position() const override; + virtual void seek(float p_time) override; void set_file(const String &p_file); - virtual Ref<Texture2D> get_texture() const; - virtual void update(float p_delta); + virtual Ref<Texture2D> get_texture() const override; + virtual void update(float p_delta) override; - virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata); - virtual int get_channels() const; - virtual int get_mix_rate() const; + virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata) override; + virtual int get_channels() const override; + virtual int get_mix_rate() const override; - virtual void set_audio_track(int p_idx); + virtual void set_audio_track(int p_idx) override; VideoStreamPlaybackTheora(); ~VideoStreamPlaybackTheora(); @@ -169,7 +169,7 @@ protected: static void _bind_methods(); public: - Ref<VideoStreamPlayback> instance_playback() { + Ref<VideoStreamPlayback> instance_playback() override { Ref<VideoStreamPlaybackTheora> pb = memnew(VideoStreamPlaybackTheora); pb->set_audio_track(audio_track); pb->set_file(file); @@ -178,7 +178,7 @@ 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; } + void set_audio_track(int p_track) override { audio_track = p_track; } VideoStreamTheora() { audio_track = 0; } }; diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h index d54b1faf42..cb5ed37ba1 100644 --- a/modules/visual_script/visual_script.h +++ b/modules/visual_script/visual_script.h @@ -249,7 +249,7 @@ private: #ifdef TOOLS_ENABLED Set<PlaceHolderScriptInstance *> placeholders; //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder); - virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); + virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; void _update_placeholders(); #endif @@ -264,7 +264,7 @@ protected: static void _bind_methods(); public: - bool inherits_script(const Ref<Script> &p_script) const; + bool inherits_script(const Ref<Script> &p_script) const override; // TODO: Remove it in future when breaking changes are acceptable StringName get_default_func() const; @@ -330,47 +330,47 @@ public: void set_instance_base_type(const StringName &p_type); - virtual bool can_instance() const; + virtual bool can_instance() const override; - virtual Ref<Script> get_base_script() const; - virtual StringName get_instance_base_type() const; - virtual ScriptInstance *instance_create(Object *p_this); - virtual bool instance_has(const Object *p_this) const; + virtual Ref<Script> get_base_script() const override; + virtual StringName get_instance_base_type() const override; + virtual ScriptInstance *instance_create(Object *p_this) override; + virtual bool instance_has(const Object *p_this) const override; - virtual bool has_source_code() const; - virtual String get_source_code() const; - virtual void set_source_code(const String &p_code); - virtual Error reload(bool p_keep_state = false); + virtual bool has_source_code() const override; + virtual String get_source_code() const override; + virtual void set_source_code(const String &p_code) override; + virtual Error reload(bool p_keep_state = false) override; - virtual bool is_tool() const; - virtual bool is_valid() const; + virtual bool is_tool() const override; + virtual bool is_valid() const override; - virtual ScriptLanguage *get_language() const; + virtual ScriptLanguage *get_language() const override; - virtual bool has_script_signal(const StringName &p_signal) const; - virtual void get_script_signal_list(List<MethodInfo> *r_signals) const; + virtual bool has_script_signal(const StringName &p_signal) const override; + virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override; - virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const; - virtual void get_script_method_list(List<MethodInfo> *p_list) const; + virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const override; + virtual void get_script_method_list(List<MethodInfo> *p_list) const override; - virtual bool has_method(const StringName &p_method) const; - virtual MethodInfo get_method_info(const StringName &p_method) const; + virtual bool has_method(const StringName &p_method) const override; + virtual MethodInfo get_method_info(const StringName &p_method) const override; - virtual void get_script_property_list(List<PropertyInfo> *p_list) const; + virtual void get_script_property_list(List<PropertyInfo> *p_list) const override; - virtual int get_member_line(const StringName &p_member) const; + virtual int get_member_line(const StringName &p_member) const override; - virtual Vector<ScriptNetData> get_rpc_methods() const; - virtual uint16_t get_rpc_method_id(const StringName &p_method) const; - virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const; + virtual Vector<ScriptNetData> get_rpc_methods() const override; + virtual uint16_t get_rpc_method_id(const StringName &p_method) const override; + virtual StringName get_rpc_method(const uint16_t p_rpc_method_id) const override; + virtual MultiplayerAPI::RPCMode get_rpc_mode_by_id(const uint16_t p_rpc_method_id) const override; + virtual MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const override; - virtual Vector<ScriptNetData> get_rset_properties() const; - virtual uint16_t get_rset_property_id(const StringName &p_property) const; - virtual StringName get_rset_property(const uint16_t p_rset_property_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const; - virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const; + virtual Vector<ScriptNetData> get_rset_properties() const override; + virtual uint16_t get_rset_property_id(const StringName &p_property) const override; + virtual StringName get_rset_property(const uint16_t p_rset_property_id) const override; + virtual MultiplayerAPI::RPCMode get_rset_mode_by_id(const uint16_t p_rpc_method_id) const override; + virtual MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const override; #ifdef TOOLS_ENABLED virtual bool are_subnodes_edited() const; diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h index 1b186353f1..aee2ed79ce 100644 --- a/modules/visual_script/visual_script_builtin_funcs.h +++ b/modules/visual_script/visual_script_builtin_funcs.h @@ -122,25 +122,25 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; + virtual String get_caption() const override; //virtual String get_text() const; - virtual String get_category() const { return "functions"; } + virtual String get_category() const override { return "functions"; } void set_func(BuiltinFunc p_which); BuiltinFunc get_func(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptBuiltinFunc(VisualScriptBuiltinFunc::BuiltinFunc func); VisualScriptBuiltinFunc(); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index b7ca3c882b..2fcd9332a1 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -4660,10 +4660,10 @@ void VisualScriptEditor::_member_option(int p_option) { } } -void VisualScriptEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) { +void VisualScriptEditor::add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) { } -void VisualScriptEditor::set_syntax_highlighter(SyntaxHighlighter *p_highlighter) { +void VisualScriptEditor::set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) { } void VisualScriptEditor::_bind_methods() { @@ -4686,6 +4686,8 @@ void VisualScriptEditor::_bind_methods() { ClassDB::bind_method("_update_members", &VisualScriptEditor::_update_members); ClassDB::bind_method("_generic_search", &VisualScriptEditor::_generic_search); + + ClassDB::bind_method(D_METHOD("add_syntax_highlighter", "highlighter"), &VisualScriptEditor::add_syntax_highlighter); } VisualScriptEditor::VisualScriptEditor() { diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index 37063b2da1..e59618e120 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -288,39 +288,39 @@ protected: static void _bind_methods(); public: - virtual void add_syntax_highlighter(SyntaxHighlighter *p_highlighter); - virtual void set_syntax_highlighter(SyntaxHighlighter *p_highlighter); - - virtual void apply_code(); - virtual RES get_edited_resource() const; - virtual void set_edited_resource(const RES &p_res); - virtual Vector<String> get_functions(); - virtual void reload_text(); - virtual String get_name(); - virtual Ref<Texture2D> get_theme_icon(); - virtual bool is_unsaved(); - virtual Variant get_edit_state(); - virtual void set_edit_state(const Variant &p_state); - virtual void goto_line(int p_line, bool p_with_error = false); - virtual void set_executing_line(int p_line); - virtual void clear_executing_line(); - virtual void trim_trailing_whitespace(); - virtual void insert_final_newline(); - virtual void convert_indent_to_spaces(); - virtual void convert_indent_to_tabs(); - virtual void ensure_focus(); - virtual void tag_saved_version(); - virtual void reload(bool p_soft); - virtual void get_breakpoints(List<int> *p_breakpoints); - virtual void add_callback(const String &p_function, PackedStringArray p_args); - virtual void update_settings(); - virtual bool show_members_overview(); - virtual void set_debugger_active(bool p_active); - virtual void set_tooltip_request_func(String p_method, Object *p_obj); - virtual Control *get_edit_menu(); - virtual void clear_edit_menu(); - virtual bool can_lose_focus_on_node_selection() { return false; } - virtual void validate(); + virtual void add_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override; + virtual void set_syntax_highlighter(Ref<EditorSyntaxHighlighter> p_highlighter) override; + + virtual void apply_code() override; + virtual RES get_edited_resource() const override; + virtual void set_edited_resource(const RES &p_res) override; + virtual Vector<String> get_functions() override; + virtual void reload_text() override; + virtual String get_name() override; + virtual Ref<Texture2D> get_theme_icon() override; + virtual bool is_unsaved() override; + virtual Variant get_edit_state() override; + virtual void set_edit_state(const Variant &p_state) override; + virtual void goto_line(int p_line, bool p_with_error = false) override; + virtual void set_executing_line(int p_line) override; + virtual void clear_executing_line() override; + virtual void trim_trailing_whitespace() override; + virtual void insert_final_newline() override; + virtual void convert_indent_to_spaces() override; + virtual void convert_indent_to_tabs() override; + virtual void ensure_focus() override; + virtual void tag_saved_version() override; + virtual void reload(bool p_soft) override; + virtual void get_breakpoints(List<int> *p_breakpoints) override; + virtual void add_callback(const String &p_function, PackedStringArray p_args) override; + virtual void update_settings() override; + virtual bool show_members_overview() override; + virtual void set_debugger_active(bool p_active) override; + virtual void set_tooltip_request_func(String p_method, Object *p_obj) override; + virtual Control *get_edit_menu() override; + virtual void clear_edit_menu() override; + virtual bool can_lose_focus_on_node_selection() override { return false; } + virtual void validate() override; static void register_editor(); diff --git a/modules/visual_script/visual_script_expression.h b/modules/visual_script/visual_script_expression.h index dee0213d54..2b3b25842d 100644 --- a/modules/visual_script/visual_script_expression.h +++ b/modules/visual_script/visual_script_expression.h @@ -259,22 +259,22 @@ protected: void _get_property_list(List<PropertyInfo> *p_list) const; public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "operators"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "operators"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptExpression(); ~VisualScriptExpression(); diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h index 45b56b3073..1d0d6d103b 100644 --- a/modules/visual_script/visual_script_flow_control.h +++ b/modules/visual_script/visual_script_flow_control.h @@ -43,20 +43,20 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "flow_control"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "flow_control"; } void set_return_type(Variant::Type); Variant::Type get_return_type() const; @@ -64,7 +64,7 @@ public: void set_enable_return_value(bool p_enable); bool is_return_value_enabled() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptReturn(); }; @@ -76,22 +76,22 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "flow_control"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "flow_control"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptCondition(); }; @@ -103,22 +103,22 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "flow_control"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "flow_control"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptWhile(); }; @@ -130,22 +130,22 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "flow_control"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "flow_control"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptIterator(); }; @@ -159,25 +159,25 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "flow_control"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "flow_control"; } void set_steps(int p_steps); int get_steps() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptSequence(); }; @@ -202,23 +202,23 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; - virtual bool has_mixed_input_and_sequence_ports() const { return true; } + virtual String get_output_sequence_port_text(int p_port) const override; + virtual bool has_mixed_input_and_sequence_ports() const override { return true; } - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "flow_control"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "flow_control"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptSwitch(); }; @@ -233,20 +233,20 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "flow_control"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "flow_control"; } void set_base_type(const StringName &p_type); StringName get_base_type() const; @@ -254,9 +254,9 @@ public: void set_base_script(const String &p_path); String get_base_script() const; - virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptTypeCast(); }; diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index 6921f0e820..8372df561f 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -75,25 +75,25 @@ private: Dictionary _get_argument_cache() const; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "functions"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "functions"; } void set_basic_type(Variant::Type p_type); Variant::Type get_basic_type() const; @@ -125,9 +125,9 @@ public: void set_rpc_call_mode(RPCCallMode p_mode); RPCCallMode get_rpc_call_mode() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; - virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; VisualScriptFunctionCall(); }; @@ -187,25 +187,25 @@ private: void _adjust_input_index(PropertyInfo &pinfo) const; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "functions"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "functions"; } void set_base_type(const StringName &p_type); StringName get_base_type() const; @@ -231,8 +231,8 @@ public: void set_assign_op(AssignOp p_op); AssignOp get_assign_op() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); - virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; VisualScriptPropertySet(); }; @@ -273,25 +273,25 @@ private: Variant::Type _get_type_cache() const; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "functions"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "functions"; } void set_base_type(const StringName &p_type); StringName get_base_type() const; @@ -314,7 +314,7 @@ public: void set_index(const StringName &p_type); StringName get_index() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptPropertyGet(); }; @@ -328,30 +328,30 @@ private: StringName name; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; + virtual String get_caption() const override; //virtual String get_text() const; - virtual String get_category() const { return "functions"; } + virtual String get_category() const override { return "functions"; } void set_signal(const StringName &p_type); StringName get_signal() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptEmitSignal(); }; diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h index fa284b216c..b6061f8838 100644 --- a/modules/visual_script/visual_script_nodes.h +++ b/modules/visual_script/visual_script_nodes.h @@ -56,20 +56,20 @@ protected: void _get_property_list(List<PropertyInfo> *p_list) const; public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "flow_control"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "flow_control"; } void add_argument(Variant::Type p_type, const String &p_name, int p_index = -1, const PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = String("")); void set_argument_type(int p_argidx, Variant::Type p_type); @@ -97,7 +97,7 @@ public: void set_rpc_mode(MultiplayerAPI::RPCMode p_mode); MultiplayerAPI::RPCMode get_rpc_mode() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptFunction(); }; @@ -142,20 +142,16 @@ public: virtual bool is_input_port_name_editable() const; virtual bool is_input_port_type_editable() const; - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; - - virtual String get_caption() const = 0; - virtual String get_text() const = 0; - virtual String get_category() const = 0; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; void add_input_data_port(Variant::Type p_type, const String &p_name, int p_index = -1); void set_input_data_port_type(int p_idx, Variant::Type p_type); @@ -177,22 +173,22 @@ class VisualScriptComposeArray : public VisualScriptLists { GDCLASS(VisualScriptComposeArray, VisualScriptLists) public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "functions"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "functions"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptComposeArray(); }; @@ -207,19 +203,19 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "operators"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "operators"; } void set_operator(Variant::Operator p_op); Variant::Operator get_operator() const; @@ -227,7 +223,7 @@ public: void set_typed(Variant::Type p_op); Variant::Type get_typed() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptOperator(); }; @@ -241,25 +237,25 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "operators"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "operators"; } void set_typed(Variant::Type p_op); Variant::Type get_typed() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptSelect(); }; @@ -270,28 +266,28 @@ class VisualScriptVariableGet : public VisualScriptNode { StringName variable; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "data"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "data"; } void set_variable(StringName p_variable); StringName get_variable() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptVariableGet(); }; @@ -302,28 +298,28 @@ class VisualScriptVariableSet : public VisualScriptNode { StringName variable; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "data"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "data"; } void set_variable(StringName p_variable); StringName get_variable() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptVariableSet(); }; @@ -335,23 +331,23 @@ class VisualScriptConstant : public VisualScriptNode { Variant value; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "constants"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "constants"; } void set_constant_type(Variant::Type p_type); Variant::Type get_constant_type() const; @@ -359,7 +355,7 @@ public: void set_constant_value(Variant p_value); Variant get_constant_value() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptConstant(); }; @@ -373,24 +369,24 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "data"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "data"; } void set_preload(const Ref<Resource> &p_preload); Ref<Resource> get_preload() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptPreload(); }; @@ -399,21 +395,21 @@ class VisualScriptIndexGet : public VisualScriptNode { GDCLASS(VisualScriptIndexGet, VisualScriptNode); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "operators"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "operators"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptIndexGet(); }; @@ -422,21 +418,21 @@ class VisualScriptIndexSet : public VisualScriptNode { GDCLASS(VisualScriptIndexSet, VisualScriptNode); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "operators"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "operators"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptIndexSet(); }; @@ -449,24 +445,24 @@ class VisualScriptGlobalConstant : public VisualScriptNode { static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "constants"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "constants"; } void set_global_constant(int p_which); int get_global_constant(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptGlobalConstant(); }; @@ -479,22 +475,22 @@ class VisualScriptClassConstant : public VisualScriptNode { protected: static void _bind_methods(); - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "constants"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "constants"; } void set_class_constant(const StringName &p_which); StringName get_class_constant(); @@ -502,7 +498,7 @@ public: void set_base_type(const StringName &p_which); StringName get_base_type(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptClassConstant(); }; @@ -515,23 +511,23 @@ class VisualScriptBasicTypeConstant : public VisualScriptNode { protected: static void _bind_methods(); - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "constants"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "constants"; } void set_basic_type_constant(const StringName &p_which); StringName get_basic_type_constant() const; @@ -539,7 +535,7 @@ public: void set_basic_type(Variant::Type p_which); Variant::Type get_basic_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptBasicTypeConstant(); }; @@ -569,24 +565,24 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "constants"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "constants"; } void set_math_constant(MathConstant p_which); MathConstant get_math_constant(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptMathConstant(); }; @@ -599,31 +595,31 @@ class VisualScriptEngineSingleton : public VisualScriptNode { String singleton; protected: - void _validate_property(PropertyInfo &property) const; + void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "data"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "data"; } void set_singleton(const String &p_string); String get_singleton(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; - virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; VisualScriptEngineSingleton(); }; @@ -634,30 +630,30 @@ class VisualScriptSceneNode : public VisualScriptNode { NodePath path; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "data"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "data"; } void set_node_path(const NodePath &p_path); NodePath get_node_path(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; - virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; VisualScriptSceneNode(); }; @@ -666,27 +662,27 @@ class VisualScriptSceneTree : public VisualScriptNode { GDCLASS(VisualScriptSceneTree, VisualScriptNode); protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "data"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "data"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; - virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; VisualScriptSceneTree(); }; @@ -700,24 +696,24 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "data"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "data"; } void set_resource_path(const String &p_path); String get_resource_path(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptResourcePath(); }; @@ -729,23 +725,23 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const { return "data"; } + virtual String get_caption() const override; + virtual String get_category() const override { return "data"; } - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; - virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const; + virtual TypeGuess guess_output_type(TypeGuess *p_inputs, int p_output) const override; VisualScriptSelf(); }; @@ -773,22 +769,22 @@ public: STEP_YIELD_BIT = STEP_SHIFT << 4, //yield (will find VisualScriptFunctionState state in first working memory) }; - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const; + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; void _script_changed(); @@ -804,22 +800,22 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const; + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptSubCall(); }; @@ -835,20 +831,20 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const; + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override; void set_title(const String &p_title); String get_title() const; @@ -859,7 +855,7 @@ public: void set_size(const Size2 &p_size); Size2 get_size() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptComment(); }; @@ -874,19 +870,19 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const; + virtual String get_caption() const override; + virtual String get_category() const override; void set_constructor_type(Variant::Type p_type); Variant::Type get_constructor_type() const; @@ -894,7 +890,7 @@ public: void set_constructor(const Dictionary &p_info); Dictionary get_constructor() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptConstructor(); }; @@ -909,19 +905,19 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const; + virtual String get_caption() const override; + virtual String get_category() const override; void set_var_name(const StringName &p_name); StringName get_var_name() const; @@ -929,7 +925,7 @@ public: void set_var_type(Variant::Type p_type); Variant::Type get_var_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptLocalVar(); }; @@ -944,20 +940,20 @@ protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const; + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override; void set_var_name(const StringName &p_name); StringName get_var_name() const; @@ -965,7 +961,7 @@ public: void set_var_type(Variant::Type p_type); Variant::Type get_var_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptLocalVarSet(); }; @@ -985,24 +981,24 @@ public: Mode mode; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const; + virtual String get_caption() const override; + virtual String get_category() const override; void set_action_name(const StringName &p_name); StringName get_action_name() const; @@ -1010,7 +1006,7 @@ public: void set_action_mode(Mode p_mode); Mode get_action_mode() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptInputAction(); }; @@ -1033,30 +1029,30 @@ class VisualScriptDeconstruct : public VisualScriptNode { void _set_elem_cache(const Array &p_elements); Array _get_elem_cache() const; - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; protected: static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_category() const; + virtual String get_caption() const override; + virtual String get_category() const override; void set_deconstruct_type(Variant::Type p_type); Variant::Type get_deconstruct_type() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptDeconstruct(); }; diff --git a/modules/visual_script/visual_script_yield_nodes.h b/modules/visual_script/visual_script_yield_nodes.h index 4877e8b7e6..7a72211027 100644 --- a/modules/visual_script/visual_script_yield_nodes.h +++ b/modules/visual_script/visual_script_yield_nodes.h @@ -50,25 +50,25 @@ private: float wait_time; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "functions"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "functions"; } void set_yield_mode(YieldMode p_mode); YieldMode get_yield_mode(); @@ -76,7 +76,7 @@ public: void set_wait_time(float p_time); float get_wait_time(); - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptYield(); }; @@ -103,25 +103,25 @@ private: StringName _get_base_type() const; protected: - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: - virtual int get_output_sequence_port_count() const; - virtual bool has_input_sequence_port() const; + virtual int get_output_sequence_port_count() const override; + virtual bool has_input_sequence_port() const override; - virtual String get_output_sequence_port_text(int p_port) const; + virtual String get_output_sequence_port_text(int p_port) const override; - virtual int get_input_value_port_count() const; - virtual int get_output_value_port_count() const; + virtual int get_input_value_port_count() const override; + virtual int get_output_value_port_count() const override; - virtual PropertyInfo get_input_value_port_info(int p_idx) const; - virtual PropertyInfo get_output_value_port_info(int p_idx) const; + virtual PropertyInfo get_input_value_port_info(int p_idx) const override; + virtual PropertyInfo get_output_value_port_info(int p_idx) const override; - virtual String get_caption() const; - virtual String get_text() const; - virtual String get_category() const { return "functions"; } + virtual String get_caption() const override; + virtual String get_text() const override; + virtual String get_category() const override { return "functions"; } void set_base_type(const StringName &p_type); StringName get_base_type() const; @@ -135,7 +135,7 @@ public: void set_call_mode(CallMode p_mode); CallMode get_call_mode() const; - virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance); + virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance) override; VisualScriptYieldSignal(); }; diff --git a/modules/webm/video_stream_webm.h b/modules/webm/video_stream_webm.h index f6c148b29b..25675cb248 100644 --- a/modules/webm/video_stream_webm.h +++ b/modules/webm/video_stream_webm.h @@ -71,30 +71,30 @@ public: bool open_file(const String &p_file); - virtual void stop(); - virtual void play(); + virtual void stop() override; + virtual void play() override; - virtual bool is_playing() const; + virtual bool is_playing() const override; - virtual void set_paused(bool p_paused); - virtual bool is_paused() const; + virtual void set_paused(bool p_paused) override; + virtual bool is_paused() const override; - virtual void set_loop(bool p_enable); - virtual bool has_loop() const; + virtual void set_loop(bool p_enable) override; + virtual bool has_loop() const override; - virtual float get_length() const; + virtual float get_length() const override; - virtual float get_playback_position() const; - virtual void seek(float p_time); + virtual float get_playback_position() const override; + virtual void seek(float p_time) override; - virtual void set_audio_track(int p_idx); + virtual void set_audio_track(int p_idx) override; - virtual Ref<Texture2D> get_texture() const; - virtual void update(float p_delta); + virtual Ref<Texture2D> get_texture() const override; + virtual void update(float p_delta) override; - virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata); - virtual int get_channels() const; - virtual int get_mix_rate() const; + virtual void set_mix_callback(AudioMixCallback p_callback, void *p_userdata) override; + virtual int get_channels() const override; + virtual int get_mix_rate() const override; private: inline bool has_enough_video_frames() const; @@ -117,11 +117,11 @@ protected: public: VideoStreamWebm(); - virtual Ref<VideoStreamPlayback> instance_playback(); + virtual Ref<VideoStreamPlayback> instance_playback() override; virtual void set_file(const String &p_file); String get_file(); - virtual void set_audio_track(int p_track); + virtual void set_audio_track(int p_track) override; }; class ResourceFormatLoaderWebm : public ResourceFormatLoader { diff --git a/modules/webrtc/webrtc_data_channel.h b/modules/webrtc/webrtc_data_channel.h index e61f786ca1..1407f1e3bd 100644 --- a/modules/webrtc/webrtc_data_channel.h +++ b/modules/webrtc/webrtc_data_channel.h @@ -73,13 +73,6 @@ public: virtual Error poll() = 0; virtual void close() = 0; - /** Inherited from PacketPeer: **/ - virtual int get_available_packet_count() const = 0; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) = 0; ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) = 0; - - virtual int get_max_packet_size() const = 0; - WebRTCDataChannel(); ~WebRTCDataChannel(); }; diff --git a/modules/webrtc/webrtc_data_channel_gdnative.h b/modules/webrtc/webrtc_data_channel_gdnative.h index be3ea13028..b578802250 100644 --- a/modules/webrtc/webrtc_data_channel_gdnative.h +++ b/modules/webrtc/webrtc_data_channel_gdnative.h @@ -48,28 +48,28 @@ private: public: void set_native_webrtc_data_channel(const godot_net_webrtc_data_channel *p_impl); - virtual void set_write_mode(WriteMode mode); - virtual WriteMode get_write_mode() const; - virtual bool was_string_packet() const; + virtual void set_write_mode(WriteMode mode) override; + virtual WriteMode get_write_mode() const override; + virtual bool was_string_packet() const override; - virtual ChannelState get_ready_state() const; - virtual String get_label() const; - virtual bool is_ordered() const; - virtual int get_id() const; - virtual int get_max_packet_life_time() const; - virtual int get_max_retransmits() const; - virtual String get_protocol() const; - virtual bool is_negotiated() const; + virtual ChannelState get_ready_state() const override; + virtual String get_label() const override; + virtual bool is_ordered() const override; + virtual int get_id() const override; + virtual int get_max_packet_life_time() const override; + virtual int get_max_retransmits() const override; + virtual String get_protocol() const override; + virtual bool is_negotiated() const override; - virtual Error poll(); - virtual void close(); + virtual Error poll() override; + virtual void close() override; /** Inherited from PacketPeer: **/ - virtual int get_available_packet_count() const; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const; + virtual int get_max_packet_size() const override; WebRTCDataChannelGDNative(); ~WebRTCDataChannelGDNative(); diff --git a/modules/webrtc/webrtc_data_channel_js.h b/modules/webrtc/webrtc_data_channel_js.h index 00b5963ea1..455866cbf1 100644 --- a/modules/webrtc/webrtc_data_channel_js.h +++ b/modules/webrtc/webrtc_data_channel_js.h @@ -60,28 +60,28 @@ public: void _on_error(); void _on_message(uint8_t *p_data, uint32_t p_size, bool p_is_string); - virtual void set_write_mode(WriteMode mode); - virtual WriteMode get_write_mode() const; - virtual bool was_string_packet() const; - - virtual ChannelState get_ready_state() const; - virtual String get_label() const; - virtual bool is_ordered() const; - virtual int get_id() const; - virtual int get_max_packet_life_time() const; - virtual int get_max_retransmits() const; - virtual String get_protocol() const; - virtual bool is_negotiated() const; - - virtual Error poll(); - virtual void close(); + virtual void set_write_mode(WriteMode mode) override; + virtual WriteMode get_write_mode() const override; + virtual bool was_string_packet() const override; + + virtual ChannelState get_ready_state() const override; + virtual String get_label() const override; + virtual bool is_ordered() const override; + virtual int get_id() const override; + virtual int get_max_packet_life_time() const override; + virtual int get_max_retransmits() const override; + virtual String get_protocol() const override; + virtual bool is_negotiated() const override; + + virtual Error poll() override; + virtual void close() override; /** Inherited from PacketPeer: **/ - virtual int get_available_packet_count() const; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); ///< buffer is GONE after next get_packet - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; - virtual int get_max_packet_size() const; + virtual int get_max_packet_size() const override; WebRTCDataChannelJS(); WebRTCDataChannelJS(int js_id); diff --git a/modules/webrtc/webrtc_multiplayer.h b/modules/webrtc/webrtc_multiplayer.h index 906b90a1b6..bfdcf6daa1 100644 --- a/modules/webrtc/webrtc_multiplayer.h +++ b/modules/webrtc/webrtc_multiplayer.h @@ -89,27 +89,27 @@ public: void close(); // PacketPeer - Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); ///< buffer is GONE after next get_packet - Error put_packet(const uint8_t *p_buffer, int p_buffer_size); - int get_available_packet_count() const; - int get_max_packet_size() const; + Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; ///< buffer is GONE after next get_packet + Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; + int get_available_packet_count() const override; + int get_max_packet_size() const override; // NetworkedMultiplayerPeer - void set_transfer_mode(TransferMode p_mode); - TransferMode get_transfer_mode() const; - void set_target_peer(int p_peer_id); + void set_transfer_mode(TransferMode p_mode) override; + TransferMode get_transfer_mode() const override; + void set_target_peer(int p_peer_id) override; - int get_unique_id() const; - int get_packet_peer() const; + int get_unique_id() const override; + int get_packet_peer() const override; - bool is_server() const; + bool is_server() const override; - void poll(); + void poll() override; - void set_refuse_new_connections(bool p_enable); - bool is_refusing_new_connections() const; + void set_refuse_new_connections(bool p_enable) override; + bool is_refusing_new_connections() const override; - ConnectionStatus get_connection_status() const; + ConnectionStatus get_connection_status() const override; }; #endif diff --git a/modules/webrtc/webrtc_peer_connection_gdnative.h b/modules/webrtc/webrtc_peer_connection_gdnative.h index 8e59ad62ba..74b7db1307 100644 --- a/modules/webrtc/webrtc_peer_connection_gdnative.h +++ b/modules/webrtc/webrtc_peer_connection_gdnative.h @@ -53,16 +53,16 @@ public: void set_native_webrtc_peer_connection(const godot_net_webrtc_peer_connection *p_impl); - virtual ConnectionState get_connection_state() const; + virtual ConnectionState get_connection_state() const override; - virtual Error initialize(Dictionary p_config = Dictionary()); - virtual Ref<WebRTCDataChannel> create_data_channel(String p_label, Dictionary p_options = Dictionary()); - virtual Error create_offer(); - virtual Error set_remote_description(String type, String sdp); - virtual Error set_local_description(String type, String sdp); - virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName); - virtual Error poll(); - virtual void close(); + virtual Error initialize(Dictionary p_config = Dictionary()) override; + virtual Ref<WebRTCDataChannel> create_data_channel(String p_label, Dictionary p_options = Dictionary()) override; + virtual Error create_offer() override; + virtual Error set_remote_description(String type, String sdp) override; + virtual Error set_local_description(String type, String sdp) override; + virtual Error add_ice_candidate(String sdpMidName, int sdpMlineIndexName, String sdpName) override; + virtual Error poll() override; + virtual void close() override; WebRTCPeerConnectionGDNative(); ~WebRTCPeerConnectionGDNative(); diff --git a/modules/websocket/editor_debugger_server_websocket.h b/modules/websocket/editor_debugger_server_websocket.h index c66db1b72a..861f389aab 100644 --- a/modules/websocket/editor_debugger_server_websocket.h +++ b/modules/websocket/editor_debugger_server_websocket.h @@ -48,12 +48,12 @@ public: void _peer_connected(int p_peer, String p_protocol); void _peer_disconnected(int p_peer, bool p_was_clean); - void poll(); - Error start(); - void stop(); - bool is_active() const; - bool is_connection_available() const; - Ref<RemoteDebuggerPeer> take_connection(); + void poll() override; + Error start() override; + void stop() override; + bool is_active() const override; + bool is_connection_available() const override; + Ref<RemoteDebuggerPeer> take_connection() override; EditorDebuggerServerWebSocket(); ~EditorDebuggerServerWebSocket(); diff --git a/modules/websocket/websocket_client.cpp b/modules/websocket/websocket_client.cpp index 3900180739..8feaa9af5a 100644 --- a/modules/websocket/websocket_client.cpp +++ b/modules/websocket/websocket_client.cpp @@ -66,7 +66,7 @@ Error WebSocketClient::connect_to_url(String p_url, const Vector<String> p_proto } // Port - p_len = host.find_last(":"); + p_len = host.rfind(":"); if (p_len != -1 && p_len == host.find(":")) { port = host.substr(p_len, host.length() - p_len).to_int(); host = host.substr(0, p_len); diff --git a/modules/websocket/websocket_client.h b/modules/websocket/websocket_client.h index ba8e21aed6..1053be22e3 100644 --- a/modules/websocket/websocket_client.h +++ b/modules/websocket/websocket_client.h @@ -55,14 +55,12 @@ public: Ref<X509Certificate> get_trusted_ssl_certificate() const; void set_trusted_ssl_certificate(Ref<X509Certificate> p_cert); - virtual void poll() = 0; virtual Error connect_to_host(String p_host, String p_path, uint16_t p_port, bool p_ssl, const Vector<String> p_protocol = Vector<String>(), const Vector<String> p_custom_headers = Vector<String>()) = 0; virtual void disconnect_from_host(int p_code = 1000, String p_reason = "") = 0; virtual IP_Address get_connected_host() const = 0; virtual uint16_t get_connected_port() const = 0; - virtual bool is_server() const; - virtual ConnectionStatus get_connection_status() const = 0; + virtual bool is_server() const override; void _on_peer_packet(); void _on_connect(String p_protocol); @@ -70,8 +68,6 @@ public: void _on_disconnect(bool p_was_clean); void _on_error(); - virtual Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) = 0; - WebSocketClient(); ~WebSocketClient(); }; diff --git a/modules/websocket/websocket_multiplayer_peer.h b/modules/websocket/websocket_multiplayer_peer.h index 3ee26e2c5b..af26aef21e 100644 --- a/modules/websocket/websocket_multiplayer_peer.h +++ b/modules/websocket/websocket_multiplayer_peer.h @@ -79,21 +79,18 @@ protected: public: /* NetworkedMultiplayerPeer */ - void set_transfer_mode(TransferMode p_mode); - TransferMode get_transfer_mode() const; - void set_target_peer(int p_target_peer); - int get_packet_peer() const; - int get_unique_id() const; - virtual bool is_server() const = 0; - void set_refuse_new_connections(bool p_enable); - bool is_refusing_new_connections() const; - virtual ConnectionStatus get_connection_status() const = 0; + void set_transfer_mode(TransferMode p_mode) override; + TransferMode get_transfer_mode() const override; + void set_target_peer(int p_target_peer) override; + int get_packet_peer() const override; + int get_unique_id() const override; + void set_refuse_new_connections(bool p_enable) override; + bool is_refusing_new_connections() const override; /* PacketPeer */ - virtual int get_available_packet_count() const; - virtual int get_max_packet_size() const = 0; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size); - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size); + virtual int get_available_packet_count() const override; + virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override; + virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override; /* WebSocketPeer */ virtual Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) = 0; diff --git a/modules/websocket/websocket_peer.h b/modules/websocket/websocket_peer.h index 5f7d1c768b..a61943b615 100644 --- a/modules/websocket/websocket_peer.h +++ b/modules/websocket/websocket_peer.h @@ -49,11 +49,6 @@ protected: static void _bind_methods(); public: - virtual int get_available_packet_count() const = 0; - virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) = 0; - virtual Error put_packet(const uint8_t *p_buffer, int p_buffer_size) = 0; - virtual int get_max_packet_size() const = 0; - virtual WriteMode get_write_mode() const = 0; virtual void set_write_mode(WriteMode p_mode) = 0; diff --git a/modules/websocket/websocket_server.h b/modules/websocket/websocket_server.h index 5df0a37945..064ad4f179 100644 --- a/modules/websocket/websocket_server.h +++ b/modules/websocket/websocket_server.h @@ -50,14 +50,12 @@ protected: Ref<X509Certificate> ca_chain; public: - virtual void poll() = 0; virtual Error listen(int p_port, const Vector<String> p_protocols = Vector<String>(), bool gd_mp_api = false) = 0; virtual void stop() = 0; virtual bool is_listening() const = 0; virtual bool has_peer(int p_id) const = 0; - virtual Ref<WebSocketPeer> get_peer(int p_id) const = 0; - virtual bool is_server() const; - ConnectionStatus get_connection_status() const; + virtual bool is_server() const override; + ConnectionStatus get_connection_status() const override; virtual IP_Address get_peer_address(int p_peer_id) const = 0; virtual int get_peer_port(int p_peer_id) const = 0; @@ -80,8 +78,6 @@ public: Ref<X509Certificate> get_ca_chain() const; void set_ca_chain(Ref<X509Certificate> p_ca_chain); - virtual Error set_buffers(int p_in_buffer, int p_in_packets, int p_out_buffer, int p_out_packets) = 0; - WebSocketServer(); ~WebSocketServer(); }; |