Skip to content

Commit ee3f68d

Browse files
committed
Update SFML to v3
1 parent 6d458da commit ee3f68d

File tree

143 files changed

+4158
-1417
lines changed

Some content is hidden

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

143 files changed

+4158
-1417
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ on:
2222
workflow_dispatch:
2323

2424
env:
25+
CXXFLAGS: "/std:c++17 /EHsc"
2526
CARGO_TERM_COLOR: always
2627

2728
jobs:
@@ -36,8 +37,7 @@ jobs:
3637
- uses: actions/checkout@v4
3738
- name: Build
3839
run: |
39-
git submodule update --init
40-
cp .\SFML\extlibs\bin\x64\openal32.dll .
40+
git submodule update --init --recursive
4141
cargo build --verbose
4242
- name: Run tests
4343
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: 133 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
#include "Audio/EffectProcessor.hpp"
2+
#include "Audio/SoundSourceCone.hpp"
3+
#include "Audio/SoundStatus.hpp"
4+
#include "SFML/Audio/SoundChannel.hpp"
15
#include "System/Vector3.hpp"
26
#include <SFML/Audio/SoundStream.hpp>
3-
#include <cstdint>
7+
#include <map>
8+
#include <mutex>
49

510
typedef bool (*sfCustomSoundStreamGetDataCb)(sf::SoundStream::Chunk *, void *);
611
typedef void (*sfCustomSoundStreamSeekCb)(int64_t, void *);
@@ -11,10 +16,11 @@ class sfCustomSoundStream final : public sf::SoundStream {
1116
sfCustomSoundStreamSeekCb onSeek,
1217
unsigned int channelCount,
1318
unsigned int sampleRate,
19+
const std::vector<sf::SoundChannel> *channel,
1420
void *userData) : myGetDataCb(onGetData),
1521
mySeekCallCb(onSeek),
1622
myUserData(userData) {
17-
initialize(channelCount, sampleRate);
23+
initialize(channelCount, sampleRate, *channel);
1824
}
1925

2026
private:
@@ -35,12 +41,9 @@ extern "C" sfCustomSoundStream *sfCustomSoundStream_new(sfCustomSoundStreamGetDa
3541
sfCustomSoundStreamSeekCb onSeek,
3642
unsigned int channelCount,
3743
unsigned int sampleRate,
44+
const std::vector<sf::SoundChannel> *channel,
3845
void *userData) {
39-
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, userData);
40-
}
41-
42-
extern "C" void sfCustomSoundStream_del(sfCustomSoundStream *soundStream) {
43-
delete soundStream;
46+
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, channel, userData);
4447
}
4548

