Catch up with SFML 3 API changes

This commit is contained in:
Chris Thrasher authored and Lukas Dürrenberger committed 2024-05-18 23:35:57 +02:00
1 parent 330b423ee9
commit 5fb7d4a0a1
14 files changed
+265 -147

No files matched your search

+13 -5
View File
@@ -30,6 +30,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Audio/Export.h>
#include <SFML/Audio/Types.h>
#include <SFML/Audio/SoundChannel.h>
#include <SFML/System/InputStream.h>
#include <SFML/System/Time.h>
#include <stddef.h>
@@ -84,15 +85,22 @@ CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromStream(sfInputStream* str
/// The assumed format of the audio samples is 16 bits signed integer
/// (int16_t).
///
/// \param samples Pointer to the array of samples in memory
/// \param sampleCount Number of samples in the array
/// \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
/// \param sampleRate Sample rate (number of samples to play per second)
/// \param samples Pointer to the array of samples in memory
/// \param sampleCount Number of samples in the array
/// \param channelCount Number of channels (1 = mono, 2 = stereo, ...)
/// \param sampleRate Sample rate (number of samples to play per second)
/// \param channelMapData Pointer to the array of channel map data
/// \param channelMapSize Size of channel map data array
///
/// \return A new sfSoundBuffer object (NULL if failed)
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples, uint64_t sampleCount, unsigned int channelCount, unsigned int sampleRate);
CSFML_AUDIO_API sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples,
uint64_t sampleCount,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize);
////////////////////////////////////////////////////////////
/// \brief Create a new sound buffer by copying an existing one
+65
View File
@@ -0,0 +1,65 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDCHANNEL_H
#define SFML_SOUNDCHANNEL_H
////////////////////////////////////////////////////////////
/// \brief Types of sound channels that can be read/written from sound buffers/files
///
/// In multi-channel audio, each sound channel can be
/// assigned a position. The position of the channel is
/// used to determine where to place a sound when it
/// is spatialised. Assigning an incorrect sound channel
/// will result in multi-channel audio being positioned
/// incorrectly when using spatialisation.
///
////////////////////////////////////////////////////////////
typedef enum
{
sfSoundChannelUnspecified,
sfSoundChannelMono,
sfSoundChannelFrontLeft,
sfSoundChannelFrontRight,
sfSoundChannelFrontCenter,
sfSoundChannelFrontLeftOfCenter,
sfSoundChannelFrontRightOfCenter,
sfSoundChannelLowFrequencyEffects,
sfSoundChannelBackLeft,
sfSoundChannelBackRight,
sfSoundChannelBackCenter,
sfSoundChannelSideLeft,
sfSoundChannelSideRight,
sfSoundChannelTopCenter,
sfSoundChannelTopFrontLeft,
sfSoundChannelTopFrontRight,
sfSoundChannelTopFrontCenter,
sfSoundChannelTopBackLeft,
sfSoundChannelTopBackRight,
sfSoundChannelTopBackCenter
} sfSoundChannel;
#endif // SFML_SOUNDCHANNEL_H
-19
View File
@@ -115,25 +115,6 @@ CSFML_AUDIO_API unsigned int sfSoundRecorder_getSampleRate(const sfSoundRecorder
////////////////////////////////////////////////////////////
CSFML_AUDIO_API bool sfSoundRecorder_isAvailable(void);
////////////////////////////////////////////////////////////
/// \brief Set the processing interval
///
/// The processing interval controls the period
/// between calls to the onProcessSamples function. You may
/// want to use a small interval if you want to process the
/// recorded data in real time, for example.
///
/// Note: this is only a hint, the actual period may vary.
/// So don't rely on this parameter to implement precise timing.
///
/// The default processing interval is 100 ms.
///
/// \param soundRecorder Sound recorder object
/// \param interval Processing interval
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API void sfSoundRecorder_setProcessingInterval(sfSoundRecorder* soundRecorder, sfTime interval);
////////////////////////////////////////////////////////////
/// \brief Get a list of the names of all available audio capture devices
///
+15 -9
View File
@@ -31,8 +31,10 @@
#include <SFML/Audio/Export.h>
#include <SFML/Audio/SoundStatus.h>
#include <SFML/Audio/Types.h>
#include <SFML/Audio/SoundChannel.h>
#include <SFML/System/Time.h>
#include <SFML/System/Vector3.h>
#include <stddef.h>
////////////////////////////////////////////////////////////
@@ -52,20 +54,24 @@ typedef void (*sfSoundStreamSeekCallback)(sfTime, void*); ///< T
////////////////////////////////////////////////////////////
/// \brief Create a new sound stream
///
/// \param onGetData Function called when the stream needs more data (can't be NULL)
/// \param onSeek Function called when the stream seeks (can't be NULL)
/// \param channelCount Number of channels to use (1 = mono, 2 = stereo)
/// \param sampleRate Sample rate of the sound (44100 = CD quality)
/// \param userData Data to pass to the callback functions
/// \param onGetData Function called when the stream needs more data (can't be NULL)
/// \param onSeek Function called when the stream seeks (can't be NULL)
/// \param channelCount Number of channels to use (1 = mono, 2 = stereo)
/// \param sampleRate Sample rate of the sound (44100 = CD quality)
/// \param channelMapData Pointer to the array of channel map data
/// \param channelMapSize Size of channel map data array
/// \param userData Data to pass to the callback functions
///
/// \return A new sfSoundStream object
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API sfSoundStream* sfSoundStream_create(sfSoundStreamGetDataCallback onGetData,
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
void* userData);
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize,
void* userData);
////////////////////////////////////////////////////////////
/// \brief Destroy a sound stream
+2 -2
View File
@@ -43,8 +43,8 @@ typedef enum
{
sfEvtClosed, ///< The window requested to be closed (no data)
sfEvtResized, ///< The window was resized (data in event.size)
sfEvtLostFocus, ///< The window lost the focus (no data)
sfEvtGainedFocus, ///< The window gained the focus (no data)
sfEvtFocusLost, ///< The window lost the focus (no data)
sfEvtFocusGained, ///< The window gained the focus (no data)
sfEvtTextEntered, ///< A character was entered (data in event.text)
sfEvtKeyPressed, ///< A key was pressed (data in event.key)
sfEvtKeyReleased, ///< A key was released (data in event.key)
+10 -2
View File
@@ -80,11 +80,19 @@ sfSoundBuffer* sfSoundBuffer_createFromStream(sfInputStream* stream)
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples, uint64_t sampleCount, unsigned int channelCount, unsigned int sampleRate)
sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples,
uint64_t sampleCount,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize)
{
sfSoundBuffer* buffer = new sfSoundBuffer;
if (!buffer->This.loadFromSamples(samples, sampleCount, channelCount, sampleRate))
std::vector<sf::SoundChannel> channelMap(channelMapSize);
for (std::size_t i = 0; i < channelMap.size(); ++i)
channelMap[i] = static_cast<sf::SoundChannel>(channelMapData[i]);
if (!buffer->This.loadFromSamples(samples, sampleCount, channelCount, sampleRate, channelMap))
{
delete buffer;
buffer = nullptr;
-7
View File
@@ -75,13 +75,6 @@ bool sfSoundRecorder_isAvailable(void)
}
////////////////////////////////////////////////////////////
void sfSoundRecorder_setProcessingInterval(sfSoundRecorder* soundRecorder, sfTime interval)
{
CSFML_CALL(soundRecorder, setProcessingInterval(interval));
}
////////////////////////////////////////////////////////////
const char** sfSoundRecorder_getAvailableDevices(size_t* count)
{
-5
View File
@@ -51,11 +51,6 @@ public :
{
}
void setProcessingInterval(sfTime interval)
{
sf::SoundRecorder::setProcessingInterval(sf::microseconds(interval.microseconds));
}
private :
bool onStart() override
+3 -1
View File
@@ -35,9 +35,11 @@ sfSoundStream* sfSoundStream_create(sfSoundStreamGetDataCallback onGetData,
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize,
void* userData)
{
return new sfSoundStream(onGetData, onSeek, channelCount, sampleRate, userData);
return new sfSoundStream(onGetData, onSeek, channelCount, sampleRate, channelMapData, channelMapSize, userData);
}
+10 -2
View File
@@ -28,6 +28,7 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundChannel.h>
#include <SFML/Audio/SoundStream.hpp>
@@ -43,12 +44,17 @@ public :
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize,
void* userData) :
myGetDataCallback(onGetData),
mySeekCallback (onSeek),
myUserData (userData)
{
initialize(channelCount, sampleRate);
std::vector<sf::SoundChannel> channelMap(channelMapSize);
for (std::size_t i = 0; i < channelMap.size(); ++i)
channelMap[i] = static_cast<sf::SoundChannel>(channelMapData[i]);
initialize(channelCount, sampleRate, channelMap);
}
private :
@@ -88,8 +94,10 @@ struct sfSoundStream
sfSoundStreamSeekCallback onSeek,
unsigned int channelCount,
unsigned int sampleRate,
sfSoundChannel* channelMapData,
size_t channelMapSize,
void* userData) :
This(onGetData, onSeek, channelCount, sampleRate, userData)
This(onGetData, onSeek, channelCount, sampleRate, channelMapData, channelMapSize, userData)
{
}
+135 -77
View File
@@ -37,84 +37,142 @@
////////////////////////////////////////////////////////////
inline void convertEvent(const sf::Event& sfmlEvent, sfEvent* event)
{
// Convert its type
event->type = static_cast<sfEventType>(sfmlEvent.type);
// Fill its fields
switch (event->type)
if (sfmlEvent.is<sf::Event::Closed>())
{
case sfEvtResized :
event->size.width = sfmlEvent.size.width;
event->size.height = sfmlEvent.size.height;
break;
case sfEvtTextEntered :
event->text.unicode = sfmlEvent.text.unicode;
break;
case sfEvtKeyReleased :
case sfEvtKeyPressed :
event->key.code = static_cast<sfKeyCode>(sfmlEvent.key.code);
event->key.scancode = static_cast<sfScancode>(sfmlEvent.key.scancode);
event->key.alt = sfmlEvent.key.alt;
event->key.control = sfmlEvent.key.control;
event->key.shift = sfmlEvent.key.shift;
event->key.system = sfmlEvent.key.system;
break;
case sfEvtMouseWheelScrolled :
event->mouseWheelScroll.wheel = static_cast<sfMouseWheel>(sfmlEvent.mouseWheelScroll.wheel);
event->mouseWheelScroll.delta = sfmlEvent.mouseWheelScroll.delta;
event->mouseWheelScroll.x = sfmlEvent.mouseWheelScroll.x;
event->mouseWheelScroll.y = sfmlEvent.mouseWheelScroll.y;
break;
case sfEvtMouseButtonPressed :
case sfEvtMouseButtonReleased :
event->mouseButton.button = static_cast<sfMouseButton>(sfmlEvent.mouseButton.button);
event->mouseButton.x = sfmlEvent.mouseButton.x;
event->mouseButton.y = sfmlEvent.mouseButton.y;
break;
case sfEvtMouseMoved :
event->mouseMove.x = sfmlEvent.mouseMove.x;
event->mouseMove.y = sfmlEvent.mouseMove.y;
break;
case sfEvtJoystickButtonPressed :
case sfEvtJoystickButtonReleased :
event->joystickButton.joystickId = sfmlEvent.joystickButton.joystickId;
event->joystickButton.button = sfmlEvent.joystickButton.button;
break;
case sfEvtJoystickMoved :
event->joystickMove.joystickId = sfmlEvent.joystickMove.joystickId;
event->joystickMove.axis = static_cast<sfJoystickAxis>(sfmlEvent.joystickMove.axis);
event->joystickMove.position = sfmlEvent.joystickMove.position;
break;
case sfEvtJoystickConnected :
case sfEvtJoystickDisconnected :
event->joystickConnect.joystickId = sfmlEvent.joystickConnect.joystickId;
break;
case sfEvtTouchBegan :
case sfEvtTouchMoved :
case sfEvtTouchEnded :
event->touch.finger = sfmlEvent.touch.finger;
event->touch.x = sfmlEvent.touch.x;
event->touch.y = sfmlEvent.touch.y;
break;
case sfEvtSensorChanged :
event->sensor.sensorType = static_cast<sfSensorType>(sfmlEvent.sensor.type);
event->sensor.x = sfmlEvent.sensor.x;
event->sensor.y = sfmlEvent.sensor.y;
event->sensor.z = sfmlEvent.sensor.z;
break;
default :
break;
event->type = sfEvtClosed;
}
else if (const auto* resized = sfmlEvent.getIf<sf::Event::Resized>())
{
event->type = sfEvtResized;
event->size.width = resized->size.x;
event->size.height = resized->size.y;
}
else if (sfmlEvent.is<sf::Event::FocusLost>())
{
event->type = sfEvtFocusLost;
}
else if (sfmlEvent.is<sf::Event::FocusGained>())
{
event->type = sfEvtFocusGained;
}
else if (const auto* textEntered = sfmlEvent.getIf<sf::Event::TextEntered>())
{
event->type = sfEvtTextEntered;
event->text.unicode = textEntered->unicode;
}
else if (const auto* keyReleased = sfmlEvent.getIf<sf::Event::KeyReleased>())
{
event->type = sfEvtKeyReleased;
event->key.code = static_cast<sfKeyCode>(keyReleased->code);
event->key.scancode = static_cast<sfScancode>(keyReleased->scancode);
event->key.alt = keyReleased->alt;
event->key.control = keyReleased->control;
event->key.shift = keyReleased->shift;
event->key.system = keyReleased->system;
}
else if (const auto* keyPressed = sfmlEvent.getIf<sf::Event::KeyPressed>())
{
event->type = sfEvtKeyPressed;
event->key.code = static_cast<sfKeyCode>(keyPressed->code);
event->key.scancode = static_cast<sfScancode>(keyPressed->scancode);
event->key.alt = keyPressed->alt;
event->key.control = keyPressed->control;
event->key.shift = keyPressed->shift;
event->key.system = keyPressed->system;
}
else if (const auto* mouseWheelScrolled = sfmlEvent.getIf<sf::Event::MouseWheelScrolled>())
{
event->type = sfEvtMouseWheelScrolled;
event->mouseWheelScroll.wheel = static_cast<sfMouseWheel>(mouseWheelScrolled->wheel);
event->mouseWheelScroll.delta = mouseWheelScrolled->delta;
event->mouseWheelScroll.x = mouseWheelScrolled->position.x;
event->mouseWheelScroll.y = mouseWheelScrolled->position.y;
}
else if (const auto* mouseButtonPressed = sfmlEvent.getIf<sf::Event::MouseButtonPressed>())
{
event->type = sfEvtMouseButtonPressed;
event->mouseButton.button = static_cast<sfMouseButton>(mouseButtonPressed->button);
event->mouseButton.x = mouseButtonPressed->position.x;
event->mouseButton.y = mouseButtonPressed->position.y;
}
else if (const auto* mouseButtonReleased = sfmlEvent.getIf<sf::Event::MouseButtonReleased>())
{
event->type = sfEvtMouseButtonReleased;
event->mouseButton.button = static_cast<sfMouseButton>(mouseButtonReleased->button);
event->mouseButton.x = mouseButtonReleased->position.x;
event->mouseButton.y = mouseButtonReleased->position.y;
}
else if (const auto* mouseMoved = sfmlEvent.getIf<sf::Event::MouseMoved>())
{
event->type = sfEvtMouseMoved;
event->mouseMove.x = mouseMoved->position.x;
event->mouseMove.y = mouseMoved->position.y;
}
else if (sfmlEvent.is<sf::Event::MouseEntered>())
{
event->type = sfEvtMouseEntered;
}
else if (sfmlEvent.is<sf::Event::MouseLeft>())
{
event->type = sfEvtMouseLeft;
}
else if (const auto* joystickButtonPressed = sfmlEvent.getIf<sf::Event::JoystickButtonPressed>())
{
event->type = sfEvtJoystickButtonPressed;
event->joystickButton.joystickId = joystickButtonPressed->joystickId;
event->joystickButton.button = joystickButtonPressed->button;
}
else if (const auto* joystickButtonReleased = sfmlEvent.getIf<sf::Event::JoystickButtonReleased>())
{
event->type = sfEvtJoystickButtonReleased;
event->joystickButton.joystickId = joystickButtonReleased->joystickId;
event->joystickButton.button = joystickButtonReleased->button;
}
else if (const auto* joystickMoved = sfmlEvent.getIf<sf::Event::JoystickMoved>())
{
event->type = sfEvtJoystickMoved;
event->joystickMove.joystickId = joystickMoved->joystickId;
event->joystickMove.axis = static_cast<sfJoystickAxis>(joystickMoved->axis);
event->joystickMove.position = joystickMoved->position;
}
else if (const auto* joystickConnected = sfmlEvent.getIf<sf::Event::JoystickConnected>())
{
event->type = sfEvtJoystickConnected;
event->joystickConnect.joystickId = joystickConnected->joystickId;
}
else if (const auto* joystickDisconnected = sfmlEvent.getIf<sf::Event::JoystickDisconnected>())
{
event->type = sfEvtJoystickDisconnected;
event->joystickConnect.joystickId = joystickDisconnected->joystickId;
}
else if (const auto* touchBegan = sfmlEvent.getIf<sf::Event::TouchBegan>())
{
event->type = sfEvtTouchBegan;
event->touch.finger = touchBegan->finger;
event->touch.x = touchBegan->position.x;
event->touch.y = touchBegan->position.y;
}
else if (const auto* touchMoved = sfmlEvent.getIf<sf::Event::TouchMoved>())
{
event->type = sfEvtTouchMoved;
event->touch.finger = touchMoved->finger;
event->touch.x = touchMoved->position.x;
event->touch.y = touchMoved->position.y;
}
else if (const auto* touchEnded = sfmlEvent.getIf<sf::Event::TouchEnded>())
{
event->type = sfEvtTouchEnded;
event->touch.finger = touchEnded->finger;
event->touch.x = touchEnded->position.x;
event->touch.y = touchEnded->position.y;
}
else if (const auto* sensorChanged = sfmlEvent.getIf<sf::Event::SensorChanged>())
{
event->type = sfEvtSensorChanged;
event->sensor.sensorType = static_cast<sfSensorType>(sensorChanged->type);
event->sensor.x = sensorChanged->value.x;
event->sensor.y = sensorChanged->value.y;
event->sensor.z = sensorChanged->value.z;
}
}
+4 -6
View File
@@ -150,11 +150,10 @@ bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
sf::Event sfmlEvent;
bool ret = renderWindow->This.pollEvent(sfmlEvent);
const sf::Event sfmlEvent = renderWindow->This.pollEvent();
// No event, return
if (!ret)
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
@@ -171,11 +170,10 @@ bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
sf::Event sfmlEvent;
bool ret = renderWindow->This.waitEvent(sfmlEvent);
const sf::Event sfmlEvent = renderWindow->This.waitEvent();
// Error, return
if (!ret)
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
+4 -6
View File
@@ -132,11 +132,10 @@ bool sfWindow_pollEvent(sfWindow* window, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
sf::Event sfmlEvent;
bool ret = window->This.pollEvent(sfmlEvent);
const sf::Event sfmlEvent = window->This.pollEvent();
// No event, return
if (!ret)
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
@@ -153,11 +152,10 @@ bool sfWindow_waitEvent(sfWindow* window, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
sf::Event sfmlEvent;
bool ret = window->This.waitEvent(sfmlEvent);
const sf::Event sfmlEvent = window->This.waitEvent();
// Error, return
if (!ret)
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
+4 -6
View File
@@ -100,11 +100,10 @@ bool sfWindowBase_pollEvent(sfWindowBase* windowBase, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
sf::Event sfmlEvent;
bool ret = windowBase->This.pollEvent(sfmlEvent);
const sf::Event sfmlEvent = windowBase->This.pollEvent();
// No event, return
if (!ret)
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
@@ -121,11 +120,10 @@ bool sfWindowBase_waitEvent(sfWindowBase* windowBase, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
sf::Event sfmlEvent;
bool ret = windowBase->This.waitEvent(sfmlEvent);
const sf::Event sfmlEvent = windowBase->This.waitEvent();
// Error, return
if (!ret)
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent