Skip to content

sfmlv3 migration PR #338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions CSFML/src/Audio/CustomSoundRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ class sfCustomSoundRecorder final : public sf::SoundRecorder {
myStopCb(onStop),
myUserData(userData) {
}
virtual void setProcessingInterval(int64_t interval) final {
sf::SoundRecorder::setProcessingInterval(sf::microseconds(interval));
}

private:
virtual bool onStart() final {
return myStartCb(myUserData);
}

virtual bool onProcessSamples(const sf::Int16 *samples, std::size_t sampleCount) final {
virtual bool onProcessSamples(const std::int16_t *samples, std::size_t sampleCount) final {
return myProcessCb(samples, sampleCount, myUserData);
}

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

extern "C" void sfCustomSoundRecorder_setProcessingInterval(sfCustomSoundRecorder *soundRecorder, int64_t interval) {
soundRecorder->setProcessingInterval(interval);
}

extern "C" bool sfCustomSoundRecorder_setDevice(sfCustomSoundRecorder *soundRecorder, const char *name) {
return soundRecorder->setDevice(name);
}
Expand Down
23 changes: 15 additions & 8 deletions CSFML/src/Audio/CustomSoundStream.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "SFML/Audio/SoundChannel.hpp"
#include "System/Vector3.hpp"
#include <SFML/Audio/SoundStream.hpp>
#include <cstdint>
Expand All @@ -11,10 +12,11 @@ class sfCustomSoundStream final : public sf::SoundStream {
sfCustomSoundStreamSeekCb onSeek,
unsigned int channelCount,
unsigned int sampleRate,
const std::vector<sf::SoundChannel> *channel,
void *userData) : myGetDataCb(onGetData),
mySeekCallCb(onSeek),
myUserData(userData) {
initialize(channelCount, sampleRate);
initialize(channelCount, sampleRate, *channel);
}

private:
Expand All @@ -35,8 +37,9 @@ extern "C" sfCustomSoundStream *sfCustomSoundStream_new(sfCustomSoundStreamGetDa
sfCustomSoundStreamSeekCb onSeek,
unsigned int channelCount,
unsigned int sampleRate,
const std::vector<sf::SoundChannel> *channel,
void *userData) {
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, userData);
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, channel, userData);
}

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

extern "C" const std::vector<sf::SoundChannel> *sfCustomSoundStream_getChannelMap(const sfCustomSoundStream *soundStream) {
return new std::vector(soundStream->getChannelMap());
}

extern "C" void sfCustomSoundStream_setPitch(sfCustomSoundStream *soundStream, float pitch) {
soundStream->setPitch(pitch);
}
Expand All @@ -76,8 +83,8 @@ extern "C" void sfCustomSoundStream_setVolume(sfCustomSoundStream *soundStream,
soundStream->setVolume(volume);
}

extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sfVector3f position) {
soundStream->setPosition(position.x, position.y, position.z);
extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sf::Vector3f position) {
soundStream->setPosition(position);
}

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

