Skip to content

Commit fa5d18d

Browse files
committed
Use inheritance to remove This data member
It's reasonable to say that, for example, sfImage _is_ an sf::Image. This "is-a" relationship is what inheritance does a very good job modeling. By using inheritance to implement CSFML types in terms of their SFML counterpart, we get code that is simpler and easier to read. We also avoid some of the extra "dancing" required to construct a CSFML type from an SFML type. This improves the encapsulation of our CSFML implementation.
1 parent 21d4571 commit fa5d18d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+439
-486
lines changed

src/CSFML/Audio/Sound.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
sfSound* sfSound_create(const sfSoundBuffer* buffer)
3535
{
3636
assert(buffer);
37-
return new sfSound{sf::Sound(buffer->This), buffer};
37+
return new sfSound{sf::Sound(*buffer), buffer};
3838
}
3939

4040

@@ -83,7 +83,7 @@ void sfSound_setBuffer(sfSound* sound, const sfSoundBuffer* buffer)
8383
if (buffer)
8484
{
8585
assert(sound);
86-
sound->This.setBuffer(buffer->This);
86+
sound->This.setBuffer(*buffer);
8787
sound->Buffer = buffer;
8888
}
8989
}

src/CSFML/Audio/SoundBuffer.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,45 +109,45 @@ bool sfSoundBuffer_saveToFile(const sfSoundBuffer* soundBuffer, const char* file
109109
{
110110
assert(soundBuffer);
111111
assert(filename);
112-
return soundBuffer->This.saveToFile(filename);
112+
return soundBuffer->saveToFile(filename);
113113
}
114114

115115

116116
////////////////////////////////////////////////////////////
117117
const int16_t* sfSoundBuffer_getSamples(const sfSoundBuffer* soundBuffer)
118118
{
119119
assert(soundBuffer);
120-
return soundBuffer->This.getSamples();
120+
return soundBuffer->getSamples();
121121
}
122122

123123

124124
////////////////////////////////////////////////////////////
125125
uint64_t sfSoundBuffer_getSampleCount(const sfSoundBuffer* soundBuffer)
126126
{
127127
assert(soundBuffer);
128-
return soundBuffer->This.getSampleCount();
128+
return soundBuffer->getSampleCount();
129129
}
130130

131131

132132
////////////////////////////////////////////////////////////
133133
unsigned int sfSoundBuffer_getSampleRate(const sfSoundBuffer* soundBuffer)
134134
{
135135
assert(soundBuffer);
136-
return soundBuffer->This.getSampleRate();
136+
return soundBuffer->getSampleRate();
137137
}
138138

139139

140140
////////////////////////////////////////////////////////////
141141
unsigned int sfSoundBuffer_getChannelCount(const sfSoundBuffer* soundBuffer)
142142
{
143143
assert(soundBuffer);
144-
return soundBuffer->This.getChannelCount();
144+
return soundBuffer->getChannelCount();
145145
}
146146

147147

148148
////////////////////////////////////////////////////////////
149149
sfTime sfSoundBuffer_getDuration(const sfSoundBuffer* soundBuffer)
150150
{
151151
assert(soundBuffer);
152-
return {soundBuffer->This.getDuration().asMicroseconds()};
152+
return {soundBuffer->getDuration().asMicroseconds()};
153153
}

src/CSFML/Audio/SoundBufferRecorder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const sfSoundBuffer* sfSoundBufferRecorder_getBuffer(const sfSoundBufferRecorder
7272
{
7373
assert(soundBufferRecorder);
7474

75-
soundBufferRecorder->SoundBuffer.This = soundBufferRecorder->This.getBuffer();
75+
soundBufferRecorder->SoundBuffer = sfSoundBuffer{soundBufferRecorder->This.getBuffer()};
7676

7777
return &soundBufferRecorder->SoundBuffer;
7878
}

src/CSFML/Audio/SoundBufferStruct.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
////////////////////////////////////////////////////////////
3434
// Internal structure of sfSoundBuffer
3535
////////////////////////////////////////////////////////////
36-
struct sfSoundBuffer
36+
struct sfSoundBuffer : sf::SoundBuffer
3737
{
38-
sf::SoundBuffer This;
3938
};

src/CSFML/Graphics/CircleShape.cpp

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,95 +64,95 @@ void sfCircleShape_destroy(const sfCircleShape* shape)
6464
void sfCircleShape_setPosition(sfCircleShape* shape, sfVector2f position)
6565
{
6666
assert(shape);
67-
shape->This.setPosition(convertVector2(position));
67+
shape->setPosition(convertVector2(position));
6868
}
6969

7070

7171
////////////////////////////////////////////////////////////
7272
void sfCircleShape_setRotation(sfCircleShape* shape, float angle)
7373
{
7474
assert(shape);
75-
shape->This.setRotation(sf::degrees(angle));
75+
shape->setRotation(sf::degrees(angle));
7676
}
7777

7878

7979
////////////////////////////////////////////////////////////
8080
void sfCircleShape_setScale(sfCircleShape* shape, sfVector2f scale)
8181
{
8282
assert(shape);
83-
shape->This.setScale(convertVector2(scale));
83+
shape->setScale(convertVector2(scale));
8484
}
8585

8686

8787
////////////////////////////////////////////////////////////
8888
void sfCircleShape_setOrigin(sfCircleShape* shape, sfVector2f origin)
8989
{
9090
assert(shape);
91-
shape->This.setOrigin(convertVector2(origin));
91+
shape->setOrigin(convertVector2(origin));
9292
}
9393

9494

9595
////////////////////////////////////////////////////////////
9696
sfVector2f sfCircleShape_getPosition(const sfCircleShape* shape)
9797
{
9898
assert(shape);
99-
return convertVector2(shape->This.getPosition());
99+
return convertVector2(shape->getPosition());
100100
}
101101

102102

103103
////////////////////////////////////////////////////////////
104104
float sfCircleShape_getRotation(const sfCircleShape* shape)
105105
{
106106
assert(shape);
107-
return shape->This.getRotation().asDegrees();
107+
return shape->getRotation().asDegrees();
108108
}
109109

110110

111111
////////////////////////////////////////////////////////////
112112
sfVector2f sfCircleShape_getScale(const sfCircleShape* shape)
113113
{
114114
assert(shape);
115-
return convertVector2(shape->This.getScale());
115+
return convertVector2(shape->getScale());
116116
}
117117

118118

119119
////////////////////////////////////////////////////////////
120120
sfVector2f sfCircleShape_getOrigin(const sfCircleShape* shape)
121121
{
122122
assert(shape);
123-
return convertVector2(shape->This.getOrigin());
123+
return convertVector2(shape->getOrigin());
124124
}
125125

126126

127127
////////////////////////////////////////////////////////////
128128
void sfCircleShape_move(sfCircleShape* shape, sfVector2f offset)
129129
{
130130
assert(shape);
131-
shape->This.move(convertVector2(offset));
131+
shape->move(convertVector2(offset));
132132
}
133133

134134

135135
////////////////////////////////////////////////////////////
136136
void sfCircleShape_rotate(sfCircleShape* shape, float angle)
137137
{
138138
assert(shape);
139-
shape->This.rotate(sf::degrees(angle));
139+
shape->rotate(sf::degrees(angle));
140140
}
141141

142142

143143
////////////////////////////////////////////////////////////
144144
void sfCircleShape_scale(sfCircleShape* shape, sfVector2f factors)
145145
{
146146
assert(shape);
147-
shape->This.scale(convertVector2(factors));
147+
shape->scale(convertVector2(factors));
148148
}
149149

150150

151151
////////////////////////////////////////////////////////////
152152
sfTransform sfCircleShape_getTransform(const sfCircleShape* shape)
153153
{
154154
assert(shape);
155-
shape->Transform = convertTransform(shape->This.getTransform());
155+
shape->Transform = convertTransform(shape->getTransform());
156156
return shape->Transform;
157157
}
158158

@@ -161,7 +161,7 @@ sfTransform sfCircleShape_getTransform(const sfCircleShape* shape)
161161
sfTransform sfCircleShape_getInverseTransform(const sfCircleShape* shape)
162162
{
163163
assert(shape);
164-
shape->InverseTransform = convertTransform(shape->This.getInverseTransform());
164+
shape->InverseTransform = convertTransform(shape->getInverseTransform());
165165
return shape->InverseTransform;
166166
}
167167

@@ -170,7 +170,7 @@ sfTransform sfCircleShape_getInverseTransform(const sfCircleShape* shape)
170170
void sfCircleShape_setTexture(sfCircleShape* shape, const sfTexture* texture, bool resetRect)
171171
{
172172
assert(shape);
173-
shape->This.setTexture(texture ? texture->This : nullptr, resetRect);
173+
shape->setTexture(texture ? texture->This : nullptr, resetRect);
174174
shape->Texture = texture;
175175
}
176176

@@ -179,31 +179,31 @@ void sfCircleShape_setTexture(sfCircleShape* shape, const sfTexture* texture, bo
179179
void sfCircleShape_setTextureRect(sfCircleShape* shape, sfIntRect rect)
180180
{
181181
assert(shape);
182-
shape->This.setTextureRect(convertRect(rect));
182+
shape->setTextureRect(convertRect(rect));
183183
}
184184

185185

186186
////////////////////////////////////////////////////////////
187187
void sfCircleShape_setFillColor(sfCircleShape* shape, sfColor color)
188188
{
189189
assert(shape);
190-
shape->This.setFillColor(convertColor(color));
190+
shape->setFillColor(convertColor(color));
191191
}
192192

193193

194194
////////////////////////////////////////////////////////////
195195
void sfCircleShape_setOutlineColor(sfCircleShape* shape, sfColor color)
196196
{
197197
assert(shape);
198-
shape->This.setOutlineColor(convertColor(color));
198+
shape->setOutlineColor(convertColor(color));
199199
}
200200

201201

202202
////////////////////////////////////////////////////////////
203203
void sfCircleShape_setOutlineThickness(sfCircleShape* shape, float thickness)
204204
{
205205
assert(shape);
206-
shape->This.setOutlineThickness(thickness);
206+
shape->setOutlineThickness(thickness);
207207
}
208208

209209

@@ -219,85 +219,85 @@ const sfTexture* sfCircleShape_getTexture(const sfCircleShape* shape)
219219
sfIntRect sfCircleShape_getTextureRect(const sfCircleShape* shape)
220220
{
221221
assert(shape);
222-
return convertRect(shape->This.getTextureRect());
222+
return convertRect(shape->getTextureRect());
223223
}
224224

225225

226226
////////////////////////////////////////////////////////////
227227
sfColor sfCircleShape_getFillColor(const sfCircleShape* shape)
228228
{
229229
assert(shape);
230-
return convertColor(shape->This.getFillColor());
230+
return convertColor(shape->getFillColor());
231231
}
232232

233233

234234
////////////////////////////////////////////////////////////
235235
sfColor sfCircleShape_getOutlineColor(const sfCircleShape* shape)
236236
{
237237
assert(shape);
238-
return convertColor(shape->This.getOutlineColor());
238+
return convertColor(shape->getOutlineColor());
239239
}
240240

241241

242242
////////////////////////////////////////////////////////////
243243
float sfCircleShape_getOutlineThickness(const sfCircleShape* shape)
244244
{
245245
assert(shape);
246-
return shape->This.getOutlineThickness();
246+
return shape->getOutlineThickness();
247247
}
248248

249249

250250
////////////////////////////////////////////////////////////
251251
size_t sfCircleShape_getPointCount(const sfCircleShape* shape)
252252
{
253253
assert(shape);
254-
return shape->This.getPointCount();
254+
return shape->getPointCount();
255255
}
256256

257257

258258
////////////////////////////////////////////////////////////
259259
sfVector2f sfCircleShape_getPoint(const sfCircleShape* shape, size_t index)
260260
{
261261
assert(shape);
262-
return convertVector2(shape->This.getPoint(index));
262+
return convertVector2(shape->getPoint(index));
263263
}
264264

265265

266266
////////////////////////////////////////////////////////////
267267
void sfCircleShape_setRadius(sfCircleShape* shape, float radius)
268268
{
269269
assert(shape);
270-
shape->This.setRadius(radius);
270+
shape->setRadius(radius);
271271
}
272272

273273

274274
////////////////////////////////////////////////////////////
275275
float sfCircleShape_getRadius(const sfCircleShape* shape)
276276
{
277277
assert(shape);
278-
return shape->This.getRadius();
278+
return shape->getRadius();
279279
}
280280

281281

282282
////////////////////////////////////////////////////////////
283283
void sfCircleShape_setPointCount(sfCircleShape* shape, size_t count)
284284
{
285285
assert(shape);
286-
shape->This.setPointCount(count);
286+
shape->setPointCount(count);
287287
}
288288

289289

290290
////////////////////////////////////////////////////////////
291291
sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape)
292292
{
293293
assert(shape);
294-
return convertRect(shape->This.getLocalBounds());
294+
return convertRect(shape->getLocalBounds());
295295
}
296296

297297

298298
////////////////////////////////////////////////////////////
299299
sfFloatRect sfCircleShape_getGlobalBounds(const sfCircleShape* shape)
300300
{
301301
assert(shape);
302-
return convertRect(shape->This.getGlobalBounds());
302+
return convertRect(shape->getGlobalBounds());
303303
}

src/CSFML/Graphics/CircleShapeStruct.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
////////////////////////////////////////////////////////////
3737
// Internal structure of sfCircleShape
3838
////////////////////////////////////////////////////////////
39-
struct sfCircleShape
39+
struct sfCircleShape : sf::CircleShape
4040
{
41-
sf::CircleShape This;
4241
const sfTexture* Texture{};
4342
mutable sfTransform Transform{};
4443
mutable sfTransform InverseTransform{};

0 commit comments

Comments
 (0)