Skip to content

Commit 0a0a33d

Browse files
committed
SFMLv3 Migration.
1 parent 5fbaa25 commit 0a0a33d

Some content is hidden

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

104 files changed

+2046
-1103
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/BlendMode.hpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
////////////////////////////////////////////////////////////
3+
/// \brief Enumeration of the blending factors
4+
///
5+
////////////////////////////////////////////////////////////
6+
typedef enum {
7+
sfBlendFactorZero, ///< (0, 0, 0, 0)
8+
sfBlendFactorOne, ///< (1, 1, 1, 1)
9+
sfBlendFactorSrcColor, ///< (src.r, src.g, src.b, src.a)
10+
sfBlendFactorOneMinusSrcColor, ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
11+
sfBlendFactorDstColor, ///< (dst.r, dst.g, dst.b, dst.a)
12+
sfBlendFactorOneMinusDstColor, ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
13+
sfBlendFactorSrcAlpha, ///< (src.a, src.a, src.a, src.a)
14+
sfBlendFactorOneMinusSrcAlpha, ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
15+
sfBlendFactorDstAlpha, ///< (dst.a, dst.a, dst.a, dst.a)
16+
sfBlendFactorOneMinusDstAlpha ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
17+
} sfBlendFactor;
18+
19+
////////////////////////////////////////////////////////////
20+
/// \brief Enumeration of the blending equations
21+
///
22+
////////////////////////////////////////////////////////////
23+
typedef enum {
24+
sfBlendEquationAdd, ///< Pixel = Src * SrcFactor + Dst * DstFactor
25+
sfBlendEquationSubtract, ///< Pixel = Src * SrcFactor - Dst * DstFactor
26+
sfBlendEquationReverseSubtract, ///< Pixel = Dst * DstFactor - Src * SrcFactor
27+
sfBlendEquationMin, ///< Pixel = min(Dst, Src)
28+
sfBlendEquationMax ///< Pixel = max(Dst, Src)
29+
} sfBlendEquation;
30+
31+
////////////////////////////////////////////////////////////
32+
/// \brief Blending mode for drawing
33+
///
34+
////////////////////////////////////////////////////////////
35+
typedef struct
36+
{
37+
sfBlendFactor colorSrcFactor; ///< Source blending factor for the color channels
38+
sfBlendFactor colorDstFactor; ///< Destination blending factor for the color channels
39+
sfBlendEquation colorEquation; ///< Blending equation for the color channels
40+
sfBlendFactor alphaSrcFactor; ///< Source blending factor for the alpha channel
41+
sfBlendFactor alphaDstFactor; ///< Destination blending factor for the alpha channel
42+
sfBlendEquation alphaEquation; ///< Blending equation for the alpha channel
43+
} sfBlendMode;

0 commit comments

Comments
 (0)