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 1 commit 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
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- name: Install deps
run: |
sudo apt-get update
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
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
- name: Build
run: |
git submodule update --init
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ on:
workflow_dispatch:

env:
CXXFLAGS: "/std:c++17 /EHsc"
CARGO_TERM_COLOR: always

jobs:
Expand All @@ -36,8 +37,7 @@ jobs:
- uses: actions/checkout@v4
- name: Build
run: |
git submodule update --init
cp .\SFML\extlibs\bin\x64\openal32.dll .
git submodule update --init --recursive
cargo build --verbose
- name: Run tests
run: |
Expand Down
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
151 changes: 133 additions & 18 deletions CSFML/src/Audio/CustomSoundStream.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "Audio/EffectProcessor.hpp"
#include "Audio/SoundSourceCone.hpp"
#include "Audio/SoundStatus.hpp"
#include "SFML/Audio/SoundChannel.hpp"
#include "System/Vector3.hpp"
#include <SFML/Audio/SoundStream.hpp>
#include <cstdint>
#include <map>
#include <mutex>

typedef bool (*sfCustomSoundStreamGetDataCb)(sf::SoundStream::Chunk *, void *);
typedef void (*sfCustomSoundStreamSeekCb)(int64_t, void *);
Expand All @@ -11,10 +16,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,12 +41,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);
}

extern "C" void sfCustomSoundStream_del(sfCustomSoundStream *soundStream) {
delete soundStream;
return new sfCustomSoundStream(onGetData, onSeek, channelCount, sampleRate, channel, userData);
}

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

extern "C" sf::SoundStream::Status sfCustomSoundStream_getStatus(const sfCustomSoundStream *soundStream) {

return soundStream->getStatus();
extern "C" sfSoundStatus sfCustomSoundStream_getStatus(const sfCustomSoundStream *soundStream) {
return static_cast<sfSoundStatus>(soundStream->getStatus());
}

extern "C" unsigned int sfCustomSoundStream_getChannelCount(const sfCustomSoundStream *soundStream) {
Expand All @@ -68,16 +70,48 @@ 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);
}

extern "C" void sfCustomSoundStream_setPan(sfCustomSoundStream *soundStream, float pan) {
soundStream->setPan(pan);
}

extern "C" void sfCustomSoundStream_setVolume(sfCustomSoundStream *soundStream, float volume) {
soundStream->setVolume(volume);
}

extern "C" void sfCustomSoundStream_setPosition(sfCustomSoundStream *soundStream, sfVector3f position) {
soundStream->setPosition(position.x, position.y, position.z);
extern "C" void sfCustomSoundStream_setSpatializationEnabled(sfCustomSoundStream *soundStream, bool enabled) {
soundStream->setSpatializationEnabled(enabled);
}

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

extern "C" void sfCustomSoundStream_setDirection(sfCustomSoundStream *soundStream, sfVector3f position) {
soundStream->setDirection(convertVector3(position));
}

extern "C" void sfCustomSoundStream_setCone(sfCustomSoundStream *soundStream, sfSoundSourceCone cone) {
soundStream->setCone(convertCone(cone));
}

extern "C" void sfCustomSoundStream_setVelocity(sfCustomSoundStream *soundStream, sfVector3f velocity) {
soundStream->setVelocity(convertVector3(velocity));
}

extern "C" void sfCustomSoundStream_setDopplerFactor(sfCustomSoundStream *soundStream, float factor) {
soundStream->setDopplerFactor(factor);
}

extern "C" void sfCustomSoundStream_setDirectionalAttenuationFactor(sfCustomSoundStream *soundStream, float factor) {
soundStream->setDirectionalAttenuationFactor(factor);
}

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

extern "C" void sfCustomSoundStream_setMaxDistance(sfCustomSoundStream *soundStream, float distance) {
soundStream->setMaxDistance(distance);
}

extern "C" void sfCustomSoundStream_setMinGain(sfCustomSoundStream *soundStream, float gain) {
soundStream->setMinGain(gain);
}

extern "C" void sfCustomSoundStream_setMaxGain(sfCustomSoundStream *soundStream, float gain) {
soundStream->setMaxGain(gain);
}

extern "C" void sfCustomSoundStream_setAttenuation(sfCustomSoundStream *soundStream, float attenuation) {
soundStream->setAttenuation(attenuation);
}
Expand All @@ -96,21 +142,48 @@ 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) {
return soundStream->getPitch();
}

extern "C" float sfCustomSoundStream_getPan(const sfCustomSoundStream *soundStream) {
return soundStream->getPan();
}

extern "C" float sfCustomSoundStream_getVolume(const sfCustomSoundStream *soundStream) {
return soundStream->getVolume();
}

extern "C" bool sfCustomSoundStream_isSpatializationEnabled(const sfCustomSoundStream *soundStream) {
return soundStream->isSpatializationEnabled();
}

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

extern "C" sfVector3f sfCustomSoundStream_getDirection(const sfCustomSoundStream *soundStream) {
return convertVector3(soundStream->getDirection());
}

