Skip to content

Commit

Permalink
SFML 3.0 migration update (#1727)
Browse files Browse the repository at this point in the history
* SFML migration update

* SFML migration update

---------

Co-authored-by: Jon Daniel <jopadan@mailfence.com>
Co-authored-by: Jon Daniel <jondaniel879@gmail.com>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent 6054a2d commit 84a3c9b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Audio/ModMusic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ bool ModMusic::openFromFile(const string& filename)
dumb_module_ = dumb_load_any(filename.c_str(), 0, 0);
if (dumb_module_ != nullptr)
{
#if (SFML_VERSION_MAJOR > 2)
initialize(2, 44100, getChannelMap());
#else
initialize(2, 44100);
#endif
return true;
}
else
Expand All @@ -103,7 +107,11 @@ bool ModMusic::loadFromMemory(const uint8_t* data, const uint32_t size)
dumb_module_ = dumb_read_any(dumbfile_open_memory((const char*)data, size), 0, 0);
if (dumb_module_ != nullptr)
{
#if (SFML_VERSION_MAJOR > 2)
initialize(2, 44100, getChannelMap());
#else
initialize(2, 44100);
#endif
dumb_player_ = duh_start_sigrenderer(dumb_module_, 0, 2, 0);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Audio/ModMusic.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ModMusic : public sf::SoundStream
bool onGetData(Chunk& data) override;
void onSeek(sf::Time timeOffset) override;

sf::Int16 samples_[44100]{};
int16_t samples_[44100]{};
DUH* dumb_module_ = nullptr;
DUH_SIGRENDERER* dumb_player_ = nullptr;

Expand Down
17 changes: 17 additions & 0 deletions src/Audio/Mp3Music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ bool Mp3Music::openFromFile(const std::string& filename)
return false;
}

#if (SFML_VERSION_MAJOR > 2)
initialize(channels, rate, getChannelMap());
#else
initialize(channels, rate);
#endif

return true;
}
Expand Down Expand Up @@ -181,7 +185,11 @@ bool Mp3Music::loadFromMemory(void* data, size_t size_in_bytes)

log::info("rate {}, channels {}", rate, channels);

#if (SFML_VERSION_MAJOR > 2)
initialize(channels, rate, getChannelMap());
#else
initialize(channels, rate);
#endif

return true;
}
Expand All @@ -201,7 +209,11 @@ sf::Time Mp3Music::duration() const

bool Mp3Music::onGetData(Chunk& data)
{
#if (SFML_VERSION_MAJOR > 2)
std::lock_guard lock(mutex_);
#else
sf::Lock lock(mutex_);
#endif

if (handle_)
{
Expand All @@ -219,7 +231,12 @@ bool Mp3Music::onGetData(Chunk& data)

void Mp3Music::onSeek(sf::Time time_offset)
{
#if (SFML_VERSION_MAJOR > 2)
std::lock_guard lock(mutex_);
#else
sf::Lock lock(mutex_);
#endif


// tschumacher: sampleoff must be (seconds * samplingRate) to make this working correctly
if (handle_)
Expand Down
5 changes: 5 additions & 0 deletions src/Audio/Mp3Music.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ class Mp3Music : public sf::SoundStream
mpg123_handle* handle_ = nullptr;
size_t buffer_size_ = 0;
unsigned char* buffer_ = nullptr;
#if (SFML_VERSION_MAJOR > 2)
std::mutex mutex_;
#else
sf::Mutex mutex_;
#endif

long sampling_rate_ = 0;
};
} // namespace slade::audio
8 changes: 8 additions & 0 deletions src/General/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,23 @@ string web::getHttp(const string& host, const string& uri)
// Setup connection & request
sf::Http http(host);
sf::Http::Request request;
#if (SFML_VERSION_MAJOR > 2)
request.setMethod(sf::Http::Request::Method::Get);
#else
request.setMethod(sf::Http::Request::Get);
#endif
request.setUri(uri);

// Send HTTP request
auto response = http.sendRequest(request);

switch (response.getStatus())
{
#if (SFML_VERSION_MAJOR > 2)
case sf::Http::Response::Status::Ok: return response.getBody();
#else
case sf::Http::Response::Ok: return response.getBody();
#endif
default: return "connect_failed";
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/MainEditor/UI/EntryPanel/AudioEntryPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ CVAR(Bool, snd_autoplay, false, CVar::Flag::Save)
AudioEntryPanel::AudioEntryPanel(wxWindow* parent) :
EntryPanel(parent, "audio"),
timer_seek_{ new wxTimer(this) },
#if (SFML_VERSION_MAJOR > 2)
sound_{ new sf::Sound(*sound_buffer_) },
#else
sound_{ new sf::Sound() },
#endif
music_{ new audio::Music() },
mod_{ new audio::ModMusic() },
mp3_{ new audio::Mp3Music() }
Expand Down Expand Up @@ -722,11 +726,19 @@ void AudioEntryPanel::onTimer(wxTimerEvent& e)
slider_seek_->SetValue(pos);

// Stop the timer if playback has reached the end
#if (SFML_VERSION_MAJOR > 2)
if (pos >= slider_seek_->GetMax() || (audio_type_ == Sound && sound_->getStatus() == sf::Sound::Status::Stopped)
|| (audio_type_ == Music && music_->getStatus() == sf::Sound::Status::Stopped)
|| (audio_type_ == Mod && mod_->getStatus() == sf::Sound::Status::Stopped)
|| (audio_type_ == Mp3 && mp3_->getStatus() == sf::Sound::Status::Stopped)
|| (audio_type_ == MIDI && !audio::midiPlayer().isPlaying()))
#else
if (pos >= slider_seek_->GetMax() || (audio_type_ == Sound && sound_->getStatus() == sf::Sound::Stopped)
|| (audio_type_ == Music && music_->getStatus() == sf::Sound::Stopped)
|| (audio_type_ == Mod && mod_->getStatus() == sf::Sound::Stopped)
|| (audio_type_ == Mp3 && mp3_->getStatus() == sf::Sound::Stopped)
|| (audio_type_ == MIDI && !audio::midiPlayer().isPlaying()))
#endif
{
timer_seek_->Stop();
slider_seek_->SetValue(0);
Expand Down

0 comments on commit 84a3c9b

Please sign in to comment.