extern "C" void sfCustomSoundStream_setLoop(sfCustomSoundStream *soundStream, bool loop) {
soundStream->setLoop(loop);
extern "C" void sfCustomSoundStream_setLooping(sfCustomSoundStream *soundStream, bool loop) {
soundStream->setLooping(loop);
}

extern "C" float sfCustomSoundStream_getPitch(const sfCustomSoundStream *soundStream) {
Expand Down Expand Up @@ -125,8 +132,8 @@ extern "C" float sfCustomSoundStream_getAttenuation(const sfCustomSoundStream *s
return soundStream->getAttenuation();
}

extern "C" bool sfCustomSoundStream_getLoop(const sfCustomSoundStream *soundStream) {
return soundStream->getLoop();
extern "C" bool sfCustomSoundStream_isLooping(const sfCustomSoundStream *soundStream) {
return soundStream->isLooping();
}

extern "C" int64_t sfCustomSoundStream_getPlayingOffset(const sfCustomSoundStream *soundStream) {
Expand Down
18 changes: 9 additions & 9 deletions CSFML/src/Audio/Listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ extern "C" float sfListener_getGlobalVolume(void) {
return sf::Listener::getGlobalVolume();
}

extern "C" void sfListener_setPosition(sfVector3f position) {
sf::Listener::setPosition(position.x, position.y, position.z);
extern "C" void sfListener_setPosition(sf::Vector3f position) {
sf::Listener::setPosition(position);
}

extern "C" sfVector3f sfListener_getPosition() {
extern "C" sf::Vector3f sfListener_getPosition() {
sf::Vector3f pos = sf::Listener::getPosition();
return {pos.x, pos.y, pos.z};
}

extern "C" void sfListener_setDirection(sfVector3f direction) {
sf::Listener::setDirection(direction.x, direction.y, direction.z);
extern "C" void sfListener_setDirection(sf::Vector3f direction) {
sf::Listener::setDirection(direction);
}

extern "C" sfVector3f sfListener_getDirection() {
extern "C" sf::Vector3f sfListener_getDirection() {
sf::Vector3f dir = sf::Listener::getDirection();
return {dir.x, dir.y, dir.z};
}

extern "C" void sfListener_setUpVector(sfVector3f upVector) {
sf::Listener::setUpVector(upVector.x, upVector.y, upVector.z);
extern "C" void sfListener_setUpVector(sf::Vector3f upVector) {
sf::Listener::setUpVector(upVector);
}

extern "C" sfVector3f sfListener_getUpVector() {
extern "C" sf::Vector3f sfListener_getUpVector() {
sf::Vector3f vec = sf::Listener::getUpVector();
return {vec.x, vec.y, vec.z};
}
18 changes: 9 additions & 9 deletions CSFML/src/Audio/Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extern "C" void sfMusic_del(sf::Music *music) {
}

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

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

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

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

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

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

extern "C" void sfMusic_play(sf::Music *music) {
Expand Down Expand Up @@ -87,8 +87,8 @@ extern "C" void sfMusic_setVolume(sf::Music *music, float volume) {
music->setVolume(volume);
}

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

extern "C" void sfMusic_setRelativeToListener(sf::Music *music, bool relative) {
Expand Down
21 changes: 11 additions & 10 deletions CSFML/src/Audio/Sound.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "System/Vector3.hpp"
#include <SFML/Audio.hpp>
#include <SFML/Audio/Sound.hpp>
#include <SFML/System/Time.hpp>
#include <chrono>
#include <cstdint>

extern "C" sf::Sound *sfSound_new(void) {
return new sf::Sound;
extern "C" sf::Sound *sfSound_new(const sf::SoundBuffer *buffer) {
return new sf::Sound(*buffer);
}

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

extern "C" const sf::SoundBuffer *sfSound_getBuffer(const sf::Sound *sound) {
const sf::Sound *s = sound;
return s->getBuffer();
return &sound->getBuffer();
}

extern "C" void sfSound_setLoop(sf::Sound *sound, bool loop) {
sound->setLoop(loop);
extern "C" void sfSound_setLooping(sf::Sound *sound, bool loop) {
sound->setLooping(loop);
}

extern "C" bool sfSound_getLoop(const sf::Sound *sound) {
return sound->getLoop();
extern "C" bool sfSound_isLooping(const sf::Sound *sound) {
return sound->isLooping();
}

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

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

extern "C" float sfSound_getPitch(const sf::Sound *sound) {
Expand Down
4 changes: 2 additions & 2 deletions CSFML/src/Audio/SoundBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extern "C" bool sfSoundBuffer_loadFromStream(sf::SoundBuffer *buffer, sfInputStr
return buffer->loadFromStream(*stream);
}

extern "C" bool sfSoundBuffer_loadFromSamples(sf::SoundBuffer *buffer, const int16_t *samples, uint64_t sampleCount, unsigned int channelCount, unsigned int sampleRate) {
return buffer->loadFromSamples(samples, sampleCount, channelCount, sampleRate);
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) {
return buffer->loadFromSamples(samples, sampleCount, channelCount, sampleRate, *channelMap);
}

extern "C" bool sfSoundBuffer_saveToFile(const sf::SoundBuffer *soundBuffer, const char *filename) {
Expand Down
15 changes: 15 additions & 0 deletions CSFML/src/Audio/SoundChannel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "Audio/SoundChannel.hpp"
#include <SFML/Audio/SoundChannel.hpp>
#include <vector>

extern "C" std::size_t sfSoundChannelVector_getLength(const std::vector<sf::SoundChannel> *vec) {
return vec->size();
}

extern "C" const sf::SoundChannel *sfSoundChannelVector_getData(const std::vector<sf::SoundChannel> *vec) {
return vec->data();
}

extern "C" void sfSoundChannelVector_del(const std::vector<sf::SoundChannel> *vec) {
delete vec;
}
24 changes: 24 additions & 0 deletions CSFML/src/Audio/SoundChannel.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

enum sfSoundChannel {
Unspecified,
Mono,
FrontLeft,
FrontRight,
FrontCenter,
FrontLeftOfCenter,
FrontRightOfCenter,
LowFrequencyEffects,
BackLeft,
BackRight,
BackCenter,
SideLeft,
SideRight,
TopCenter,
TopFrontLeft,
TopFrontRight,
TopFrontCenter,
TopBackLeft,
TopBackRight,
TopBackCenter
};
43 changes: 43 additions & 0 deletions CSFML/src/Graphics/BlendMode.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once
////////////////////////////////////////////////////////////
/// \brief Enumeration of the blending factors
///
////////////////////////////////////////////////////////////
typedef enum {
sfBlendFactorZero, ///< (0, 0, 0, 0)
sfBlendFactorOne, ///< (1, 1, 1, 1)
sfBlendFactorSrcColor, ///< (src.r, src.g, src.b, src.a)
sfBlendFactorOneMinusSrcColor, ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
sfBlendFactorDstColor, ///< (dst.r, dst.g, dst.b, dst.a)
sfBlendFactorOneMinusDstColor, ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
sfBlendFactorSrcAlpha, ///< (src.a, src.a, src.a, src.a)
sfBlendFactorOneMinusSrcAlpha, ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
sfBlendFactorDstAlpha, ///< (dst.a, dst.a, dst.a, dst.a)
sfBlendFactorOneMinusDstAlpha ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
} sfBlendFactor;

////////////////////////////////////////////////////////////
/// \brief Enumeration of the blending equations
///
////////////////////////////////////////////////////////////
typedef enum {
sfBlendEquationAdd, ///< Pixel = Src * SrcFactor + Dst * DstFactor
sfBlendEquationSubtract, ///< Pixel = Src * SrcFactor - Dst * DstFactor
sfBlendEquationReverseSubtract, ///< Pixel = Dst * DstFactor - Src * SrcFactor
sfBlendEquationMin, ///< Pixel = min(Dst, Src)
sfBlendEquationMax ///< Pixel = max(Dst, Src)
} sfBlendEquation;

////////////////////////////////////////////////////////////
/// \brief Blending mode for drawing
///
////////////////////////////////////////////////////////////
typedef struct
{
sfBlendFactor colorSrcFactor; ///< Source blending factor for the color channels
sfBlendFactor colorDstFactor; ///< Destination blending factor for the color channels
sfBlendEquation colorEquation; ///< Blending equation for the color channels
sfBlendFactor alphaSrcFactor; ///< Source blending factor for the alpha channel
sfBlendFactor alphaDstFactor; ///< Destination blending factor for the alpha channel
sfBlendEquation alphaEquation; ///< Blending equation for the alpha channel
} sfBlendMode;
Loading
Loading