Skip to content

Commit ef81fbd

Browse files
ZXShadyChrisThrasher
authored andcommitted
use aggregate initialization
1 parent 84f580e commit ef81fbd

File tree

5 files changed

+53
-70
lines changed

5 files changed

+53
-70
lines changed

src/CSFML/Graphics/Color.cpp

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,26 @@ const sfColor sfTransparent = sfColor_fromRGBA(0, 0, 0, 0);
4545
////////////////////////////////////////////////////////////
4646
sfColor sfColor_fromRGB(uint8_t red, uint8_t green, uint8_t blue)
4747
{
48-
return sfColor_fromRGBA(red, green, blue, 255);
48+
return {red, green, blue, 255};
4949
}
5050

5151

5252
////////////////////////////////////////////////////////////
5353
sfColor sfColor_fromRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
5454
{
55-
sfColor color;
56-
57-
color.r = red;
58-
color.g = green;
59-
color.b = blue;
60-
color.a = alpha;
61-
62-
return color;
55+
return {red, green, blue, alpha};
6356
}
6457

6558

6659
////////////////////////////////////////////////////////////
6760
sfColor sfColor_fromInteger(uint32_t color)
6861
{
69-
auto red = static_cast<uint8_t>((color & 0xff000000) >> 24);
70-
auto green = static_cast<uint8_t>((color & 0x00ff0000) >> 16);
71-
auto blue = static_cast<uint8_t>((color & 0x0000ff00) >> 8);
72-
auto alpha = static_cast<uint8_t>((color & 0x000000ff) >> 0);
73-
74-
return sfColor_fromRGBA(red, green, blue, alpha);
62+
return {
63+
static_cast<uint8_t>((color & 0xff000000) >> 24),
64+
static_cast<uint8_t>((color & 0x00ff0000) >> 16),
65+
static_cast<uint8_t>((color & 0x0000ff00) >> 8),
66+
static_cast<uint8_t>((color & 0x000000ff) >> 0),
67+
};
7568
}
7669

7770

@@ -85,43 +78,34 @@ uint32_t sfColor_toInteger(sfColor color)
8578
////////////////////////////////////////////////////////////
8679
sfColor sfColor_add(sfColor color1, sfColor color2)
8780
{
88-
int red = std::min(color1.r + color2.r, 255);
89-
int green = std::min(color1.g + color2.g, 255);
90-
int blue = std::min(color1.b + color2.b, 255);
91-
int alpha = std::min(color1.a + color2.a, 255);
92-
93-
return sfColor_fromRGBA(static_cast<uint8_t>(red),
94-
static_cast<uint8_t>(green),
95-
static_cast<uint8_t>(blue),
96-
static_cast<uint8_t>(alpha));
81+
return {
82+
static_cast<uint8_t>(std::min(color1.r + color2.r, 255)),
83+
static_cast<uint8_t>(std::min(color1.g + color2.g, 255)),
84+
static_cast<uint8_t>(std::min(color1.b + color2.b, 255)),
85+
static_cast<uint8_t>(std::min(color1.a + color2.a, 255)),
86+
};
9787
}
9888

9989

10090
////////////////////////////////////////////////////////////
10191
sfColor sfColor_subtract(sfColor color1, sfColor color2)
10292
{
103-
int red = std::max(color1.r - color2.r, 0);
104-
int green = std::max(color1.g - color2.g, 0);
105-
int blue = std::max(color1.b - color2.b, 0);
106-
int alpha = std::max(color1.a - color2.a, 0);
107-
108-
return sfColor_fromRGBA(static_cast<uint8_t>(red),
109-
static_cast<uint8_t>(green),
110-
static_cast<uint8_t>(blue),
111-
static_cast<uint8_t>(alpha));
93+
return {
94+
static_cast<uint8_t>(std::max(color1.r - color2.r, 0)),
95+
static_cast<uint8_t>(std::max(color1.g - color2.g, 0)),
96+
static_cast<uint8_t>(std::max(color1.b - color2.b, 0)),
97+
static_cast<uint8_t>(std::max(color1.a - color2.a, 0)),
98+
};
11299
}
113100

114101