extern "C" sfSoundSourceCone sfCustomSoundStream_getCone(const sfCustomSoundStream *soundStream) {
return convertCone(soundStream->getCone());
}

extern "C" sfVector3f sfCustomSoundStream_getVelocity(const sfCustomSoundStream *soundStream) {
return convertVector3(soundStream->getVelocity());
}

extern "C" float sfCustomSoundStream_getDopplerFactor(const sfCustomSoundStream *soundStream) {
return soundStream->getDopplerFactor();
}

extern "C" float sfCustomSoundStream_getDirectionalAttenuationFactor(const sfCustomSoundStream *soundStream) {
return soundStream->getDirectionalAttenuationFactor();
}

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

extern "C" float sfCustomSoundStream_getMaxDistance(const sfCustomSoundStream *soundStream) {
return soundStream->getMaxDistance();
}

extern "C" float sfCustomSoundStream_getMinGain(const sfCustomSoundStream *soundStream) {
return soundStream->getMinGain();
}

extern "C" float sfCustomSoundStream_getMaxGain(const sfCustomSoundStream *soundStream) {
return soundStream->getMaxGain();
}

extern "C" float sfCustomSoundStream_getAttenuation(const sfCustomSoundStream *soundStream) {
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) {
return soundStream->getPlayingOffset().asMicroseconds();
}

static std::map<sfCustomSoundStream *, std::pair<sfEffectProcessor, void *>> processors;
static std::mutex processorMutex;

extern "C" void sfCustomSoundStream_setEffectProcessor(sfCustomSoundStream *soundStream, sfEffectProcessor effectProcessor, void *userData) {
std::unique_lock<std::mutex> lock(processorMutex);
if (!effectProcessor) {
processors.erase(soundStream);
soundStream->setEffectProcessor(nullptr);
} else {
processors[soundStream] = {effectProcessor, userData};
soundStream->setEffectProcessor(
[soundStream](const float *inputFrames,
unsigned int &inputFrameCount,
float *outputFrames,
unsigned int &outputFrameCount,
unsigned int frameChannelCount) {
std::unique_lock<std::mutex> lock(processorMutex);
auto it = processors.find(soundStream);
if (it != processors.end()) {
it->second.first(inputFrames, &inputFrameCount, outputFrames, &outputFrameCount, frameChannelCount, it->second.second);
}
});
}
}

extern "C" void sfCustomSoundStream_del(sfCustomSoundStream *music) {
sfCustomSoundStream_setEffectProcessor(music, nullptr, nullptr);
delete music;
}
8 changes: 8 additions & 0 deletions CSFML/src/Audio/EffectProcessor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

typedef void (*sfEffectProcessor)(const float *inputFrames,
unsigned int *inputFrameCount,
float *outputFrames,
unsigned int *outputFrameCount,
unsigned int frameChannelCount,
void *user_data);
49 changes: 42 additions & 7 deletions CSFML/src/Audio/Listener.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
#include "System/Vector3.hpp"
#include <SFML/Audio/Listener.hpp>

typedef struct
{
float innerAngle; //!< Inner angle, in degrees
float outerAngle; //!< Outer angle, in degrees
float outerGain; //!< Outer gain
} sfListenerCone;

////////////////////////////////////////////////////////////
// Convert sf::Listener::Cone to sfListenerCone
////////////////////////////////////////////////////////////
[[nodiscard]] inline sfListenerCone convertCone(const sf::Listener::Cone cone) {
return {cone.innerAngle.asDegrees(), cone.outerAngle.asDegrees(), cone.outerGain};
}

////////////////////////////////////////////////////////////
// Convert sfVector3f to sf::Vector3f
////////////////////////////////////////////////////////////
[[nodiscard]] inline sf::Listener::Cone convertCone(const sfListenerCone cone) {
return {sf::degrees(cone.innerAngle), sf::degrees(cone.outerAngle), cone.outerGain};
}

extern "C" void sfListener_setGlobalVolume(float volume) {
sf::Listener::setGlobalVolume(volume);
}
Expand All @@ -10,7 +31,7 @@ extern "C" float sfListener_getGlobalVolume(void) {
}

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

extern "C" sfVector3f sfListener_getPosition() {
Expand All @@ -19,19 +40,33 @@ extern "C" sfVector3f sfListener_getPosition() {
}

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

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

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

extern "C" sfVector3f sfListener_getUpVector() {
sf::Vector3f vec = sf::Listener::getUpVector();
return {vec.x, vec.y, vec.z};
return convertVector3(sf::Listener::getUpVector());
}

extern "C" void sfListener_setVelocity(sfVector3f velocity) {
sf::Listener::setVelocity(convertVector3(velocity));
}

extern "C" sfVector3f sfListener_getVelocity() {
return convertVector3(sf::Listener::getVelocity());
}

extern "C" void sfListener_setCone(sfListenerCone cone) {
sf::Listener::setCone(convertCone(cone));
}

extern "C" sfListenerCone sfListener_getCone() {
return convertCone(sf::Listener::getCone());
}
Loading
Loading