-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made OpenAL context management more intelligent, in analogy to OpenGL…
… context management. OpenAL contexts now only exist as long as AlResources require them and are destroyed when they are no longer required. Fixes #30.
- Loading branch information
1 parent
337df1e
commit c7bb5da
Showing
14 changed files
with
377 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//////////////////////////////////////////////////////////// | ||
// | ||
// SFML - Simple and Fast Multimedia Library | ||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) | ||
// | ||
// This software is provided 'as-is', without any express or implied warranty. | ||
// In no event will the authors be held liable for any damages arising from the use of this software. | ||
// | ||
// Permission is granted to anyone to use this software for any purpose, | ||
// including commercial applications, and to alter it and redistribute it freely, | ||
// subject to the following restrictions: | ||
// | ||
// 1. The origin of this software must not be misrepresented; | ||
// you must not claim that you wrote the original software. | ||
// If you use this software in a product, an acknowledgment | ||
// in the product documentation would be appreciated but is not required. | ||
// | ||
// 2. Altered source versions must be plainly marked as such, | ||
// and must not be misrepresented as being the original software. | ||
// | ||
// 3. This notice may not be removed or altered from any source distribution. | ||
// | ||
//////////////////////////////////////////////////////////// | ||
|
||
#ifndef SFML_ALRESOURCE_HPP | ||
#define SFML_ALRESOURCE_HPP | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Headers | ||
//////////////////////////////////////////////////////////// | ||
#include <SFML/Audio/Export.hpp> | ||
|
||
|
||
namespace sf | ||
{ | ||
//////////////////////////////////////////////////////////// | ||
/// \brief Base class for classes that require an OpenAL context | ||
/// | ||
//////////////////////////////////////////////////////////// | ||
class SFML_AUDIO_API AlResource | ||
{ | ||
protected : | ||
|
||
//////////////////////////////////////////////////////////// | ||
/// \brief Default constructor | ||
/// | ||
//////////////////////////////////////////////////////////// | ||
AlResource(); | ||
|
||
//////////////////////////////////////////////////////////// | ||
/// \brief Destructor | ||
/// | ||
//////////////////////////////////////////////////////////// | ||
~AlResource(); | ||
}; | ||
|
||
} // namespace sf | ||
|
||
|
||
#endif // SFML_ALRESOURCE_HPP | ||
|
||
//////////////////////////////////////////////////////////// | ||
/// \class sf::AlResource | ||
/// \ingroup audio | ||
/// | ||
/// This class is for internal use only, it must be the base | ||
/// of every class that requires a valid OpenAL context in | ||
/// order to work. | ||
/// | ||
//////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//////////////////////////////////////////////////////////// | ||
// | ||
// SFML - Simple and Fast Multimedia Library | ||
// Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com) | ||
// | ||
// This software is provided 'as-is', without any express or implied warranty. | ||
// In no event will the authors be held liable for any damages arising from the use of this software. | ||
// | ||
// Permission is granted to anyone to use this software for any purpose, | ||
// including commercial applications, and to alter it and redistribute it freely, | ||
// subject to the following restrictions: | ||
// | ||
// 1. The origin of this software must not be misrepresented; | ||
// you must not claim that you wrote the original software. | ||
// If you use this software in a product, an acknowledgment | ||
// in the product documentation would be appreciated but is not required. | ||
// | ||
// 2. Altered source versions must be plainly marked as such, | ||
// and must not be misrepresented as being the original software. | ||
// | ||
// 3. This notice may not be removed or altered from any source distribution. | ||
// | ||
//////////////////////////////////////////////////////////// | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Headers | ||
//////////////////////////////////////////////////////////// | ||
#include <SFML/Audio/AlResource.hpp> | ||
#include <SFML/Audio/AudioDevice.hpp> | ||
#include <SFML/System/Mutex.hpp> | ||
#include <SFML/System/Lock.hpp> | ||
|
||
|
||
namespace | ||
{ | ||
// OpenAL resources counter and its mutex | ||
unsigned int count = 0; | ||
sf::Mutex mutex; | ||
|
||
// The audio device is instantiated on demand rather than at global startup, | ||
// which solves a lot of weird crashes and errors. | ||
// It is destroyed when it is no longer needed. | ||
sf::priv::AudioDevice* globalDevice; | ||
} | ||
|
||
|
||
namespace sf | ||
{ | ||
//////////////////////////////////////////////////////////// | ||
AlResource::AlResource() | ||
{ | ||
// Protect from concurrent access | ||
Lock lock(mutex); | ||
|
||
// If this is the very first resource, trigger the global device initialization | ||
if (count == 0) | ||
globalDevice = new priv::AudioDevice; | ||
|
||
// Increment the resources counter | ||
count++; | ||
} | ||
|
||
|
||
//////////////////////////////////////////////////////////// | ||
AlResource::~AlResource() | ||
{ | ||
// Protect from concurrent access | ||
Lock lock(mutex); | ||
|
||
// Decrement the resources counter | ||
count--; | ||
|
||
// If there's no more resource alive, we can destroy the device | ||
if (count == 0) | ||
delete globalDevice; | ||
} | ||
|
||
} // namespace sf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.