From af50a7db3955cee697d6778fef2d8d3442bbe7c1 Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 11 Oct 2023 21:41:10 -0700 Subject: [PATCH] Ensure all classes initialize all variables --- bullet.cpp | 7 ++++++- bullet_server.cpp | 2 ++ bullet_spawner.cpp | 19 ++++++++++++++++++- bullet_type.cpp | 15 ++++++++------- doc_classes/BulletServer.xml | 4 ++-- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/bullet.cpp b/bullet.cpp index 2e7f91a..067fd7d 100644 --- a/bullet.cpp +++ b/bullet.cpp @@ -186,7 +186,12 @@ void Bullet::_bind_methods() { Bullet::Bullet() { ci_rid = RS::get_singleton()->canvas_item_create(); - direction = Vector2(0, 0); + direction = Vector2(); + position = Vector2(); + type = Ref(); + rotation = 0.0; + _offset = Vector2(); + _popped = false; } Bullet::~Bullet() { diff --git a/bullet_server.cpp b/bullet_server.cpp index 7ae9c4a..e30e8b6 100644 --- a/bullet_server.cpp +++ b/bullet_server.cpp @@ -336,6 +336,8 @@ void BulletServer::_bind_methods() { BulletServer::BulletServer() { bullet_pool_size = 1500; + max_lifetime = 0.0; + play_area_allow_incoming = true; play_area_mode = VIEWPORT; play_area_margin = 0; play_area_rect = Rect2(); diff --git a/bullet_spawner.cpp b/bullet_spawner.cpp index e5daa90..981bf22 100644 --- a/bullet_spawner.cpp +++ b/bullet_spawner.cpp @@ -754,23 +754,40 @@ void BulletSpawner::_bind_methods() { //initialiser/terminator BulletSpawner::BulletSpawner() { autofire = false; + _autofire_time = 0.0; interval_frames = 10; + shot_count = 1; + radius = 10.0; arc_width = 0.0; arc_rotation = 0.0; arc_offset = 0.0; + + bullet_type = Ref(); + aim_mode = RADIAL; aim_angle = 0.0; + aim_target_position = Vector2(); + scatter_mode = NONE; scatter_range = 0.0; + pattern_mode = ALL; + active_shot_indices = PackedInt32Array(); + preview_visible_in_game = false; preview_color = Color(0.0, 1.0, 0.0, 1.0); //green preview_shot_color = Color(1.0, 1.0, 1.0, 1.0); - preview_arc_points = 32; preview_extent = 50; + preview_arc_points = 32; + relay_autoconnect = true; + + _cached_volley = Array(); + _volley_changed = true; + + _previous_transform = Transform2D(); } BulletSpawner::~BulletSpawner() { diff --git a/bullet_type.cpp b/bullet_type.cpp index 45e6749..e107808 100644 --- a/bullet_type.cpp +++ b/bullet_type.cpp @@ -314,28 +314,29 @@ void BulletType::_bind_methods() { } BulletType::BulletType() { + speed = 100.0; + damage = 0.0; lifetime = 0.0; texture = Ref(); modulate = Color(1, 1, 1, 1); light_mask = 1; material = Ref(); - face_direction = false; - scale = Vector2(1, 1); - damage = 0.0; collision_shape = Ref(); collision_mask = 1; collision_detect_bodies = true; collision_detect_areas = true; - speed = 100.0; linear_acceleration = 0.0; curve_rate = 0.0; + h_wave_type = WaveType::NONE; + h_wave_amplitude = 0.0; + h_wave_frequency = 0.0; v_wave_type = WaveType::NONE; v_wave_amplitude = 0.0; v_wave_frequency = 0.0; + face_direction = false; rotation = 0.0; - h_wave_type = WaveType::NONE; - h_wave_amplitude = 0.0; - h_wave_frequency = 0.0; + scale = Vector2(1, 1); + custom_data = Dictionary(); } BulletType::~BulletType() { diff --git a/doc_classes/BulletServer.xml b/doc_classes/BulletServer.xml index 5058bbe..3ff6010 100644 --- a/doc_classes/BulletServer.xml +++ b/doc_classes/BulletServer.xml @@ -61,9 +61,9 @@ A [BulletServer] generates all bullets on ready, and adds/removes them from play by cycling them between active and inactive groups. Spawning bullets pulls them from the inactive group and makes them active, and recycles the oldest active bullet if no inactive bullets are available. - The maximium lifetime of any [Bullet] managed by the server. Bullets older than this are automatically popped. + The maximium lifetime of any [Bullet] managed by the server. Bullets older than this are automatically popped. Setting to 0.0 means bullets do not pop automatically. - + If [code]true[/code], bullets outside of the play area will only be automatically popped if they are moving away from it. Bullets outside of the play area will not detect collisions. Calculation of whether bullet is "incoming" is approximate, and based on its angle to the center of the play area, so bullets that would enter a corner of the play area at an oblique angle may still be popped.