MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / GameSound

Method GameSound

source/sound/SoundEffectsManager.cpp:30–66  ·  view source on GitHub ↗

class GameSound

Source from the content-addressed store, hash-verified

28
29// class GameSound
30GameSound::GameSound(const std::string& filename, bool spatialSound):
31 mSound(nullptr),
32 mSoundBuffer(nullptr)
33{
34 // Loads the buffer
35 mSoundBuffer = new sf::SoundBuffer();
36 if (mSoundBuffer->loadFromFile(filename) == false)
37 {
38 delete mSoundBuffer;
39 mSoundBuffer = nullptr;
40 return;
41 }
42
43 mFilename = filename;
44
45 mSound = new sf::Sound();
46 // Loads the main sound object
47 mSound->setBuffer(*mSoundBuffer);
48
49 mSound->setLoop(false);
50
51 // Sets a correct attenuation value if the sound is spatial
52 if (spatialSound == true)
53 {
54 // Set convenient spatial fading unit.
55 mSound->setVolume(100.0f);
56 mSound->setAttenuation(3.0f);
57 mSound->setMinDistance(3.0f);
58 }
59 else // Disable attenuation for sounds that must heard the same way everywhere
60 {
61 // Prevents the sound from being too loud
62 mSound->setRelativeToListener(true);
63 mSound->setVolume(30.0f);
64 mSound->setAttenuation(0.0f);
65 }
66}
67
68GameSound::~GameSound()
69{

Callers

nothing calls this directly

Calls 1

loadFromFileMethod · 0.80

Tested by

no test coverage detected