Skip to content

Commit 0332b04

Browse files
committed
SFMLv3 Migration. Allow rust-sfml to compile
1 parent 2b3cd27 commit 0332b04

Some content is hidden

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

81 files changed

+1464
-988
lines changed

CSFML/src/Audio/CustomSoundRecorder.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ class sfCustomSoundRecorder final : public sf::SoundRecorder {
1818
myStopCb(onStop),
1919
myUserData(userData) {
2020
}
21-
virtual void setProcessingInterval(int64_t interval) final {
22-
sf::SoundRecorder::setProcessingInterval(sf::microseconds(interval));
23-
}
2421

2522
private:
2623
virtual bool onStart() final {
2724
return myStartCb(myUserData);
2825
}
2926

30-
virtual bool onProcessSamples(const sf::Int16 *samples, std::size_t sampleCount) final {
27+
virtual bool onProcessSamples(const std::int16_t *samples, std::size_t sampleCount) final {
3128
return myProcessCb(samples, sampleCount, myUserData);
3229
}
3330

@@ -64,10 +61,6 @@ extern "C" unsigned int sfCustomSoundRecorder_getSampleRate(const sfCustomSoundR
6461
return soundRecorder->getSampleRate();
6562
}
6663

67-
extern "C" void sfCustomSoundRecorder_setProcessingInterval(sfCustomSoundRecorder *soundRecorder, int64_t interval) {
68-
soundRecorder->setProcessingInterval(interval);
69-
}
70-
7164
extern "C" bool sfCustomSoundRecorder_setDevice(sfCustomSoundRecorder *soundRecorder, const char *name) {
7265
return soundRecorder->setDevice(name);
7366
}

CSFML/src/Audio/CustomSoundStream.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "SFML/Audio/SoundChannel.hpp"
12
#include "System/Vector3.hpp"
23
#include <SFML/Audio/SoundStream.hpp>
34
#include <cstdint>
@@ -11,10 +12,11 @@ class sfCustomSoundStream final : public sf::SoundStream {
1112
sfCustomSoundStreamSeekCb onSeek,
1213
unsigned int channelCount,
1314
unsigned int sampleRate,
15+
const std::vector<sf::SoundChannel> *channel,
1416
void *userData) : myGetDataCb(onGetData),
1517
mySeekCallCb(onSeek),
1618
myUserData(userData) {
17-
initialize(channelCount, sampleRate);
19+
initialize(channelCount, sampleRate, *channel);
1820
}
1921

2022
private:
@@ -35,8 +37,9 @@ extern "C" sfCustomSoundStream *sfCustomSoundStream_new(sfCustomSoundStreamGetDa
3537
sfCustomSoundStreamSeekCb onSeek,
3638
unsigned int channelCount,
3739
unsigned int sampleRate,
40+
const std::vector<sf::SoundChannel> *channel,
3841
void *userData) {
39-
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, userData);
42+
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, channel, userData);
4043
}
4144

4245
extern "C" void sfCustomSoundStream_del(sfCustomSoundStream *soundStream) {
@@ -68,6 +71,10 @@ extern "C" unsigned int sfCustomSoundStream_getSampleRate(const sfCustomSoundStr
6871
return soundStream->getSampleRate();
6972
}
7073

74+
extern "C" const std::vector<sf::SoundChannel> *sfCustomSoundStream_getChannelMap(const sfCustomSoundStream *soundStream) {
75+
return new std::vector(soundStream->getChannelMap());
76+
}
77+
7178
extern "C" void sfCustomSoundStream_setPitch(sfCustomSoundStream *soundStream, float pitch) {
7279
soundStream->setPitch(pitch);
7380
}
@@ -76,8 +83,8 @@ extern "C" void sfCustomSoundStream_setVolume(sfCustomSoundStream *soundStream,
7683
soundStream->setVolume(volume);
7784
}
7885

79-
extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sfVector3f position) {
80-
soundStream->setPosition(position.x, position.y, position.z);
86+
extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sf::Vector3f position) {
87+
soundStream->setPosition(position);
8188
}
8289

