Skip to content

Commit

Permalink
Merge pull request #44630 from qarmin/cppcheck_scene_1
Browse files Browse the repository at this point in the history
Initialize class variables with default values in scene/ [1/2]
  • Loading branch information
akien-mga authored Feb 8, 2021
2 parents 57e2822 + 003bb8e commit cea42fa
Show file tree
Hide file tree
Showing 139 changed files with 879 additions and 1,660 deletions.
11 changes: 0 additions & 11 deletions scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,4 @@ void AnimatedSprite2D::_bind_methods() {
}

AnimatedSprite2D::AnimatedSprite2D() {
centered = true;
hflip = false;
vflip = false;

frame = 0;
speed_scale = 1.0f;
playing = false;
backwards = false;
animation = "default";
timeout = 0;
is_over = false;
}
29 changes: 12 additions & 17 deletions scene/2d/animated_sprite_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,9 @@ class SpriteFrames : public Resource {
GDCLASS(SpriteFrames, Resource);

struct Anim {
float speed;
bool loop;
float speed = 5.0;
bool loop = true;
Vector<Ref<Texture2D>> frames;

Anim() {
loop = true;
speed = 5;
}
};

Map<StringName, Anim> animations;
Expand Down Expand Up @@ -109,20 +104,20 @@ class AnimatedSprite2D : public Node2D {
GDCLASS(AnimatedSprite2D, Node2D);

Ref<SpriteFrames> frames;
bool playing;
bool backwards;
StringName animation;
int frame;
float speed_scale;
bool playing = false;
bool backwards = false;
StringName animation = "default";
int frame = 0;
float speed_scale = 1.0f;

bool centered;
bool centered = true;
Point2 offset;

bool is_over;
float timeout;
bool is_over = false;
float timeout = 0.0;

bool hflip;
bool vflip;
bool hflip = false;
bool vflip = false;

void _res_changed();

Expand Down
12 changes: 0 additions & 12 deletions scene/2d/area_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,20 +627,8 @@ void Area2D::_bind_methods() {

Area2D::Area2D() :
CollisionObject2D(PhysicsServer2D::get_singleton()->area_create(), true) {
space_override = SPACE_OVERRIDE_DISABLED;
set_gravity(98);
set_gravity_vector(Vector2(0, 1));
gravity_is_point = false;
gravity_distance_scale = 0;
linear_damp = 0.1;
angular_damp = 1;
locked = false;
priority = 0;
monitoring = false;
monitorable = false;
collision_mask = 1;
collision_layer = 1;
audio_bus_override = false;
set_monitoring(true);
set_monitorable(true);
}
Expand Down
40 changes: 20 additions & 20 deletions scene/2d/area_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,28 @@ class Area2D : public CollisionObject2D {
};

private:
SpaceOverride space_override;
SpaceOverride space_override = SPACE_OVERRIDE_DISABLED;
Vector2 gravity_vec;
real_t gravity;
bool gravity_is_point;
real_t gravity_distance_scale;
real_t linear_damp;
real_t angular_damp;
uint32_t collision_mask;
uint32_t collision_layer;
int priority;
bool monitoring;
bool monitorable;
bool locked;
bool gravity_is_point = false;
real_t gravity_distance_scale = 0.0;
real_t linear_damp = 0.1;
real_t angular_damp = 1.0;
uint32_t collision_mask = 1;
uint32_t collision_layer = 1;
int priority = 0;
bool monitoring = false;
bool monitorable = false;
bool locked = false;

void _body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape);

void _body_enter_tree(ObjectID p_id);
void _body_exit_tree(ObjectID p_id);

struct ShapePair {
int body_shape;
int area_shape;
int body_shape = 0;
int area_shape = 0;
bool operator<(const ShapePair &p_sp) const {
if (body_shape == p_sp.body_shape) {
return area_shape < p_sp.area_shape;
Expand All @@ -85,8 +85,8 @@ class Area2D : public CollisionObject2D {
};

struct BodyState {
int rc;
bool in_tree;
int rc = 0;
bool in_tree = false;
VSet<ShapePair> shapes;
};

Expand All @@ -98,8 +98,8 @@ class Area2D : public CollisionObject2D {
void _area_exit_tree(ObjectID p_id);

struct AreaShapePair {
int area_shape;
int self_shape;
int area_shape = 0;
int self_shape = 0;
bool operator<(const AreaShapePair &p_sp) const {
if (area_shape == p_sp.area_shape) {
return self_shape < p_sp.self_shape;
Expand All @@ -116,15 +116,15 @@ class Area2D : public CollisionObject2D {
};

struct AreaState {
int rc;
bool in_tree;
int rc = 0;
bool in_tree = false;
VSet<AreaShapePair> shapes;
};

Map<ObjectID, AreaState> area_map;
void _clear_monitoring();

bool audio_bus_override;
bool audio_bus_override = false;
StringName audio_bus;

protected:
Expand Down
15 changes: 0 additions & 15 deletions scene/2d/audio_stream_player_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,21 +503,6 @@ void AudioStreamPlayer2D::_bind_methods() {
}

AudioStreamPlayer2D::AudioStreamPlayer2D() {
volume_db = 0;
pitch_scale = 1.0;
autoplay = false;
setseek = -1;
active = false;
output_count = 0;
prev_output_count = 0;
max_distance = 2000;
attenuation = 1;
setplay = -1;
output_ready = false;
area_mask = 1;
stream_paused = false;
stream_paused_fade_in = false;
stream_paused_fade_out = false;
AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &AudioStreamPlayer2D::_bus_layout_changed));
}

Expand Down
34 changes: 17 additions & 17 deletions scene/2d/audio_stream_player_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,32 @@ class AudioStreamPlayer2D : public Node2D {

struct Output {
AudioFrame vol;
int bus_index;
Viewport *viewport; //pointer only used for reference to previous mix
int bus_index = 0;
Viewport *viewport = nullptr; //pointer only used for reference to previous mix
};

Output outputs[MAX_OUTPUTS];
volatile int output_count;
volatile bool output_ready;
volatile int output_count = 0;
volatile bool output_ready = false;

//these are used by audio thread to have a reference of previous volumes (for ramping volume and avoiding clicks)
Output prev_outputs[MAX_OUTPUTS];
int prev_output_count;
int prev_output_count = 0;

Ref<AudioStreamPlayback> stream_playback;
Ref<AudioStream> stream;
Vector<AudioFrame> mix_buffer;

volatile float setseek;
volatile bool active;
volatile float setplay;
volatile float setseek = -1.0;
volatile bool active = false;
volatile float setplay = -1.0;

float volume_db;
float pitch_scale;
bool autoplay;
bool stream_paused;
bool stream_paused_fade_in;
bool stream_paused_fade_out;
float volume_db = 0.0;
float pitch_scale = 1.0;
bool autoplay = false;
bool stream_paused = false;
bool stream_paused_fade_in = false;
bool stream_paused_fade_out = false;
StringName bus;

void _mix_audio();
Expand All @@ -83,10 +83,10 @@ class AudioStreamPlayer2D : public Node2D {

void _bus_layout_changed();

uint32_t area_mask;
uint32_t area_mask = 1;

float max_distance;
float attenuation;
float max_distance = 2000.0;
float attenuation = 1.0;

protected:
void _validate_property(PropertyInfo &property) const override;
Expand Down
2 changes: 0 additions & 2 deletions scene/2d/back_buffer_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ void BackBufferCopy::_bind_methods() {
}

BackBufferCopy::BackBufferCopy() {
rect = Rect2(-100, -100, 200, 200);
copy_mode = COPY_MODE_RECT;
_update_copy_mode();
}

Expand Down
4 changes: 2 additions & 2 deletions scene/2d/back_buffer_copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class BackBufferCopy : public Node2D {
};

private:
Rect2 rect;
CopyMode copy_mode;
Rect2 rect = Rect2(-100, -100, 200, 200);
CopyMode copy_mode = COPY_MODE_RECT;

void _update_copy_mode();

Expand Down
24 changes: 0 additions & 24 deletions scene/2d/camera_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,6 @@ void Camera2D::_bind_methods() {
}

Camera2D::Camera2D() {
anchor_mode = ANCHOR_MODE_DRAG_CENTER;
rotating = false;
current = false;
limit[SIDE_LEFT] = -10000000;
limit[SIDE_TOP] = -10000000;
limit[SIDE_RIGHT] = 10000000;
Expand All @@ -761,27 +758,6 @@ Camera2D::Camera2D() {
drag_margin[SIDE_TOP] = 0.2;
drag_margin[SIDE_RIGHT] = 0.2;
drag_margin[SIDE_BOTTOM] = 0.2;
camera_pos = Vector2();
first = true;
smoothing_enabled = false;
limit_smoothing_enabled = false;
custom_viewport = nullptr;

process_mode = CAMERA2D_PROCESS_IDLE;

smoothing = 5.0;
zoom = Vector2(1, 1);

screen_drawing_enabled = true;
limit_drawing_enabled = false;
margin_drawing_enabled = false;

drag_horizontal_enabled = false;
drag_vertical_enabled = false;
drag_horizontal_offset = 0;
drag_vertical_offset = 0;
drag_horizontal_offset_changed = false;
drag_vertical_offset_changed = false;

set_notify_transform(true);
}
40 changes: 20 additions & 20 deletions scene/2d/camera_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,32 @@ class Camera2D : public Node2D {
protected:
Point2 camera_pos;
Point2 smoothed_camera_pos;
bool first;
bool first = true;

ObjectID custom_viewport_id; // to check validity
Viewport *custom_viewport;
Viewport *viewport;
Viewport *custom_viewport = nullptr;
Viewport *viewport = nullptr;

StringName group_name;
StringName canvas_group_name;
RID canvas;
Vector2 offset;
Vector2 zoom;
AnchorMode anchor_mode;
bool rotating;
bool current;
float smoothing;
bool smoothing_enabled;
Vector2 zoom = Vector2(1, 1);
AnchorMode anchor_mode = ANCHOR_MODE_DRAG_CENTER;
bool rotating = false;
bool current = false;
float smoothing = 5.0;
bool smoothing_enabled = false;
int limit[4];
bool limit_smoothing_enabled;
bool limit_smoothing_enabled = false;

float drag_margin[4];
bool drag_horizontal_enabled;
bool drag_vertical_enabled;
float drag_horizontal_offset;
float drag_vertical_offset;
bool drag_horizontal_offset_changed;
bool drag_vertical_offset_changed;
bool drag_horizontal_enabled = false;
bool drag_vertical_enabled = false;
float drag_horizontal_offset = 0.0;
float drag_vertical_offset = 0.0;
bool drag_horizontal_offset_changed = false;
bool drag_vertical_offset_changed = false;

Point2 camera_screen_center;
void _update_process_mode();
Expand All @@ -87,11 +87,11 @@ class Camera2D : public Node2D {

void _set_old_smoothing(float p_enable);

bool screen_drawing_enabled;
bool limit_drawing_enabled;
bool margin_drawing_enabled;
bool screen_drawing_enabled = true;
bool limit_drawing_enabled = false;
bool margin_drawing_enabled = false;

Camera2DProcessMode process_mode;
Camera2DProcessMode process_mode = CAMERA2D_PROCESS_IDLE;

Size2 _get_camera_screen_size() const;

Expand Down
1 change: 0 additions & 1 deletion scene/2d/canvas_modulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ String CanvasModulate::get_configuration_warning() const {
}

CanvasModulate::CanvasModulate() {
color = Color(1, 1, 1, 1);
}

CanvasModulate::~CanvasModulate() {
Expand Down
2 changes: 1 addition & 1 deletion scene/2d/canvas_modulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
class CanvasModulate : public Node2D {
GDCLASS(CanvasModulate, Node2D);

Color color;
Color color = Color(1, 1, 1, 1);

protected:
void _notification(int p_what);
Expand Down
Loading

0 comments on commit cea42fa

Please sign in to comment.