Skip to content

Commit

Permalink
Fix API changes in SFML 3
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed May 23, 2024
1 parent 1b53960 commit 2b2154a
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 138 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: SFML/SFML
ref: c89c32d7baa15927a39a161a4ead867c11d5ea21
ref: 7234fc149bf21b12fbb10deec73025fdfec07808
path: SFML

- name: Configure SFML CMake
Expand Down
48 changes: 17 additions & 31 deletions src/SFML/Audio/SoundBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,22 @@
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_createFromFile(const char* filename)
{
sfSoundBuffer* buffer = new sfSoundBuffer;
auto soundBuffer = sf::SoundBuffer::loadFromFile(filename);
if (!soundBuffer)
return nullptr;

if (!buffer->This.loadFromFile(filename))
{
delete buffer;
buffer = nullptr;
}

return buffer;
return new sfSoundBuffer{std::move(*soundBuffer)};
}


////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_createFromMemory(const void* data, size_t sizeInBytes)
{
sfSoundBuffer* buffer = new sfSoundBuffer;

if (!buffer->This.loadFromMemory(data, sizeInBytes))
{
delete buffer;
buffer = nullptr;
}
auto soundBuffer = sf::SoundBuffer::loadFromMemory(data, sizeInBytes);
if (!soundBuffer)
return nullptr;

return buffer;
return new sfSoundBuffer{std::move(*soundBuffer)};
}


Expand All @@ -67,15 +59,12 @@ sfSoundBuffer* sfSoundBuffer_createFromStream(sfInputStream* stream)
{
CSFML_CHECK_RETURN(stream, nullptr);

sfSoundBuffer* buffer = new sfSoundBuffer;
CallbackStream sfmlStream(stream);
if (!buffer->This.loadFromStream(sfmlStream))
{
delete buffer;
buffer = nullptr;
}
auto soundBuffer = sf::SoundBuffer::loadFromStream(sfmlStream);
if (!soundBuffer)
return nullptr;

return buffer;
return new sfSoundBuffer{std::move(*soundBuffer)};
}


Expand All @@ -87,18 +76,15 @@ sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples,
sfSoundChannel* channelMapData,
size_t channelMapSize)
{
sfSoundBuffer* buffer = new sfSoundBuffer;

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;
}

return buffer;
auto soundBuffer = sf::SoundBuffer::loadFromSamples(samples, sampleCount, channelCount, sampleRate, channelMap);
if (!soundBuffer)
return nullptr;

return new sfSoundBuffer{std::move(*soundBuffer)};
}