115102
////////////////////////////////////////////////////////////
116103
sfColor sfColor_modulate(sfColor color1, sfColor color2)
117104
{
118-
int red = color1.r * color2.r / 255;
119-
int green = color1.g * color2.g / 255;
120-
int blue = color1.b * color2.b / 255;
121-
int alpha = color1.a * color2.a / 255;
122-
123-
return sfColor_fromRGBA(static_cast<uint8_t>(red),
124-
static_cast<uint8_t>(green),
125-
static_cast<uint8_t>(blue),
126-
static_cast<uint8_t>(alpha));
105+
return {
106+
static_cast<uint8_t>(color1.r * color2.r / 255),
107+
static_cast<uint8_t>(color1.g * color2.g / 255),
108+
static_cast<uint8_t>(color1.b * color2.b / 255),
109+
static_cast<uint8_t>(color1.a * color2.a / 255),
110+
};
127111
}

src/CSFML/Graphics/Shader.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,14 @@ void sfShader_setVec4Uniform(sfShader* shader, const char* name, sfGlslVec4 vect
201201
////////////////////////////////////////////////////////////
202202
void sfShader_setColorUniform(sfShader* shader, const char* name, sfColor color)
203203
{
204-
sfGlslVec4 vec4;
205-
vec4.x = color.r / 255.f;
206-
vec4.y = color.g / 255.f;
207-
vec4.z = color.b / 255.f;
208-
vec4.w = color.a / 255.f;
209-
210-
sfShader_setVec4Uniform(shader, name, vec4);
204+
sfShader_setVec4Uniform(shader,
205+
name,
206+
{
207+
color.r / 255.f,
208+
color.g / 255.f,
209+
color.b / 255.f,
210+
color.a / 255.f,
211+
});
211212
}
212213

213214
////////////////////////////////////////////////////////////
@@ -249,13 +250,14 @@ void sfShader_setIvec4Uniform(sfShader* shader, const char* name, sfGlslIvec4 ve
249250
////////////////////////////////////////////////////////////
250251
void sfShader_setIntColorUniform(sfShader* shader, const char* name, sfColor color)
251252
{
252-
sfGlslIvec4 ivec4;
253-
ivec4.x = static_cast<int>(color.r);
254-
ivec4.y = static_cast<int>(color.g);
255-
ivec4.z = static_cast<int>(color.b);
256-
ivec4.w = static_cast<int>(color.a);
257-
258-
sfShader_setIvec4Uniform(shader, name, ivec4);
253+
sfShader_setIvec4Uniform(shader,
254+
name,
255+
{
256+
static_cast<int>(color.r),
257+
static_cast<int>(color.g),
258+
static_cast<int>(color.b),
259+
static_cast<int>(color.a),
260+
});
259261
}
260262

261263
////////////////////////////////////////////////////////////

src/CSFML/Graphics/Transform.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ const sfTransform sfTransform_Identity = {
4848
////////////////////////////////////////////////////////////
4949
sfTransform sfTransform_fromMatrix(float a00, float a01, float a02, float a10, float a11, float a12, float a20, float a21, float a22)
5050
{
51-
sfTransform transform = {a00, a01, a02, a10, a11, a12, a20, a21, a22};
52-
return transform;
51+
// clang-format off
52+
return {
53+
a00, a01, a02,
54+
a10, a11, a12,
55+
a20, a21, a22,
56+
};
57+
// clang-format on
5358
}
5459

5560

src/CSFML/Graphics/Transformable.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
////////////////////////////////////////////////////////////
3535
sfTransformable* sfTransformable_create()
3636
{
37-
auto* transformable = new sfTransformable;
38-
39-
return transformable;
37+
return new sfTransformable;
4038
}
4139

4240

src/CSFML/System/Time.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,19 @@ int64_t sfTime_asMicroseconds(sfTime time)
5656
////////////////////////////////////////////////////////////
5757
sfTime sfSeconds(float amount)
5858
{
59-
sfTime time;
60-
time.microseconds = static_cast<int64_t>(amount * 1000000);
61-
return time;
59+
return {static_cast<int64_t>(amount * 1000000)};
6260
}
6361

6462

6563
////////////////////////////////////////////////////////////
6664
sfTime sfMilliseconds(int32_t amount)
6765
{
68-
sfTime time;
69-
time.microseconds = static_cast<int64_t>(amount) * 1000;
70-
return time;
66+
return {static_cast<int64_t>(amount * 1000)};
7167
}
7268

7369

7470
////////////////////////////////////////////////////////////
7571
sfTime sfMicroseconds(int64_t amount)
7672
{
77-
sfTime time;
78-
time.microseconds = amount;
79-
return time;
73+
return {amount};
8074
}

0 commit comments

Comments
 (0)