Skip to content

Commit da4caec

Browse files
Merge pull request #338 from dogunbound/sfmlv3
sfmlv3 migration PR
2 parents 6d458da + a896271 commit da4caec

File tree

147 files changed

+5292
-1649
lines changed

Some content is hidden

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

147 files changed

+5292
-1649
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Install deps
3737
run: |
3838
sudo apt-get update
39-
sudo apt-get install libpthread-stubs0-dev libgl1-mesa-dev libx11-dev libx11-xcb-dev libxcb-image0-dev libxrandr-dev libxcb-randr0-dev libudev-dev libfreetype6-dev libglew-dev libjpeg8-dev libgpgme11-dev libsndfile1-dev libopenal-dev libjpeg62 libxcursor-dev cmake libclang-dev clang libflac-dev
39+
sudo apt-get install libpthread-stubs0-dev libgl1-mesa-dev libx11-dev libx11-xcb-dev libxcb-image0-dev libxrandr-dev libxcb-randr0-dev libudev-dev libfreetype6-dev libglew-dev libjpeg8-dev libgpgme11-dev libsndfile1-dev libopenal-dev libjpeg62 libxcursor-dev cmake libclang-dev clang libflac-dev libxi-dev
4040
- name: Build
4141
run: |
4242
git submodule update --init

.github/workflows/windows.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ jobs:
3636
- uses: actions/checkout@v4
3737
- name: Build
3838
run: |
39-
git submodule update --init
40-
cp .\SFML\extlibs\bin\x64\openal32.dll .
39+
git submodule update --init --recursive
4140
cargo build --verbose
4241
- name: Run tests
4342
run: |

CSFML/src/Audio/CustomSoundRecorder.cpp

Lines changed: 1 addition & 8 deletions
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

Lines changed: 141 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
#include "Audio/EffectProcessor.hpp"
2+
#include "Audio/SoundSourceCone.hpp"
3+
#include "Audio/SoundStatus.hpp"
4+
#include "Audio/SoundChannel.hpp"
5+
#include "SFML/Audio/SoundChannel.hpp"
16
#include "System/Vector3.hpp"
27
#include <SFML/Audio/SoundStream.hpp>
3-
#include <cstdint>
8+
#include <cstdio>
9+
#include <map>
10+
#include <mutex>
411

512
typedef bool (*sfCustomSoundStreamGetDataCb)(sf::SoundStream::Chunk *, void *);
613
typedef void (*sfCustomSoundStreamSeekCb)(int64_t, void *);
@@ -11,10 +18,16 @@ class sfCustomSoundStream final : public sf::SoundStream {
1118
sfCustomSoundStreamSeekCb onSeek,
1219
unsigned int channelCount,
1320
unsigned int sampleRate,
21+
const sfSoundChannel *soundChannels,
22+
size_t soundChannelMapLen,
1423
void *userData) : myGetDataCb(onGetData),
1524
mySeekCallCb(onSeek),
1625
myUserData(userData) {
17-
initialize(channelCount, sampleRate);
26+
std::vector<sf::SoundChannel> castedSoundChannels(soundChannelMapLen);
27+
for (size_t i = 0; i < soundChannelMapLen; i++) {
28+
castedSoundChannels.push_back(static_cast<sf::SoundChannel>(soundChannels[i]));
29+
}
30+
initialize(channelCount, sampleRate, castedSoundChannels);
1831
}
1932

2033
private:
@@ -35,12 +48,10 @@ extern "C" sfCustomSoundStream *sfCustomSoundStream_new(sfCustomSoundStreamGetDa
3548
sfCustomSoundStreamSeekCb onSeek,
3649
unsigned int channelCount,
3750
unsigned int sampleRate,
51+
const sfSoundChannel *channelMap,
52+
size_t soundChannelMapLen,
3853
void *userData) {
39-
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, userData);
40-
}
41-
42-
extern "C" void sfCustomSoundStream_del(sfCustomSoundStream *soundStream) {
43-
delete soundStream;
54+
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, channelMap, soundChannelMapLen, userData);
4455
}
4556