Expand Down
4 changes: 2 additions & 2 deletions src/SFML/Audio/SoundBufferRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ const sfSoundBuffer* sfSoundBufferRecorder_getBuffer(const sfSoundBufferRecorder
{
CSFML_CHECK_RETURN(soundBufferRecorder, nullptr);

soundBufferRecorder->SoundBuffer.This = soundBufferRecorder->This.getBuffer();
soundBufferRecorder->SoundBuffer = sfSoundBuffer{soundBufferRecorder->This.getBuffer()};

return &soundBufferRecorder->SoundBuffer;
return &*soundBufferRecorder->SoundBuffer;
}

////////////////////////////////////////////////////////////
Expand Down
8 changes: 5 additions & 3 deletions src/SFML/Audio/SoundBufferRecorderStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@
#include <SFML/Audio/SoundBufferRecorder.hpp>
#include <SFML/Audio/SoundBufferStruct.h>

#include <optional>


////////////////////////////////////////////////////////////
// Internal structure of sfSoundBufferRecorder
////////////////////////////////////////////////////////////
struct sfSoundBufferRecorder
{
sf::SoundBufferRecorder This;
mutable sfSoundBuffer SoundBuffer;
std::string DeviceName;
sf::SoundBufferRecorder This;
mutable std::optional<sfSoundBuffer> SoundBuffer;
std::string DeviceName;
};


Expand Down
35 changes: 13 additions & 22 deletions src/SFML/Graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,22 @@
////////////////////////////////////////////////////////////
sfFont* sfFont_createFromFile(const char* filename)
{
sfFont* font = new sfFont;
if (!font->This.loadFromFile(filename))
{
delete font;
font = nullptr;
}
const auto font = sf::Font::loadFromFile(filename);
if (!font)
return nullptr;

return font;
return new sfFont{std::move(*font), {}, {}};
}


////////////////////////////////////////////////////////////
sfFont* sfFont_createFromMemory(const void* data, size_t sizeInBytes)
{
sfFont* font = new sfFont;
if (!font->This.loadFromMemory(data, sizeInBytes))
{
delete font;
font = nullptr;
}
const auto font = sf::Font::loadFromMemory(data, sizeInBytes);
if (!font)
return nullptr;

return font;
return new sfFont{std::move(*font), {}, {}};
}


Expand All @@ -64,15 +58,12 @@ sfFont* sfFont_createFromStream(sfInputStream* stream)
{
CSFML_CHECK_RETURN(stream, nullptr);

sfFont* font = new sfFont;
font->Stream = CallbackStream(stream);
if (!font->This.loadFromStream(font->Stream))
{
delete font;
font = nullptr;
}
CallbackStream sfmlStream(stream);
const auto font = sf::Font::loadFromStream(sfmlStream);
if (!font)
return nullptr;

return font;
return new sfFont{std::move(*font), {}, sfmlStream};
}


Expand Down
51 changes: 15 additions & 36 deletions src/SFML/Graphics/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,60 +35,43 @@
////////////////////////////////////////////////////////////
sfImage* sfImage_create(unsigned int width, unsigned int height)
{
sfImage* image = new sfImage;
image->This.create({ width, height });

return image;
return new sfImage{sf::Image({width, height})};
}


////////////////////////////////////////////////////////////
sfImage* sfImage_createFromColor(unsigned int width, unsigned int height, sfColor color)
{
sfImage* image = new sfImage;
image->This.create({ width, height }, sf::Color(color.r, color.g, color.b, color.a));

return image;
return new sfImage{sf::Image({ width, height }, sf::Color(color.r, color.g, color.b, color.a))};
}


////////////////////////////////////////////////////////////
sfImage* sfImage_createFromPixels(unsigned int width, unsigned int height, const uint8_t* data)
{
sfImage* image = new sfImage;
image->This.create({ width, height }, data);

return image;
return new sfImage{sf::Image({ width, height }, data)};
}


////////////////////////////////////////////////////////////
sfImage* sfImage_createFromFile(const char* filename)
{
sfImage* image = new sfImage;

if (!image->This.loadFromFile(filename))
{
delete image;
image = nullptr;
}
const auto image = sf::Image::loadFromFile(filename);
if (!image)
return nullptr;

return image;
return new sfImage{std::move(*image)};
}


////////////////////////////////////////////////////////////
sfImage* sfImage_createFromMemory(const void* data, size_t sizeInBytes)
{
sfImage* image = new sfImage;
const auto image = sf::Image::loadFromMemory(data, sizeInBytes);
if (!image)
return nullptr;

if (!image->This.loadFromMemory(data, sizeInBytes))
{
delete image;
image = nullptr;
}

return image;
return new sfImage{std::move(*image)};
}


Expand All @@ -97,16 +80,12 @@ sfImage* sfImage_createFromStream(sfInputStream* stream)
{
CSFML_CHECK_RETURN(stream, nullptr);

sfImage* image = new sfImage;

CallbackStream sfmlStream(stream);
if (!image->This.loadFromStream(sfmlStream))
{
delete image;
image = nullptr;
}
const auto image = sf::Image::loadFromStream(sfmlStream);
if (!image)
return nullptr;

return image;
return new sfImage{std::move(*image)};
}


Expand Down
Loading

0 comments on commit 2b2154a

Please sign in to comment.