8390
extern "C" void sfCustomSoundStream_setRelativeToListener(sfCustomSoundStream *soundStream, bool relative) {
@@ -96,8 +103,8 @@ extern "C" void sfCustomSoundStream_setPlayingOffset(sfCustomSoundStream *soundS
96103
soundStream->setPlayingOffset(sf::microseconds(timeOffset));
97104
}
98105

99-
extern "C" void sfCustomSoundStream_setLoop(sfCustomSoundStream *soundStream, bool loop) {
100-
soundStream->setLoop(loop);
106+
extern "C" void sfCustomSoundStream_setLooping(sfCustomSoundStream *soundStream, bool loop) {
107+
soundStream->setLooping(loop);
101108
}
102109

103110
extern "C" float sfCustomSoundStream_getPitch(const sfCustomSoundStream *soundStream) {
@@ -125,8 +132,8 @@ extern "C" float sfCustomSoundStream_getAttenuation(const sfCustomSoundStream *s
125132
return soundStream->getAttenuation();
126133
}
127134

128-
extern "C" bool sfCustomSoundStream_getLoop(const sfCustomSoundStream *soundStream) {
129-
return soundStream->getLoop();
135+
extern "C" bool sfCustomSoundStream_isLooping(const sfCustomSoundStream *soundStream) {
136+
return soundStream->isLooping();
130137
}
131138

132139
extern "C" int64_t sfCustomSoundStream_getPlayingOffset(const sfCustomSoundStream *soundStream) {

CSFML/src/Audio/Listener.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ extern "C" float sfListener_getGlobalVolume(void) {
99
return sf::Listener::getGlobalVolume();
1010
}
1111

12-
extern "C" void sfListener_setPosition(sfVector3f position) {
13-
sf::Listener::setPosition(position.x, position.y, position.z);
12+
extern "C" void sfListener_setPosition(sf::Vector3f position) {
13+
sf::Listener::setPosition(position);
1414
}
1515

16-
extern "C" sfVector3f sfListener_getPosition() {
16+
extern "C" sf::Vector3f sfListener_getPosition() {
1717
sf::Vector3f pos = sf::Listener::getPosition();
1818
return {pos.x, pos.y, pos.z};
1919
}
2020

21-
extern "C" void sfListener_setDirection(sfVector3f direction) {
22-
sf::Listener::setDirection(direction.x, direction.y, direction.z);
21+
extern "C" void sfListener_setDirection(sf::Vector3f direction) {
22+
sf::Listener::setDirection(direction);
2323
}
2424

25-
extern "C" sfVector3f sfListener_getDirection() {
25+
extern "C" sf::Vector3f sfListener_getDirection() {
2626
sf::Vector3f dir = sf::Listener::getDirection();
2727
return {dir.x, dir.y, dir.z};
2828
}
2929

30-
extern "C" void sfListener_setUpVector(sfVector3f upVector) {
31-
sf::Listener::setUpVector(upVector.x, upVector.y, upVector.z);
30+
extern "C" void sfListener_setUpVector(sf::Vector3f upVector) {
31+
sf::Listener::setUpVector(upVector);
3232
}
3333

34-
extern "C" sfVector3f sfListener_getUpVector() {
34+
extern "C" sf::Vector3f sfListener_getUpVector() {
3535
sf::Vector3f vec = sf::Listener::getUpVector();
3636
return {vec.x, vec.y, vec.z};
3737
}

CSFML/src/Audio/Music.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern "C" void sfMusic_del(sf::Music *music) {
1717
}
1818

1919
extern "C" bool sfMusic_openFromFile(sf::Music *music, const char *filename) {
20-
return music->openFromFile(filename);
20+
return music->openFromFile(std::filesystem::path(filename));
2121
}
2222

2323
extern "C" bool sfMusic_openFromMemory(sf::Music *music, const uint8_t *data, size_t sizeInBytes) {
@@ -28,12 +28,12 @@ extern "C" bool sfMusic_openFromStream(sf::Music *music, sfInputStreamHelper *st
2828
return music->openFromStream(*stream);
2929
}
3030

31-
extern "C" void sfMusic_setLoop(sf::Music *music, bool loop) {
32-
music->setLoop(loop != 0);
31+
extern "C" void sfMusic_setLooping(sf::Music *music, bool loop) {
32+
music->setLooping(loop != 0);
3333
}
3434

35-
extern "C" bool sfMusic_getLoop(const sf::Music *music) {
36-
return music->getLoop();
35+
extern "C" bool sfMusic_isLooping(const sf::Music *music) {
36+
return music->isLooping();
3737
}
3838

3939
extern "C" int64_t sfMusic_getDuration(const sf::Music *music) {
@@ -46,8 +46,8 @@ extern "C" sfTimeSpan sfMusic_getLoopPoints(const sf::Music *music) {
4646
}
4747

4848
extern "C" void sfMusic_setLoopPoints(sf::Music *music, sfTimeSpan timePoints) {
49-
music->setLoopPoints(sf::Music::TimeSpan(sf::microseconds(timePoints.offset),
50-
sf::microseconds(timePoints.length)));
49+
music->setLoopPoints({sf::microseconds(timePoints.offset),
50+
sf::microseconds(timePoints.length)});
5151
}
5252

5353
extern "C" void sfMusic_play(sf::Music *music) {
@@ -87,8 +87,8 @@ extern "C" void sfMusic_setVolume(sf::Music *music, float volume) {
8787
music->setVolume(volume);
8888
}
8989

90-
extern "C" void sfMusic_setPosition(sf::Music *music, sfVector3f position) {
91-
music->setPosition(sf::Vector3f(position.x, position.y, position.z));
90+
extern "C" void sfMusic_setPosition(sf::Music *music, sf::Vector3f position) {
91+
music->setPosition(position);
9292
}
9393

9494
extern "C" void sfMusic_setRelativeToListener(sf::Music *music, bool relative) {

CSFML/src/Audio/Sound.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "System/Vector3.hpp"
2-
#include <SFML/Audio.hpp>
2+
#include <SFML/Audio/Sound.hpp>
3+
#include <SFML/System/Time.hpp>
4+
#include <chrono>
35
#include <cstdint>
46

5-
extern "C" sf::Sound *sfSound_new(void) {
6-
return new sf::Sound;
7+
extern "C" sf::Sound *sfSound_new(const sf::SoundBuffer *buffer) {
8+
return new sf::Sound(*buffer);
79
}
810

911
extern "C" sf::Sound *sfSound_cpy(const sf::Sound *sound) {
@@ -31,16 +33,15 @@ extern "C" void sfSound_setBuffer(sf::Sound *sound, const sf::SoundBuffer *buffe
3133
}
3234

3335
extern "C" const sf::SoundBuffer *sfSound_getBuffer(const sf::Sound *sound) {
34-
const sf::Sound *s = sound;
35-
return s->getBuffer();
36+
return &sound->getBuffer();
3637
}
3738

38-
extern "C" void sfSound_setLoop(sf::Sound *sound, bool loop) {
39-
sound->setLoop(loop);
39+
extern "C" void sfSound_setLooping(sf::Sound *sound, bool loop) {
40+
sound->setLooping(loop);
4041
}
4142

42-
extern "C" bool sfSound_getLoop(const sf::Sound *sound) {
43-
return sound->getLoop();
43+
extern "C" bool sfSound_isLooping(const sf::Sound *sound) {
44+
return sound->isLooping();
4445
}
4546

4647
extern "C" sf::Sound::Status sfSound_getStatus(const sf::Sound *sound) {
@@ -72,7 +73,7 @@ extern "C" void sfSound_setAttenuation(sf::Sound *sound, float attenuation) {
7273
}
7374

7475
extern "C" void sfSound_setPlayingOffset(sf::Sound *sound, int64_t timeOffset) {
75-
sound->setPlayingOffset(sf::microseconds(timeOffset));
76+
sound->setPlayingOffset(std::chrono::microseconds(timeOffset));
7677
}
7778

7879
extern "C" float sfSound_getPitch(const sf::Sound *sound) {

CSFML/src/Audio/SoundBuffer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ extern "C" bool sfSoundBuffer_loadFromStream(sf::SoundBuffer *buffer, sfInputStr
2626
return buffer->loadFromStream(*stream);
2727
}
2828

29-
extern "C" bool sfSoundBuffer_loadFromSamples(sf::SoundBuffer *buffer, const int16_t *samples, uint64_t sampleCount, unsigned int channelCount, unsigned int sampleRate) {
30-
return buffer->loadFromSamples(samples, sampleCount, channelCount, sampleRate);
29+
extern "C" bool sfSoundBuffer_loadFromSamples(sf::SoundBuffer *buffer, const int16_t *samples, uint64_t sampleCount, unsigned int channelCount, unsigned int sampleRate, const std::vector<sf::SoundChannel> *channelMap) {
30+
return buffer->loadFromSamples(samples, sampleCount, channelCount, sampleRate, *channelMap);
3131
}
3232

3333
extern "C" bool sfSoundBuffer_saveToFile(const sf::SoundBuffer *soundBuffer, const char *filename) {

CSFML/src/Audio/SoundChannel.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "Audio/SoundChannel.hpp"
2+
#include <SFML/Audio/SoundChannel.hpp>
3+
#include <vector>
4+
5+
extern "C" std::size_t sfSoundChannelVector_getLength(const std::vector<sf::SoundChannel> *vec) {
6+
return vec->size();
7+
}
8+
9+
extern "C" const sf::SoundChannel *sfSoundChannelVector_getData(const std::vector<sf::SoundChannel> *vec) {
10+
return vec->data();
11+
}
12+
13+
extern "C" void sfSoundChannelVector_del(const std::vector<sf::SoundChannel> *vec) {
14+
delete vec;
15+
}

CSFML/src/Audio/SoundChannel.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
enum sfSoundChannel {
4+
Unspecified,
5+
Mono,
6+
FrontLeft,
7+
FrontRight,
8+
FrontCenter,
9+
FrontLeftOfCenter,
10+
FrontRightOfCenter,
11+
LowFrequencyEffects,
12+
BackLeft,
13+
BackRight,
14+
BackCenter,
15+
SideLeft,
16+
SideRight,
17+
TopCenter,
18+
TopFrontLeft,
19+
TopFrontRight,
20+
TopFrontCenter,
21+
TopBackLeft,
22+
TopBackRight,
23+
TopBackCenter
24+
};

CSFML/src/Graphics/CircleShape.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ extern "C" void sfCircleShape_del(sf::CircleShape *shape) {
1818
}
1919

2020
extern "C" void sfCircleShape_setPosition(sf::CircleShape *shape, sfVector2f position) {
21-
shape->setPosition(position.x, position.y);
21+
shape->setPosition(sf::Vector2f(position.x, position.y));
2222
}
2323

2424
extern "C" void sfCircleShape_setRotation(sf::CircleShape *shape, float angle) {
25-
shape->setRotation(angle);
25+
shape->setRotation(sf::degrees(angle));
2626
}
2727

2828
extern "C" void sfCircleShape_setScale(sf::CircleShape *shape, sfVector2f scale) {
29-
shape->setScale(scale.x, scale.y);
29+
shape->setScale(sf::Vector2f(scale.x, scale.y));
3030
}
3131

3232
extern "C" void sfCircleShape_setOrigin(sf::CircleShape *shape, sfVector2f origin) {
33-
shape->setOrigin(origin.x, origin.y);
33+
shape->setOrigin(sf::Vector2f(origin.x, origin.y));
3434
}
3535

3636
extern "C" sfVector2f sfCircleShape_getPosition(const sf::CircleShape *shape) {
@@ -39,7 +39,7 @@ extern "C" sfVector2f sfCircleShape_getPosition(const sf::CircleShape *shape) {
3939
}
4040

4141
extern "C" float sfCircleShape_getRotation(const sf::CircleShape *shape) {
42-
return shape->getRotation();
42+
return shape->getRotation().asDegrees();
4343
}
4444

4545
extern "C" sfVector2f sfCircleShape_getScale(const sf::CircleShape *shape) {
@@ -53,15 +53,15 @@ extern "C" sfVector2f sfCircleShape_getOrigin(const sf::CircleShape *shape) {
5353
}
5454

5555
extern "C" void sfCircleShape_move(sf::CircleShape *shape, sfVector2f offset) {
56-
shape->move(offset.x, offset.y);
56+
shape->move(sf::Vector2f(offset.x, offset.y));
5757
}
5858

5959
extern "C" void sfCircleShape_rotate(sf::CircleShape *shape, float angle) {
60-
shape->rotate(angle);
60+
shape->rotate(sf::degrees(angle));
6161
}
6262

6363
extern "C" void sfCircleShape_scale(sf::CircleShape *shape, sfVector2f factors) {
64-
shape->scale(factors.x, factors.y);
64+
shape->scale(sf::Vector2f(factors.x, factors.y));
6565
}
6666

6767
extern "C" sf::Transform const *sfCircleShape_getTransform(const sf::CircleShape *shape) {
@@ -77,7 +77,7 @@ extern "C" void sfCircleShape_setTexture(sf::CircleShape *shape, const sf::Textu
7777
}
7878

7979
extern "C" void sfCircleShape_setTextureRect(sf::CircleShape *shape, sfIntRect rect) {
80-
shape->setTextureRect(sf::IntRect(rect.left, rect.top, rect.width, rect.height));
80+
shape->setTextureRect({sf::Vector2i(rect.position.x, rect.position.y), sf::Vector2i(rect.size.x, rect.size.y)});
8181
}
8282

8383
extern "C" void sfCircleShape_setFillColor(sf::CircleShape *shape, sfColor color) {
@@ -98,7 +98,7 @@ extern "C" const sf::Texture *sfCircleShape_getTexture(const sf::CircleShape *sh
9898

9999
extern "C" sfIntRect sfCircleShape_getTextureRect(const sf::CircleShape *shape) {
100100
sf::IntRect rect = shape->getTextureRect();
101-
return {rect.left, rect.top, rect.width, rect.height};
101+
return {rect.position.x, rect.position.y, rect.size.x, rect.size.y};
102102
}
103103

104104
extern "C" sfColor sfCircleShape_getFillColor(const sf::CircleShape *shape) {
@@ -138,10 +138,10 @@ extern "C" void sfCircleShape_setPointCount(sf::CircleShape *shape, size_t count
138138

139139
extern "C" sfFloatRect sfCircleShape_getLocalBounds(const sf::CircleShape *shape) {
140140
sf::FloatRect rect = shape->getLocalBounds();
141-
return {rect.left, rect.top, rect.width, rect.height};
141+
return {rect.position.x, rect.position.y, rect.size.x, rect.size.y};
142142
}
143143

144144
extern "C" sfFloatRect sfCircleShape_getGlobalBounds(const sf::CircleShape *shape) {
145145
sf::FloatRect rect = shape->getGlobalBounds();
146-
return {rect.left, rect.top, rect.width, rect.height};
146+
return {rect.position.x, rect.position.y, rect.size.x, rect.size.y};
147147
}

0 commit comments

Comments
 (0)