4649
extern "C" void sfCustomSoundStream_play(sfCustomSoundStream *soundStream) {
@@ -55,9 +58,8 @@ extern "C" void sfCustomSoundStream_stop(sfCustomSoundStream *soundStream) {
5558
soundStream->stop();
5659
}
5760

58-
extern "C" sf::SoundStream::Status sfCustomSoundStream_getStatus(const sfCustomSoundStream *soundStream) {
59-
60-
return soundStream->getStatus();
61+
extern "C" sfSoundStatus sfCustomSoundStream_getStatus(const sfCustomSoundStream *soundStream) {
62+
return static_cast<sfSoundStatus>(soundStream->getStatus());
6163
}
6264

6365
extern "C" unsigned int sfCustomSoundStream_getChannelCount(const sfCustomSoundStream *soundStream) {
@@ -68,16 +70,48 @@ extern "C" unsigned int sfCustomSoundStream_getSampleRate(const sfCustomSoundStr
6870
return soundStream->getSampleRate();
6971
}
7072

73+
extern "C" const std::vector<sf::SoundChannel> *sfCustomSoundStream_getChannelMap(const sfCustomSoundStream *soundStream) {
74+
return new std::vector(soundStream->getChannelMap());
75+
}
76+
7177
extern "C" void sfCustomSoundStream_setPitch(sfCustomSoundStream *soundStream, float pitch) {
7278
soundStream->setPitch(pitch);
7379
}
7480

81+
extern "C" void sfCustomSoundStream_setPan(sfCustomSoundStream *soundStream, float pan) {
82+
soundStream->setPan(pan);
83+
}
84+
7585
extern "C" void sfCustomSoundStream_setVolume(sfCustomSoundStream *soundStream, float volume) {
7686
soundStream->setVolume(volume);
7787
}
7888

79-
extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sfVector3f position) {
80-
soundStream->setPosition(position.x, position.y, position.z);
89+
extern "C" void sfCustomSoundStream_setSpatializationEnabled(sfCustomSoundStream *soundStream, bool enabled) {
90+
soundStream->setSpatializationEnabled(enabled);
91+
}
92+
93+
extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sf::Vector3f position) {
94+
soundStream->setPosition(position);
95+
}
96+
97+
extern "C" void sfCustomSoundStream_setDirection(sfCustomSoundStream *soundStream, sfVector3f position) {
98+
soundStream->setDirection(convertVector3(position));
99+
}
100+
101+
extern "C" void sfCustomSoundStream_setCone(sfCustomSoundStream *soundStream, sfSoundSourceCone cone) {
102+
soundStream->setCone(convertCone(cone));
103+
}
104+
105+
extern "C" void sfCustomSoundStream_setVelocity(sfCustomSoundStream *soundStream, sfVector3f velocity) {
106+
soundStream->setVelocity(convertVector3(velocity));
107+
}
108+
109+
extern "C" void sfCustomSoundStream_setDopplerFactor(sfCustomSoundStream *soundStream, float factor) {
110+
soundStream->setDopplerFactor(factor);
111+
}
112+
113+
extern "C" void sfCustomSoundStream_setDirectionalAttenuationFactor(sfCustomSoundStream *soundStream, float factor) {
114+
soundStream->setDirectionalAttenuationFactor(factor);
81115
}
82116

83117
extern "C" void sfCustomSoundStream_setRelativeToListener(sfCustomSoundStream *soundStream, bool relative) {
@@ -88,6 +122,18 @@ extern "C" void sfCustomSoundStream_setMinDistance(sfCustomSoundStream *soundStr
88122
soundStream->setMinDistance(distance);
89123
}
90124

125+
extern "C" void sfCustomSoundStream_setMaxDistance(sfCustomSoundStream *soundStream, float distance) {
126+
soundStream->setMaxDistance(distance);
127+
}
128+
129+
extern "C" void sfCustomSoundStream_setMinGain(sfCustomSoundStream *soundStream, float gain) {
130+
soundStream->setMinGain(gain);
131+
}
132+
133+
extern "C" void sfCustomSoundStream_setMaxGain(sfCustomSoundStream *soundStream, float gain) {
134+
soundStream->setMaxGain(gain);
135+
}
136+
91137
extern "C" void sfCustomSoundStream_setAttenuation(sfCustomSoundStream *soundStream, float attenuation) {
92138
soundStream->setAttenuation(attenuation);
93139
}
@@ -96,21 +142,48 @@ extern "C" void sfCustomSoundStream_setPlayingOffset(sfCustomSoundStream *soundS
96142
soundStream->setPlayingOffset(sf::microseconds(timeOffset));
97143
}
98144

99-
extern "C" void sfCustomSoundStream_setLoop(sfCustomSoundStream *soundStream, bool loop) {
100-
soundStream->setLoop(loop);
145+
extern "C" void sfCustomSoundStream_setLooping(sfCustomSoundStream *soundStream, bool loop) {
146+
soundStream->setLooping(loop);
101147
}
102148

103149
extern "C" float sfCustomSoundStream_getPitch(const sfCustomSoundStream *soundStream) {
104150
return soundStream->getPitch();
105151
}
106152

153+
extern "C" float sfCustomSoundStream_getPan(const sfCustomSoundStream *soundStream) {
154+
return soundStream->getPan();
155+
}
156+
107157
extern "C" float sfCustomSoundStream_getVolume(const sfCustomSoundStream *soundStream) {
108158
return soundStream->getVolume();
109159
}
110160

161+
extern "C" bool sfCustomSoundStream_isSpatializationEnabled(const sfCustomSoundStream *soundStream) {
162+
return soundStream->isSpatializationEnabled();
163+
}
164+
111165
extern "C" sfVector3f sfCustomSoundStream_getPosition(const sfCustomSoundStream *soundStream) {
112-
sf::Vector3f pos = soundStream->getPosition();
113-
return {pos.x, pos.y, pos.z};
166+
return convertVector3(soundStream->getPosition());
167+
}
168+
169+
extern "C" sfVector3f sfCustomSoundStream_getDirection(const sfCustomSoundStream *soundStream) {
170+
return convertVector3(soundStream->getDirection());
171+
}
172+
173+
extern "C" sfSoundSourceCone sfCustomSoundStream_getCone(const sfCustomSoundStream *soundStream) {
174+
return convertCone(soundStream->getCone());
175+
}
176+
177+
extern "C" sfVector3f sfCustomSoundStream_getVelocity(const sfCustomSoundStream *soundStream) {
178+
return convertVector3(soundStream->getVelocity());
179+
}
180+
181+
extern "C" float sfCustomSoundStream_getDopplerFactor(const sfCustomSoundStream *soundStream) {
182+
return soundStream->getDopplerFactor();
183+
}
184+
185+
extern "C" float sfCustomSoundStream_getDirectionalAttenuationFactor(const sfCustomSoundStream *soundStream) {
186+
return soundStream->getDirectionalAttenuationFactor();
114187
}
115188

116189
extern "C" bool sfCustomSoundStream_isRelativeToListener(const sfCustomSoundStream *soundStream) {
@@ -121,14 +194,56 @@ extern "C" float sfCustomSoundStream_getMinDistance(const sfCustomSoundStream *s
121194
return soundStream->getMinDistance();
122195
}
123196

197+
extern "C" float sfCustomSoundStream_getMaxDistance(const sfCustomSoundStream *soundStream) {
198+
return soundStream->getMaxDistance();
199+
}
200+
201+
extern "C" float sfCustomSoundStream_getMinGain(const sfCustomSoundStream *soundStream) {
202+
return soundStream->getMinGain();
203+
}
204+
205+
extern "C" float sfCustomSoundStream_getMaxGain(const sfCustomSoundStream *soundStream) {
206+
return soundStream->getMaxGain();
207+
}
208+
124209
extern "C" float sfCustomSoundStream_getAttenuation(const sfCustomSoundStream *soundStream) {
125210
return soundStream->getAttenuation();
126211
}
127212

128-
extern "C" bool sfCustomSoundStream_getLoop(const sfCustomSoundStream *soundStream) {
129-
return soundStream->getLoop();
213+
extern "C" bool sfCustomSoundStream_isLooping(const sfCustomSoundStream *soundStream) {
214+
return soundStream->isLooping();
130215
}
131216

132217
extern "C" int64_t sfCustomSoundStream_getPlayingOffset(const sfCustomSoundStream *soundStream) {
133218
return soundStream->getPlayingOffset().asMicroseconds();
134219
}
220+
221+
static std::map<sfCustomSoundStream *, std::pair<sfEffectProcessor, void *>> processors;
222+
static std::mutex processorMutex;
223+
224+
extern "C" void sfCustomSoundStream_setEffectProcessor(sfCustomSoundStream *soundStream, sfEffectProcessor effectProcessor, void *userData) {
225+
std::unique_lock<std::mutex> lock(processorMutex);
226+
if (!effectProcessor) {
227+
processors.erase(soundStream);
228+
soundStream->setEffectProcessor(nullptr);
229+
} else {
230+
processors[soundStream] = {effectProcessor, userData};
231+
soundStream->setEffectProcessor(
232+
[soundStream](const float *inputFrames,
233+
unsigned int &inputFrameCount,
234+
float *outputFrames,
235+
unsigned int &outputFrameCount,
236+
unsigned int frameChannelCount) {
237+
std::unique_lock<std::mutex> lock(processorMutex);
238+
auto it = processors.find(soundStream);
239+
if (it != processors.end()) {
240+
it->second.first(inputFrames, &inputFrameCount, outputFrames, &outputFrameCount, frameChannelCount, it->second.second);
241+
}
242+
});
243+
}
244+
}
245+
246+
extern "C" void sfCustomSoundStream_del(sfCustomSoundStream *music) {
247+
sfCustomSoundStream_setEffectProcessor(music, nullptr, nullptr);
248+
delete music;
249+
}

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)