Merge pull request #56696 from AnilBK/use-init-lists

This commit is contained in:
Rémi Verschelde 2022-01-12 10:04:45 +01:00 committed by GitHub
commit 189662e5bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 326 additions and 308 deletions

View file

@ -164,15 +164,15 @@ void CollisionPolygon2D::_notification(int p_what) {
dcol.a = 1.0;
Vector2 line_to(0, 20);
draw_line(Vector2(), line_to, dcol, 3);
Vector<Vector2> pts;
real_t tsize = 8;
pts.push_back(line_to + (Vector2(0, tsize)));
pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0)));
pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0)));
Vector<Color> cols;
for (int i = 0; i < 3; i++) {
cols.push_back(dcol);
}
Vector<Vector2> pts = {
line_to + Vector2(0, tsize),
line_to + Vector2(Math_SQRT12 * tsize, 0),
line_to + Vector2(-Math_SQRT12 * tsize, 0)
};
Vector<Color> cols{ dcol, dcol, dcol };
draw_primitive(pts, cols, Vector<Vector2>()); //small arrow
}

View file

@ -121,15 +121,15 @@ void CollisionShape2D::_notification(int p_what) {
}
Vector2 line_to(0, 20);
draw_line(Vector2(), line_to, draw_col, 2);
Vector<Vector2> pts;
real_t tsize = 8;
pts.push_back(line_to + (Vector2(0, tsize)));
pts.push_back(line_to + (Vector2(Math_SQRT12 * tsize, 0)));
pts.push_back(line_to + (Vector2(-Math_SQRT12 * tsize, 0)));
Vector<Color> cols;
for (int i = 0; i < 3; i++) {
cols.push_back(draw_col);
}
Vector<Vector2> pts{
line_to + Vector2(0, tsize),
line_to + Vector2(Math_SQRT12 * tsize, 0),
line_to + Vector2(-Math_SQRT12 * tsize, 0)
};
Vector<Color> cols{ draw_col, draw_col, draw_col };
draw_primitive(pts, cols, Vector<Vector2>());
}

View file

