Skip to content

Commit 078a20c

Browse files
committed
SFMLv3 Migration.
1 parent 5fbaa25 commit 078a20c

File tree

130 files changed

+2933
-1270
lines changed

Some content is hidden

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

130 files changed

+2933
-1270
lines changed

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: 16 additions & 10 deletions
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) {
@@ -109,8 +116,7 @@ extern "C" float sfCustomSoundStream_getVolume(const sfCustomSoundStream *soundS
109116
}
110117

111118
extern "C" sfVector3f sfCustomSoundStream_getPosition(const sfCustomSoundStream *soundStream) {
112-
sf::Vector3f pos = soundStream->getPosition();
113-
return {pos.x, pos.y, pos.z};
119+
return convertVector3(soundStream->getPosition());
114120
}
115121

116122
extern "C" bool sfCustomSoundStream_isRelativeToListener(const sfCustomSoundStream *soundStream) {
@@ -125,8 +131,8 @@ extern "C" float sfCustomSoundStream_getAttenuation(const sfCustomSoundStream *s
125131
return soundStream->getAttenuation();
126132
}
127133

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

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

CSFML/src/Audio/EffectProcessor.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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);

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
}

CSFML/src/Audio/Music.cpp

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#include "Audio/EffectProcessor.hpp"
2+
#include "Audio/SoundSourceCone.hpp"
3+
#include "SFML/Audio/SoundChannel.hpp"
14
#include "System/InputStreamHelper.hpp"
25
#include "System/Vector3.hpp"
36
#include <SFML/Audio/Music.hpp>
@@ -17,7 +20,7 @@ extern "C" void sfMusic_del(sf::Music *music) {
1720
}
1821

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

2326
extern "C" bool sfMusic_openFromMemory(sf::Music *music, const uint8_t *data, size_t sizeInBytes) {
@@ -28,12 +31,25 @@ extern "C" bool sfMusic_openFromStream(sf::Music *music, sfInputStreamHelper *st
2831
return music->openFromStream(*stream);
2932
}
3033

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

35-
extern "C" bool sfMusic_getLoop(const sf::Music *music) {
36-
return music->getLoop();
38+
extern "C" bool sfMusic_isLooping(const sf::Music *music) {
39+
return music->isLooping();
40+
}
41+
42+
extern "C" void sfMusic_setEffectProcessor(sf::Music *music, sfEffectProcessor effectProcessor) {
43+
if (!effectProcessor) {
44+
music->setEffectProcessor(nullptr);
45+
} else {
46+
music->setEffectProcessor(
47+
[effectProcessor](const float *inputFrames,
48+
unsigned int &inputFrameCount,
49+
float *outputFrames,
50+
unsigned int &outputFrameCount,
51+
unsigned int frameChannelCount) { effectProcessor(inputFrames, &inputFrameCount, outputFrames, &outputFrameCount, frameChannelCount); });
52+
}
3753
}
3854

3955
extern "C" int64_t sfMusic_getDuration(const sf::Music *music) {
@@ -46,8 +62,8 @@ extern "C" sfTimeSpan sfMusic_getLoopPoints(const sf::Music *music) {
4662
}
4763

4864
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)));
65+
music->setLoopPoints({sf::microseconds(timePoints.offset),
66+
sf::microseconds(timePoints.length)});
5167
}
5268

5369
extern "C" void sfMusic_play(sf::Music *music) {
@@ -70,8 +86,11 @@ extern "C" unsigned int sfMusic_getSampleRate(const sf::Music *music) {
7086
return music->getSampleRate();
7187
}
7288

73-
extern "C" sf::Music::Status sfMusic_getStatus(const sf::Music *music) {
89+
extern "C" const std::vector<sf::SoundChannel> *sfMusic_getChannelMap(const sf::Music *music) {
90+
return new std::vector(music->getChannelMap());
91+
}
7492

93+
extern "C" sf::Music::Status sfMusic_getStatus(const sf::Music *music) {
7594
return music->getStatus();
7695
}
7796

@@ -83,12 +102,32 @@ extern "C" void sfMusic_setPitch(sf::Music *music, float pitch) {
83102
music->setPitch(pitch);
84103
}
85104

105+
extern "C" void sfMusic_setPan(sf::Music *music, float pan) {
106+
music->setPan(pan);
107+
}
108+
86109
extern "C" void sfMusic_setVolume(sf::Music *music, float volume) {
87110
music->setVolume(volume);
88111
}
89112

90-
extern "C" void sfMusic_setPosition(sf::Music *music, sfVector3f position) {
91-
music->setPosition(sf::Vector3f(position.x, position.y, position.z));
113+
extern "C" void sfMusic_setSpatializationEnabled(sf::Music *music, bool enabled) {
114+
music->setSpatializationEnabled(enabled);
115+
}
116+
117+
extern "C" void sfMusic_setDirection(sf::Music *music, sfVector3f direction) {
118+
music->setDirection({direction.x, direction.y, direction.z});
119+
}
120+
121+
extern "C" void sfMusic_setCone(sf::Music *music, sfSoundSourceCone cone) {
122+
music->setCone(convertCone(cone));
123+
}
124+
125+
extern "C" void sfMusic_setVelocity(sf::Music *music, sfVector3f velocity) {
126+
music->setVelocity(convertVector3(velocity));
127+
}
128+
129+
extern "C" void sfMusic_setPosition(sf::Music *music, sf::Vector3f position) {
130+
music->setPosition(position);
92131
}
93132

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

CSFML/src/Audio/Sound.cpp

Lines changed: 11 additions & 10 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 24 additions & 0 deletions
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+
};

0 commit comments

Comments
 (0)