Skip to content

Commit

Permalink
Move the assignation of sound with its sound samples file out of the …
Browse files Browse the repository at this point in the history
…AudioManager. So that they can be assigned out of the class: e.g:

context_->GetSubsystem<AudioManager>()->RegisterAudio(AudioDefs::MUSIC::MENU, Sounds/achievement.wav);
  • Loading branch information
urnenfeld committed Apr 3, 2021
1 parent 17f64c4 commit e8e236e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
15 changes: 15 additions & 0 deletions app/src/main/cpp/Audio/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ void AudioManager::SubscribeConsoleCommands()
SendEvent(ConsoleHandlerEvents::E_CONSOLE_COMMAND_ADD, data);
}

void AudioManager::RegisterAudio(AudioDefs::SOUND_EFFECTS effect, String file)
{
soundEffects_[effect] = file;
}

void AudioManager::RegisterAudio(AudioDefs::MUSIC music, String file)
{
music_[music] = file;
}

void AudioManager::RegisterAudio(AudioDefs::AMBIENT_SOUNDS ambient, String file)
{
ambientSounds_[ambient] = file;
}

void AudioManager::HandlePlaySound(StringHash eventType, VariantMap& eventData)
{
using namespace PlaySound;
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/cpp/Audio/AudioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@

using namespace Urho3D;


namespace AudioDefs {
enum SOUND_EFFECTS : unsigned int;
enum MUSIC : unsigned int;
enum AMBIENT_SOUNDS : unsigned int;
}


class AudioManager : public Object
{
URHO3D_OBJECT(AudioManager, Object);
Expand All @@ -20,6 +28,21 @@ class AudioManager : public Object

virtual ~AudioManager();

/**
* Register Sound Effects assigned to AudioManager
*/
void RegisterAudio(AudioDefs::SOUND_EFFECTS effect, String file);

/**
* Register Music assigned to AudioManager
*/
void RegisterAudio(AudioDefs::MUSIC music, String file);

/**
* Register Ambient Sounds to AudioManager
*/
void RegisterAudio(AudioDefs::AMBIENT_SOUNDS ambient, String file);

/**
* When enabled, multiple music tracks can be played simultaneously
* If disabled, previous music track will be stopped when new music
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/Audio/AudioManagerDefs.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#pragma once

namespace AudioDefs {
enum SOUND_EFFECTS {
enum SOUND_EFFECTS : unsigned int {
HIT,
THROW,
BUTTON_CLICK,
ACHIEVEMENT,
PLACE_BLOCK
};

enum MUSIC {
enum MUSIC : unsigned int {
GAME,
MENU
};

enum AMBIENT_SOUNDS {
enum AMBIENT_SOUNDS : unsigned int {
LEVEL
};
}

0 comments on commit e8e236e

Please sign in to comment.