Skip to content

Commit

Permalink
Merge pull request #95 from YGNI-RType/dev
Browse files Browse the repository at this point in the history
hotfix AudioManager: float conversion and transmission through network lost volume data
  • Loading branch information
Popochounet authored Nov 27, 2024
2 parents b88ef61 + 1a9713f commit cd938e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions include/GEngine/libdev/components/driver/output/Sound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ struct Sound : public gengine::Component<Sound> {
struct Music : public gengine::Component<Music> {
bool pause = false;
std::uint64_t musicId;
float volume;
uint16_t volume;

Music(std::uint64_t musicId, float volume = 1)
Music(std::uint64_t musicId, uint16_t volume = UINT16_MAX)
: musicId(musicId)
, volume(volume) {
}
Expand Down
9 changes: 4 additions & 5 deletions include/GEngine/libdev/systems/driver/output/AudioManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ class AudioManager
void onMusic(gengine::system::event::driver::output::Music &e) {
auto &musics = getComponents<gengine::component::driver::output::Music>();
auto &netSends = getComponents<geg::component::network::NetSend>();

if (!musics.size())
spawnEntity(gengine::component::driver::output::Music(getMusicIdByPath(e.path)),
if (!musics.size()) {
spawnEntity(gengine::component::driver::output::Music(getMusicIdByPath(e.path), e.volume * UINT16_MAX),
geg::component::network::NetSend());
else {
} else {
getMusicComponent().musicId = getMusicIdByPath(e.path);
getMusicComponent().volume = e.volume;
getMusicComponent().volume = e.volume * UINT16_MAX;
for (auto [e, _unused, netSend] : gengine::Zip(musics, netSends)) {
netSend.update();
break;
Expand Down
6 changes: 3 additions & 3 deletions source/GEngine/libdev/systems/driver/output/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void AudioManager::onMainLoop(geg::event::RenderLoop &e) {
StopMusicStream(getMusicById(m_currentMusicId));
m_currentMusicId = music.musicId;
PlayMusicStream(getMusicById(m_currentMusicId));
SetMusicVolume(getMusicById(m_currentMusicId), music.volume);
SetMusicVolume(getMusicById(m_currentMusicId), float(music.volume) / UINT16_MAX);
}
}

Expand All @@ -95,10 +95,10 @@ void AudioManager::onMainLoop(geg::event::RenderLoop &e) {
gengine::component::driver::output::Music &AudioManager::getMusicComponent(void) {
auto &musics = getComponents<gengine::component::driver::output::Music>();

if (!musics.size())
THROW_WARNING("Music component not initilazed");
for (auto &[_, m] : musics)
return m;

THROW_WARNING("Music component not initilazed");
}

void AudioManager::onSoundPlayed(
Expand Down

0 comments on commit cd938e0

Please sign in to comment.