@ -152,11 +152,14 @@ void CPUParticles2D::_update_mesh_texture() {
} else {
tex_size = Size2(1, 1);
}
Vector<Vector2> vertices;
vertices.push_back(-tex_size * 0.5);
vertices.push_back(-tex_size * 0.5 + Vector2(tex_size.x, 0));
vertices.push_back(-tex_size * 0.5 + tex_size);
vertices.push_back(-tex_size * 0.5 + Vector2(0, tex_size.y));
Vector<Vector2> vertices = {
-tex_size * 0.5,
-tex_size * 0.5 + Vector2(tex_size.x, 0),
-tex_size * 0.5 + tex_size,
-tex_size * 0.5 + Vector2(0, tex_size.y)
};
Vector<Vector2> uvs;
AtlasTexture *atlas_texure = Object::cast_to<AtlasTexture>(*texture);
if (atlas_texure && atlas_texure->get_atlas().is_valid()) {
@ -172,18 +175,15 @@ void CPUParticles2D::_update_mesh_texture() {
uvs.push_back(Vector2(1, 1));
uvs.push_back(Vector2(0, 1));
}
Vector<Color> colors;
colors.push_back(Color(1, 1, 1, 1));
colors.push_back(Color(1, 1, 1, 1));
colors.push_back(Color(1, 1, 1, 1));
colors.push_back(Color(1, 1, 1, 1));
Vector<int> indices;
indices.push_back(0);
indices.push_back(1);
indices.push_back(2);
indices.push_back(2);
indices.push_back(3);
indices.push_back(0);
Vector<Color> colors = {
Color(1, 1, 1, 1),
Color(1, 1, 1, 1),
Color(1, 1, 1, 1),
Color(1, 1, 1, 1)
};
Vector<int> indices = { 0, 1, 2, 2, 3, 0 };
Array arr;
arr.resize(RS::ARRAY_MAX);

View file

@ -427,26 +427,23 @@ void GPUParticles2D::_notification(int p_what) {
} else {
RS::get_singleton()->mesh_clear(mesh);
Vector<Vector2> points;
points.resize(4);
points.write[0] = Vector2(-size.x / 2.0, -size.y / 2.0);
points.write[1] = Vector2(size.x / 2.0, -size.y / 2.0);
points.write[2] = Vector2(size.x / 2.0, size.y / 2.0);
points.write[3] = Vector2(-size.x / 2.0, size.y / 2.0);
Vector<Vector2> uvs;
uvs.resize(4);
uvs.write[0] = Vector2(0, 0);
uvs.write[1] = Vector2(1, 0);
uvs.write[2] = Vector2(1, 1);
uvs.write[3] = Vector2(0, 1);
Vector<int> indices;
indices.resize(6);
indices.write[0] = 0;
indices.write[1] = 1;
indices.write[2] = 2;
indices.write[3] = 0;
indices.write[4] = 2;
indices.write[5] = 3;
Vector<Vector2> points = {
Vector2(-size.x / 2.0, -size.y / 2.0),
Vector2(size.x / 2.0, -size.y / 2.0),
Vector2(size.x / 2.0, size.y / 2.0),
Vector2(-size.x / 2.0, size.y / 2.0)
};
Vector<Vector2> uvs = {
Vector2(0, 0),
Vector2(1, 0),
Vector2(1, 1),
Vector2(0, 1)
};
Vector<int> indices = { 0, 1, 2, 0, 2, 3 };
Array arr;
arr.resize(RS::ARRAY_MAX);
arr[RS::ARRAY_VERTEX] = points;

View file

@ -36,37 +36,41 @@ void Position2D::_draw_cross() {
const real_t extents = get_gizmo_extents();
// Add more points to create a "hard stop" in the color gradient.
PackedVector2Array points_x;
points_x.push_back(Point2(+extents, 0));
points_x.push_back(Point2());
points_x.push_back(Point2());
points_x.push_back(Point2(-extents, 0));
PackedVector2Array points_x = {
Point2(+extents, 0),
Point2(),
Point2(),
Point2(-extents, 0)
};
PackedVector2Array points_y;
points_y.push_back(Point2(0, +extents));
points_y.push_back(Point2());
points_y.push_back(Point2());
points_y.push_back(Point2(0, -extents));
PackedVector2Array points_y = {
Point2(0, +extents),
Point2(),
Point2(),
Point2(0, -extents)
};
// Use the axis color which is brighter for the positive axis.
// Use a darkened axis color for the negative axis.
// This makes it possible to see in which direction the Position3D node is rotated
// (which can be important depending on how it's used).
// Axis colors are taken from `axis_x_color` and `axis_y_color` (defined in `editor/editor_themes.cpp`).
PackedColorArray colors_x;
const Color color_x = Color(0.96, 0.20, 0.32);
colors_x.push_back(color_x);
colors_x.push_back(color_x);
colors_x.push_back(color_x.lerp(Color(0, 0, 0), 0.5));
colors_x.push_back(color_x.lerp(Color(0, 0, 0), 0.5));
PackedColorArray colors_x = {
color_x,
color_x,
color_x.lerp(Color(0, 0, 0), 0.5),
color_x.lerp(Color(0, 0, 0), 0.5)
};
draw_multiline_colors(points_x, colors_x);
PackedColorArray colors_y;
const Color color_y = Color(0.53, 0.84, 0.01);
colors_y.push_back(color_y);
colors_y.push_back(color_y);
colors_y.push_back(color_y.lerp(Color(0, 0, 0), 0.5));
colors_y.push_back(color_y.lerp(Color(0, 0, 0), 0.5));
PackedColorArray colors_y = {
color_y,
color_y,
color_y.lerp(Color(0, 0, 0), 0.5),
color_y.lerp(Color(0, 0, 0), 0.5)
};
draw_multiline_colors(points_y, colors_y);
}

View file

@ -244,15 +244,13 @@ void RayCast2D::_draw_debug_shape() {
xf.rotate(target_position.angle());
xf.translate(Vector2(no_line ? 0 : target_position.length() - arrow_size, 0));
Vector<Vector2> pts;
pts.push_back(xf.xform(Vector2(arrow_size, 0)));
pts.push_back(xf.xform(Vector2(0, 0.5 * arrow_size)));
pts.push_back(xf.xform(Vector2(0, -0.5 * arrow_size)));
Vector<Vector2> pts = {
xf.xform(Vector2(arrow_size, 0)),
xf.xform(Vector2(0, 0.5 * arrow_size)),
xf.xform(Vector2(0, -0.5 * arrow_size))
};
Vector<Color> cols;
for (int i = 0; i < 3; i++) {
cols.push_back(draw_col);
}
Vector<Color> cols = { draw_col, draw_col, draw_col };
draw_primitive(pts, cols, Vector<Vector2>());
}

View file

@ -239,14 +239,16 @@ void ShapeCast2D::_notification(int p_what) {
xf.translate(Vector2(target_position.length(), 0));
draw_line(Vector2(), target_position, draw_col, 2);
Vector<Vector2> pts;
float tsize = 8;
pts.push_back(xf.xform(Vector2(tsize, 0)));
pts.push_back(xf.xform(Vector2(0, Math_SQRT12 * tsize)));
pts.push_back(xf.xform(Vector2(0, -Math_SQRT12 * tsize)));
Vector<Color> cols;
for (int i = 0; i < 3; i++)
cols.push_back(draw_col);
Vector<Vector2> pts = {
xf.xform(Vector2(tsize, 0)),
xf.xform(Vector2(0, Math_SQRT12 * tsize)),
xf.xform(Vector2(0, -Math_SQRT12 * tsize))
};
Vector<Color> cols = { draw_col, draw_col, draw_col };
draw_primitive(pts, cols, Vector<Vector2>());
}