4657
extern "C" void sfCustomSoundStream_play(sfCustomSoundStream *soundStream) {
@@ -55,9 +66,8 @@ extern "C" void sfCustomSoundStream_stop(sfCustomSoundStream *soundStream) {
5566
soundStream->stop();
5667
}
5768

58-
extern "C" sf::SoundStream::Status sfCustomSoundStream_getStatus(const sfCustomSoundStream *soundStream) {
59-
60-
return soundStream->getStatus();
69+
extern "C" sfSoundStatus sfCustomSoundStream_getStatus(const sfCustomSoundStream *soundStream) {
70+
return static_cast<sfSoundStatus>(soundStream->getStatus());
6171
}
6272

6373
extern "C" unsigned int sfCustomSoundStream_getChannelCount(const sfCustomSoundStream *soundStream) {
@@ -68,16 +78,48 @@ extern "C" unsigned int sfCustomSoundStream_getSampleRate(const sfCustomSoundStr
6878
return soundStream->getSampleRate();
6979
}
7080

81+
extern "C" const std::vector<sf::SoundChannel> *sfCustomSoundStream_getChannelMap(const sfCustomSoundStream *soundStream) {
82+
return new std::vector(soundStream->getChannelMap());
83+
}
84+
7185
extern "C" void sfCustomSoundStream_setPitch(sfCustomSoundStream *soundStream, float pitch) {
7286
soundStream->setPitch(pitch);
7387
}
7488

89+
extern "C" void sfCustomSoundStream_setPan(sfCustomSoundStream *soundStream, float pan) {
90+
soundStream->setPan(pan);
91+
}
92+
7593
extern "C" void sfCustomSoundStream_setVolume(sfCustomSoundStream *soundStream, float volume) {
7694
soundStream->setVolume(volume);
7795
}
7896

79-
extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sfVector3f position) {
80-
soundStream->setPosition(position.x, position.y, position.z);
97+
extern "C" void sfCustomSoundStream_setSpatializationEnabled(sfCustomSoundStream *soundStream, bool enabled) {
98+
soundStream->setSpatializationEnabled(enabled);
99+
}
100+
101+
extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sf::Vector3f position) {
102+
soundStream->setPosition(position);
103+
}
104+
105+
extern "C" void sfCustomSoundStream_setDirection(sfCustomSoundStream *soundStream, sfVector3f position) {
106+
soundStream->setDirection(convertVector3(position));
107+
}
108+
109+
extern "C" void sfCustomSoundStream_setCone(sfCustomSoundStream *soundStream, sfSoundSourceCone cone) {
110+
soundStream->setCone(convertCone(cone));
111+
}
112+
113+
extern "C" void sfCustomSoundStream_setVelocity(sfCustomSoundStream *soundStream, sfVector3f velocity) {
114+
soundStream->setVelocity(convertVector3(velocity));
115+
}
116+
117+
extern "C" void sfCustomSoundStream_setDopplerFactor(sfCustomSoundStream *soundStream, float factor) {
118+
soundStream->setDopplerFactor(factor);
119+
}
120+
121+
extern "C" void sfCustomSoundStream_setDirectionalAttenuationFactor(sfCustomSoundStream *soundStream, float factor) {
122+
soundStream->setDirectionalAttenuationFactor(factor);
81123
}
82124

83125
extern "C" void sfCustomSoundStream_setRelativeToListener(sfCustomSoundStream *soundStream, bool relative) {
@@ -88,6 +130,18 @@ extern "C" void sfCustomSoundStream_setMinDistance(sfCustomSoundStream *soundStr
88130
soundStream->setMinDistance(distance);
89131
}
90132

133+
extern "C" void sfCustomSoundStream_setMaxDistance(sfCustomSoundStream *soundStream, float distance) {
134+
soundStream->setMaxDistance(distance);
135+
}
136+
137+
extern "C" void sfCustomSoundStream_setMinGain(sfCustomSoundStream *soundStream, float gain) {
138+
soundStream->setMinGain(gain);
139+
}
140+
141+
extern "C" void sfCustomSoundStream_setMaxGain(sfCustomSoundStream *soundStream, float gain) {
142+
soundStream->setMaxGain(gain);
143+
}
144+
91145
extern "C" void sfCustomSoundStream_setAttenuation(sfCustomSoundStream *soundStream, float attenuation) {
92146
soundStream->setAttenuation(attenuation);
93147
}
@@ -96,21 +150,48 @@ extern "C" void sfCustomSoundStream_setPlayingOffset(sfCustomSoundStream *soundS
96150
soundStream->setPlayingOffset(sf::microseconds(timeOffset));
97151
}
98152

99-
extern "C" void sfCustomSoundStream_setLoop(sfCustomSoundStream *soundStream, bool loop) {
100-
soundStream->setLoop(loop);
153+
extern "C" void sfCustomSoundStream_setLooping(sfCustomSoundStream *soundStream, bool loop) {
154+
soundStream->setLooping(loop);
101155
}
102156

103157
extern "C" float sfCustomSoundStream_getPitch(const sfCustomSoundStream *soundStream) {
104158
return soundStream->getPitch();
105159
}
106160

161+
extern "C" float sfCustomSoundStream_getPan(const sfCustomSoundStream *soundStream) {
162+
return soundStream->getPan();
163+
}
164+
107165
extern "C" float sfCustomSoundStream_getVolume(const sfCustomSoundStream *soundStream) {
108166
return soundStream->getVolume();
109167
}
110168

169+
extern "C" bool sfCustomSoundStream_isSpatializationEnabled(const sfCustomSoundStream *soundStream) {
170+
return soundStream->isSpatializationEnabled();
171+
}
172+
111173
extern "C" sfVector3f sfCustomSoundStream_getPosition(const sfCustomSoundStream *soundStream) {
112-
sf::Vector3f pos = soundStream->getPosition();
113-
return {pos.x, pos.y, pos.z};
174+
return convertVector3(soundStream->getPosition());
175+
}
176+
177+
extern "C" sfVector3f sfCustomSoundStream_getDirection(const sfCustomSoundStream *soundStream) {
178+
return convertVector3(soundStream->getDirection());
179+
}
180+
181+
extern "C" sfSoundSourceCone sfCustomSoundStream_getCone(const sfCustomSoundStream *soundStream) {
182+
return convertCone(soundStream->getCone());
183+
}
184+
185+
extern "C" sfVector3f sfCustomSoundStream_getVelocity(const sfCustomSoundStream *soundStream) {
186+
return convertVector3(soundStream->getVelocity());
187+
}
188+
189+
extern "C" float sfCustomSoundStream_getDopplerFactor(const sfCustomSoundStream *soundStream) {
190+
return soundStream->getDopplerFactor();
191+
}
192+
193+
extern "C" float sfCustomSoundStream_getDirectionalAttenuationFactor(const sfCustomSoundStream *soundStream) {
194+
return soundStream->getDirectionalAttenuationFactor();
114195
}
115196

116197
extern "C" bool sfCustomSoundStream_isRelativeToListener(const sfCustomSoundStream *soundStream) {
@@ -121,14 +202,56 @@ extern "C" float sfCustomSoundStream_getMinDistance(const sfCustomSoundStream *s
121202
return soundStream->getMinDistance();
122203
}
123204

205+
extern "C" float sfCustomSoundStream_getMaxDistance(const sfCustomSoundStream *soundStream) {
206+
return soundStream->getMaxDistance();
207+
}
208+
209+
extern "C" float sfCustomSoundStream_getMinGain(const sfCustomSoundStream *soundStream) {
210+
return soundStream->getMinGain();
211+
}
212+
213+
extern "C" float sfCustomSoundStream_getMaxGain(const sfCustomSoundStream *soundStream) {
214+
return soundStream->getMaxGain();
215+
}
216+
124217
extern "C" float sfCustomSoundStream_getAttenuation(const sfCustomSoundStream *soundStream) {
125218
return soundStream->getAttenuation();
126219
}
127220

128-
extern "C" bool sfCustomSoundStream_getLoop(const sfCustomSoundStream *soundStream) {
129-
return soundStream->getLoop();
221+
extern "C" bool sfCustomSoundStream_isLooping(const sfCustomSoundStream *soundStream) {
222+
return soundStream->isLooping();
130223
}
131224

132225
extern "C" int64_t sfCustomSoundStream_getPlayingOffset(const sfCustomSoundStream *soundStream) {
133226
return soundStream->getPlayingOffset().asMicroseconds();
134227
}
228+
229+
static std::map<sfCustomSoundStream *, std::pair<sfEffectProcessor, void *>> processors;
230+
static std::mutex processorMutex;
231+
232+
extern "C" void sfCustomSoundStream_setEffectProcessor(sfCustomSoundStream *soundStream, sfEffectProcessor effectProcessor, void *userData) {
233+
std::unique_lock<std::mutex> lock(processorMutex);
234+
if (!effectProcessor) {
235+
processors.erase(soundStream);
236+
soundStream->setEffectProcessor(nullptr);
237+
} else {
238+
processors[soundStream] = {effectProcessor, userData};
239+
soundStream->setEffectProcessor(
240+
[soundStream](const float *inputFrames,
241+
unsigned int &inputFrameCount,
242+
float *outputFrames,
243+
unsigned int &outputFrameCount,
244+
unsigned int frameChannelCount) {
245+
std::unique_lock<std::mutex> lock(processorMutex);
246+
auto it = processors.find(soundStream);
247+
if (it != processors.end()) {
248+
it->second.first(inputFrames, &inputFrameCount, outputFrames, &outputFrameCount, frameChannelCount, it->second.second);
249+
}
250+
});
251+
}
252+
}
253+
254+
extern "C" void sfCustomSoundStream_del(sfCustomSoundStream *music) {
255+
sfCustomSoundStream_setEffectProcessor(music, nullptr, nullptr);
256+
delete music;
257+
}

CSFML/src/Audio/EffectProcessor.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
typedef void (*sfEffectProcessor)(const float *inputFrames,
4+
unsigned int *inputFrameCount,
5+
float *outputFrames,
6+
unsigned int *outputFrameCount,
7+
unsigned int frameChannelCount,
8+
void *user_data);

CSFML/src/Audio/Listener.cpp

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
#include "System/Vector3.hpp"
22
#include <SFML/Audio/Listener.hpp>
33

4+
typedef struct
5+
{
6+
float innerAngle; //!< Inner angle, in degrees
7+
float outerAngle; //!< Outer angle, in degrees
8+
float outerGain; //!< Outer gain
9+
} sfListenerCone;
10+
11+
////////////////////////////////////////////////////////////
12+
// Convert sf::Listener::Cone to sfListenerCone
13+
////////////////////////////////////////////////////////////
14+
[[nodiscard]] inline sfListenerCone convertCone(const sf::Listener::Cone cone) {
15+
return {cone.innerAngle.asDegrees(), cone.outerAngle.asDegrees(), cone.outerGain};
16+
}
17+
18+
////////////////////////////////////////////////////////////
19+
// Convert sfVector3f to sf::Vector3f
20+
////////////////////////////////////////////////////////////
21+
[[nodiscard]] inline sf::Listener::Cone convertCone(const sfListenerCone cone) {
22+
return {sf::degrees(cone.innerAngle), sf::degrees(cone.outerAngle), cone.outerGain};
23+
}
24+
425
extern "C" void sfListener_setGlobalVolume(float volume) {
526
sf::Listener::setGlobalVolume(volume);
627
}
@@ -10,7 +31,7 @@ extern "C" float sfListener_getGlobalVolume(void) {
1031
}
1132

1233
extern "C" void sfListener_setPosition(sfVector3f position) {
13-
sf::Listener::setPosition(position.x, position.y, position.z);
34+
sf::Listener::setPosition(convertVector3(position));
1435
}
1536

1637
extern "C" sfVector3f sfListener_getPosition() {
@@ -19,19 +40,33 @@ extern "C" sfVector3f sfListener_getPosition() {
1940
}
2041

2142
extern "C" void sfListener_setDirection(sfVector3f direction) {
22-
sf::Listener::setDirection(direction.x, direction.y, direction.z);
43+
sf::Listener::setDirection(convertVector3(direction));
2344
}
2445

2546
extern "C" sfVector3f sfListener_getDirection() {
26-
sf::Vector3f dir = sf::Listener::getDirection();
27-
return {dir.x, dir.y, dir.z};
47+
return convertVector3(sf::Listener::getDirection());
2848
}
2949

3050
extern "C" void sfListener_setUpVector(sfVector3f upVector) {
31-
sf::Listener::setUpVector(upVector.x, upVector.y, upVector.z);
51+
sf::Listener::setUpVector(convertVector3(upVector));
3252
}
3353

3454
extern "C" sfVector3f sfListener_getUpVector() {
35-
sf::Vector3f vec = sf::Listener::getUpVector();
36-
return {vec.x, vec.y, vec.z};
55+
return convertVector3(sf::Listener::getUpVector());
56+
}
57+
58+
extern "C" void sfListener_setVelocity(sfVector3f velocity) {
59+
sf::Listener::setVelocity(convertVector3(velocity));
60+
}
61+
62+
extern "C" sfVector3f sfListener_getVelocity() {
63+
return convertVector3(sf::Listener::getVelocity());
64+
}
65+
66+
extern "C" void sfListener_setCone(sfListenerCone cone) {
67+
sf::Listener::setCone(convertCone(cone));
68+
}
69+
70+
extern "C" sfListenerCone sfListener_getCone() {
71+
return convertCone(sf::Listener::getCone());
3772
}

0 commit comments

Comments
 (0)