diff --git a/ee.files b/ee.files
index e64c94a98..4e9daf447 100644
--- a/ee.files
+++ b/ee.files
@@ -814,3 +814,4 @@ src/bnb/cgamedata.hpp
src/bnb/cgamedata.cpp
src/bnb/cgameobjectdoor.hpp
src/bnb/cgameobjectdoor.cpp
+src/audio/openal.cpp
diff --git a/ee.lib.win.cbp b/ee.lib.win.cbp
index 1ea0d93eb..6af7050cd 100644
--- a/ee.lib.win.cbp
+++ b/ee.lib.win.cbp
@@ -77,6 +77,7 @@
+
diff --git a/src/audio/caudiodevice.cpp b/src/audio/caudiodevice.cpp
index 2ed47abd1..b52150b9f 100755
--- a/src/audio/caudiodevice.cpp
+++ b/src/audio/caudiodevice.cpp
@@ -3,13 +3,10 @@
namespace EE { namespace Audio {
-cAudioDevice * cAudioDevice::mInstance = NULL;
+ALCdevice * mDevice = NULL;
+ALCcontext * mContext = NULL;
-cAudioDevice::cAudioDevice() :
- mDevice(NULL),
- mContext(NULL),
- mRefCount(0)
-{
+cAudioDevice::cAudioDevice() {
PrintInfo();
// Create the device
@@ -23,8 +20,8 @@ cAudioDevice::cAudioDevice() :
alcMakeContextCurrent( mContext );
// Initialize the listener, located at the origin and looking along the Z axis
- cAudioListener::instance()->Position(0.f, 0.f, 0.f);
- cAudioListener::instance()->Target(0.f, 0.f, -1.f);
+ //cAudioListener::Position(0.f, 0.f, 0.f);
+ //cAudioListener::Target(0.f, 0.f, -1.f);
std::string log( "OpenAL current device:\n" );
log += "\t" + std::string( (const char *)alcGetString(mDevice, ALC_DEVICE_SPECIFIER) );
@@ -69,42 +66,8 @@ cAudioDevice::~cAudioDevice() {
alcCloseDevice( mDevice );
}
-bool cAudioDevice::isCreated() {
- return mContext && mDevice;
-}
-
-cAudioDevice * cAudioDevice::instance() {
- // Create the audio device if it doesn't exist
- if ( NULL == mInstance )
- mInstance = eeNew( cAudioDevice, () );
-
- return mInstance;
-}
-
-void cAudioDevice::AddReference() {
- cAudioDevice::instance();
-
- // Increase the references count
- mInstance->mRefCount++;
-}
-
-void cAudioDevice::RemoveReference() {
- // Decrease the references count
- mInstance->mRefCount--;
-
- // Destroy the audio device if the references count reaches 0
- if (mInstance->mRefCount == 0) {
- eeDelete( mInstance );
- mInstance = NULL;
- }
-}
-
-ALCdevice * cAudioDevice::GetDevice() const {
- return mDevice;
-}
-
bool cAudioDevice::IsExtensionSupported( const std::string& extension ) {
- cAudioDevice::instance();
+ EnsureALInit();
if ( ( extension.length() > 2 ) && ( extension.substr(0, 3) == "ALC" ) )
return alcIsExtensionPresent( mDevice, extension.c_str() ) != AL_FALSE;
@@ -112,10 +75,10 @@ bool cAudioDevice::IsExtensionSupported( const std::string& extension ) {
return alIsExtensionPresent( extension.c_str() ) != AL_FALSE;
}
-ALenum cAudioDevice::GetFormatFromChannelsCount(unsigned int ChannelsCount) const {
- cAudioDevice::instance();
+ALenum cAudioDevice::GetFormatFromChannelsCount( unsigned int ChannelsCount ) {
+ EnsureALInit();
- switch (ChannelsCount) {
+ switch ( ChannelsCount ) {
case 1 : return AL_FORMAT_MONO16;
case 2 : return AL_FORMAT_STEREO16;
case 4 : return alGetEnumValue("AL_FORMAT_QUAD16");
@@ -123,7 +86,12 @@ ALenum cAudioDevice::GetFormatFromChannelsCount(unsigned int ChannelsCount) cons
case 7 : return alGetEnumValue("AL_FORMAT_61CHN16");
case 8 : return alGetEnumValue("AL_FORMAT_71CHN16");
}
+
return 0;
}
+bool cAudioDevice::IsAvailable() {
+ return NULL != mDevice && NULL != mContext;
+}
+
}}
diff --git a/src/audio/caudiodevice.hpp b/src/audio/caudiodevice.hpp
index 4f32a1781..2225115d7 100755
--- a/src/audio/caudiodevice.hpp
+++ b/src/audio/caudiodevice.hpp
@@ -7,30 +7,16 @@ namespace EE { namespace Audio {
class EE_API cAudioDevice {
public :
- static cAudioDevice * instance();
-
- static void AddReference();
-
- static void RemoveReference();
-
- ALCdevice * GetDevice() const;
-
- ALenum GetFormatFromChannelsCount(unsigned int ChannelsCount) const;
-
- bool IsExtensionSupported( const std::string& extension );
-
- bool isCreated();
-
- ~cAudioDevice();
- private :
cAudioDevice();
- static cAudioDevice * mInstance;
+ ~cAudioDevice();
- ALCdevice * mDevice;
- ALCcontext * mContext;
- unsigned int mRefCount;
+ static ALenum GetFormatFromChannelsCount( unsigned int ChannelsCount );
+ static bool IsExtensionSupported( const std::string& extension );
+
+ static bool IsAvailable();
+ private :
void PrintInfo();
};
diff --git a/src/audio/caudiolistener.cpp b/src/audio/caudiolistener.cpp
index 2f326d8ca..33754623e 100755
--- a/src/audio/caudiolistener.cpp
+++ b/src/audio/caudiolistener.cpp
@@ -3,10 +3,14 @@
namespace EE { namespace Audio {
void cAudioListener::GlobalVolume( const ALfloat& Volume ) {
+ EnsureALInit();
+
ALCheck( alListenerf( AL_GAIN, Volume * 0.01f ) );
}
ALfloat cAudioListener::GlobalVolume() {
+ EnsureALInit();
+
ALfloat Volume = 0.f;
ALCheck( alGetListenerf( AL_GAIN, &Volume ) );
@@ -14,14 +18,18 @@ ALfloat cAudioListener::GlobalVolume() {
}
void cAudioListener::Position( const ALfloat& X, const ALfloat& Y, const ALfloat& Z ) {
+ EnsureALInit();
+
ALCheck( alListener3f( AL_POSITION, X, Y, Z ) );
}
void cAudioListener::Position(const Vector3AL& Position) {
- this->Position( Position.x, Position.y, Position.z );
+ cAudioListener::Position( Position.x, Position.y, Position.z );
}
Vector3AL cAudioListener::Position() {
+ EnsureALInit();
+
Vector3AL Position;
ALCheck( alGetListener3f( AL_POSITION, &Position.x, &Position.y, &Position.z ) );
@@ -29,15 +37,19 @@ Vector3AL cAudioListener::Position() {
}
void cAudioListener::Target( const ALfloat& X, const ALfloat& Y, const ALfloat& Z ) {
+ EnsureALInit();
+
ALfloat Orientation[] = {X, Y, Z, 0.f, 1.f, 0.f};
ALCheck( alListenerfv( AL_ORIENTATION, Orientation ) );
}
void cAudioListener::Target(const Vector3AL& Target) {
- this->Target( Target.x, Target.y, Target.z );
+ cAudioListener::Target( Target.x, Target.y, Target.z );
}
Vector3AL cAudioListener::Target() {
+ EnsureALInit();
+
ALfloat Orientation[6];
ALCheck( alGetListenerfv( AL_ORIENTATION, Orientation ) );
diff --git a/src/audio/caudiolistener.hpp b/src/audio/caudiolistener.hpp
index e5008ae79..689375976 100755
--- a/src/audio/caudiolistener.hpp
+++ b/src/audio/caudiolistener.hpp
@@ -8,33 +8,33 @@ namespace EE { namespace Audio {
typedef Vector3 Vector3AL; //! Use this special vector because OpenAL doesn't support doubles.
/** @brief Listener is a global interface for defining the audio listener properties. */
-class EE_API cAudioListener : public tSingleton {
+class EE_API cAudioListener {
public:
/** Change the global volume of all the sounds. ( default 100 )
* @param Volume New global volume, in the range [0, 100]
*/
- void GlobalVolume( const ALfloat& Volume );
+ static void GlobalVolume( const ALfloat& Volume );
/** Get the Global Volume */
- ALfloat GlobalVolume();
+ static ALfloat GlobalVolume();
/** Change the position of the listener. \n The default position is (0, 0, 0) */
- void Position( const ALfloat& X, const ALfloat& Y, const ALfloat& Z );
+ static void Position( const ALfloat& X, const ALfloat& Y, const ALfloat& Z );
/** Change the position of the listener from a 3D vector. */
- void Position(const Vector3AL& Position);
+ static void Position(const Vector3AL& Position);
/** Get the current position of the listener */
- Vector3AL Position();
+ static Vector3AL Position();
/** Change the orientation of the listener (the point he must look at). \n The default target is (0, 0, -1). */
- void Target( const ALfloat& X, const ALfloat& Y, const ALfloat& Z );
+ static void Target( const ALfloat& X, const ALfloat& Y, const ALfloat& Z );
/** Change the orientation of the listener from a 3D vector. */
- void Target(const Vector3AL& Target);
+ static void Target(const Vector3AL& Target);
/** Get the current orientation of the listener (the point he's looking at) */
- Vector3AL Target();
+ static Vector3AL Target();
};
}}
diff --git a/src/audio/caudioresource.cpp b/src/audio/caudioresource.cpp
index 0704d3996..75c6b5f6b 100755
--- a/src/audio/caudioresource.cpp
+++ b/src/audio/caudioresource.cpp
@@ -3,15 +3,12 @@
namespace EE { namespace Audio {
cAudioResource::cAudioResource() {
- cAudioDevice::AddReference();
}
cAudioResource::cAudioResource(const cAudioResource&) {
- cAudioDevice::AddReference();
}
cAudioResource::~cAudioResource() {
- cAudioDevice::RemoveReference();
}
}}
diff --git a/src/audio/caudioresource.hpp b/src/audio/caudioresource.hpp
index 8f14b105a..c2618eef5 100755
--- a/src/audio/caudioresource.hpp
+++ b/src/audio/caudioresource.hpp
@@ -8,7 +8,9 @@ namespace EE { namespace Audio {
class EE_API cAudioResource {
protected :
cAudioResource();
+
cAudioResource(const cAudioResource&);
+
virtual ~cAudioResource();
};
diff --git a/src/audio/cmusic.cpp b/src/audio/cmusic.cpp
index 5dab8bd24..7f2fbe2f0 100755
--- a/src/audio/cmusic.cpp
+++ b/src/audio/cmusic.cpp
@@ -52,7 +52,7 @@ bool cMusic::OpenFromFile( const std::string& Filename ) {
mDuration = static_cast( mFile->GetSamplesCount() ) / mFile->GetSampleRate() / mFile->GetChannelsCount();
// Initialize the stream
- Initialize(mFile->GetChannelsCount(), mFile->GetSampleRate());
+ Initialize( mFile->GetChannelsCount(), mFile->GetSampleRate() );
cLog::instance()->Write( "Music file " + Filename + " loaded." );
return true;
diff --git a/src/audio/csound.cpp b/src/audio/csound.cpp
index 8fe84474c..496e1b799 100755
--- a/src/audio/csound.cpp
+++ b/src/audio/csound.cpp
@@ -3,18 +3,18 @@
namespace EE { namespace Audio {
cSound::cSound() : mBuffer(NULL) {
- ALCheck( alGenSources(1, &mSource) );
- ALCheck( alSourcei(mSource, AL_BUFFER, 0) );
+ ALCheck( alGenSources( 1, &mSource ) );
+ ALCheck( alSourcei( mSource, AL_BUFFER, 0 ) );
}
cSound::cSound( const cSoundBuffer& Buffer, const bool& Loop, const eeFloat& Pitch, const eeFloat& Volume, const Vector3AL& Position ) : mBuffer(&Buffer) {
ALCheck( alGenSources(1, &mSource) );
- ALCheck( alSourcei (mSource, AL_BUFFER, Buffer.mBuffer) );
- ALCheck( alSourcei (mSource, AL_LOOPING, Loop) );
- ALCheck( alSourcef (mSource, AL_PITCH, Pitch) );
- ALCheck( alSourcef (mSource, AL_GAIN, Volume * 0.01f) );
- ALCheck( alSource3f(mSource, AL_POSITION, Position.x, Position.y, Position.z) );
+ ALCheck( alSourcei ( mSource, AL_BUFFER, Buffer.mBuffer ) );
+ ALCheck( alSourcei ( mSource, AL_LOOPING, Loop ) );
+ ALCheck( alSourcef ( mSource, AL_PITCH, Pitch ) );
+ ALCheck( alSourcef ( mSource, AL_GAIN, Volume * 0.01f ) );
+ ALCheck( alSource3f( mSource, AL_POSITION, Position.x, Position.y, Position.z ) );
}
cSound::cSound(const cSound& Copy) :
@@ -42,15 +42,15 @@ cSound::~cSound() {
}
void cSound::Play() {
- ALCheck( alSourcePlay(mSource) );
+ ALCheck( alSourcePlay( mSource ) );
}
void cSound::Pause() {
- ALCheck( alSourcePause(mSource) );
+ ALCheck( alSourcePause( mSource ) );
}
void cSound::Stop() {
- ALCheck( alSourceStop(mSource) );
+ ALCheck( alSourceStop( mSource ) );
}
void cSound::Buffer(const cSoundBuffer& Buffer) {
@@ -62,23 +62,23 @@ void cSound::Buffer(const cSoundBuffer& Buffer) {
mBuffer = &Buffer;
mBuffer->AttachSound (this );
- ALCheck( alSourcei(mSource, AL_BUFFER, mBuffer ? mBuffer->mBuffer : 0) );
+ ALCheck( alSourcei( mSource, AL_BUFFER, mBuffer ? mBuffer->mBuffer : 0 ) );
}
void cSound::Loop( const bool& Loop ) {
- ALCheck( alSourcei(mSource, AL_LOOPING, Loop) );
+ ALCheck( alSourcei( mSource, AL_LOOPING, Loop ) );
}
void cSound::Pitch( const eeFloat& Pitch ) {
- ALCheck( alSourcef(mSource, AL_PITCH, Pitch) );
+ ALCheck( alSourcef( mSource, AL_PITCH, Pitch ) );
}
void cSound::Volume( const eeFloat& Volume ) {
- ALCheck( alSourcef(mSource, AL_GAIN, Volume * 0.01f) );
+ ALCheck( alSourcef( mSource, AL_GAIN, Volume * 0.01f ) );
}
void cSound::Position( const eeFloat& X, const eeFloat& Y, const eeFloat& Z ) {
- ALCheck( alSource3f(mSource, AL_POSITION, X, Y, Z) );
+ ALCheck( alSource3f( mSource, AL_POSITION, X, Y, Z ) );
}
void cSound::Position( const Vector3AL& Position ) {
@@ -86,11 +86,11 @@ void cSound::Position( const Vector3AL& Position ) {
}
void cSound::MinDistance( const eeFloat& MinDistance ) {
- ALCheck( alSourcef(mSource, AL_REFERENCE_DISTANCE, MinDistance) );
+ ALCheck( alSourcef( mSource, AL_REFERENCE_DISTANCE, MinDistance ) );
}
void cSound::Attenuation( const eeFloat& Attenuation ) {
- ALCheck( alSourcef(mSource, AL_ROLLOFF_FACTOR, Attenuation) );
+ ALCheck( alSourcef( mSource, AL_ROLLOFF_FACTOR, Attenuation ) );
}
const cSoundBuffer* cSound::Buffer() const {
@@ -99,49 +99,49 @@ const cSoundBuffer* cSound::Buffer() const {
bool cSound::Loop() const {
ALint Loop;
- ALCheck( alGetSourcei(mSource, AL_LOOPING, &Loop) );
+ ALCheck( alGetSourcei( mSource, AL_LOOPING, &Loop ) );
return Loop != 0;
}
eeFloat cSound::Pitch() const {
ALfloat Pitch;
- ALCheck( alGetSourcef(mSource, AL_PITCH, &Pitch) );
+ ALCheck( alGetSourcef( mSource, AL_PITCH, &Pitch ) );
return Pitch;
}
eeFloat cSound::Volume() const {
ALfloat Gain;
- ALCheck( alGetSourcef(mSource, AL_GAIN, &Gain) );
+ ALCheck( alGetSourcef( mSource, AL_GAIN, &Gain ) );
return Gain * 100.f;
}
Vector3AL cSound::Position() const {
Vector3AL Position;
- ALCheck( alGetSource3f(mSource, AL_POSITION, &Position.x, &Position.y, &Position.z) );
+ ALCheck( alGetSource3f( mSource, AL_POSITION, &Position.x, &Position.y, &Position.z ) );
return Position;
}
eeFloat cSound::MinDistance() const {
ALfloat MinDistance;
- ALCheck( alGetSourcef(mSource, AL_REFERENCE_DISTANCE, &MinDistance) );
+ ALCheck( alGetSourcef( mSource, AL_REFERENCE_DISTANCE, &MinDistance ) );
return MinDistance;
}
eeFloat cSound::Attenuation() const {
ALfloat Attenuation;
- ALCheck( alGetSourcef(mSource, AL_ROLLOFF_FACTOR, &Attenuation) );
+ ALCheck( alGetSourcef( mSource, AL_ROLLOFF_FACTOR, &Attenuation ) );
return Attenuation;
}
EE_SOUND_STATE cSound::GetState() const {
ALint State;
- ALCheck( alGetSourcei(mSource, AL_SOURCE_STATE, &State) );
+ ALCheck( alGetSourcei( mSource, AL_SOURCE_STATE, &State ) );
switch (State) {
case AL_INITIAL :
@@ -153,15 +153,15 @@ EE_SOUND_STATE cSound::GetState() const {
return SOUND_STOPPED;
}
-eeFloat cSound::PlayingOffset() const {
+Uint32 cSound::PlayingOffset() const {
ALfloat Seconds = 0.f;
- ALCheck( alGetSourcef(mSource, AL_SEC_OFFSET, &Seconds) );
+ ALCheck( alGetSourcef( mSource, AL_SEC_OFFSET, &Seconds ) );
- return Seconds;
+ return static_cast ( Seconds * 1000 );
}
-void cSound::PlayingOffset( const eeFloat& TimeOffset ) {
- ALCheck( alSourcef(mSource, AL_SEC_OFFSET, TimeOffset) );
+void cSound::PlayingOffset( const Uint32& TimeOffset ) {
+ ALCheck( alSourcef( mSource, AL_SEC_OFFSET, TimeOffset / 1000.f ) );
}
cSound& cSound::operator =( const cSound& Other ) {
@@ -202,10 +202,13 @@ void cSound::ResetBuffer() {
Stop();
// Detach the buffer
- ALCheck( alSourcei( mSource, AL_BUFFER, 0) );
+ ALCheck( alSourcei( mSource, AL_BUFFER, 0 ) );
mBuffer = NULL;
}
+EE_SOUND_STATE cSound::State() const {
+ return GetState();
+}
}}
diff --git a/src/audio/csound.hpp b/src/audio/csound.hpp
index 5354335ba..d65c6b450 100755
--- a/src/audio/csound.hpp
+++ b/src/audio/csound.hpp
@@ -17,6 +17,7 @@ enum EE_SOUND_STATE {
class EE_API cSound : public cAudioResource {
public :
cSound();
+
~cSound();
/** Construct the sound from its parameters */
@@ -83,15 +84,15 @@ class EE_API cSound : public cAudioResource {
EE_SOUND_STATE GetState() const;
/** Get the Sound State */
- EE_SOUND_STATE State() const { return GetState(); };
+ EE_SOUND_STATE State() const;
/** Get the current playing position of the sound */
- virtual eeFloat PlayingOffset() const;
+ virtual Uint32 PlayingOffset() const;
/** Set the current playing position of the sound
- * @param TimeOffset : New playing position, expressed in seconds
+ * @param TimeOffset : New playing position, expressed in miliseconds
*/
- virtual void PlayingOffset( const eeFloat& TimeOffset );
+ virtual void PlayingOffset( const Uint32& TimeOffset );
/** Assignment operator */
cSound& operator =(const cSound& Other);
diff --git a/src/audio/csoundbuffer.cpp b/src/audio/csoundbuffer.cpp
index e71f39710..05e7808c2 100755
--- a/src/audio/csoundbuffer.cpp
+++ b/src/audio/csoundbuffer.cpp
@@ -1,5 +1,6 @@
#include "csoundbuffer.hpp"
#include "csound.hpp"
+#include "caudiodevice.hpp"
#include "../system/cpackmanager.hpp"
namespace EE { namespace Audio {
@@ -8,6 +9,8 @@ cSoundBuffer::cSoundBuffer() :
mBuffer(0),
mDuration(0.f)
{
+ EnsureALInit();
+
ALCheck( alGenBuffers( 1, &mBuffer ) );
}
@@ -18,6 +21,8 @@ cSoundBuffer::cSoundBuffer(const cSoundBuffer& Copy) :
mDuration(Copy.mDuration),
mSounds()
{
+ EnsureALInit();
+
ALCheck( alGenBuffers( 1, &mBuffer ) );
Update( Copy.GetChannelsCount(), Copy.GetSampleRate() );
}
@@ -169,7 +174,7 @@ unsigned int cSoundBuffer::GetChannelsCount() const {
return ChannelsCount;
}
-eeFloat cSoundBuffer::GetDuration() const {
+Uint32 cSoundBuffer::GetDuration() const {
return mDuration;
}
@@ -190,7 +195,7 @@ bool cSoundBuffer::Update( unsigned int ChannelsCount, unsigned int SampleRate )
return false;
// Find the good format according to the number of channels
- ALenum Format = cAudioDevice::instance()->GetFormatFromChannelsCount( ChannelsCount );
+ ALenum Format = cAudioDevice::GetFormatFromChannelsCount( ChannelsCount );
// Check if the format is valid
if ( Format == 0 ) {
@@ -203,7 +208,7 @@ bool cSoundBuffer::Update( unsigned int ChannelsCount, unsigned int SampleRate )
ALCheck( alBufferData( mBuffer, Format, &mSamples[0], Size, SampleRate ) );
// Compute the duration
- mDuration = static_cast( mSamples.size() ) / SampleRate / ChannelsCount;
+ mDuration = static_cast( 1000 * mSamples.size() ) / SampleRate / ChannelsCount;
return true;
}
diff --git a/src/audio/csoundbuffer.hpp b/src/audio/csoundbuffer.hpp
index 0960db38f..5b2d051e4 100755
--- a/src/audio/csoundbuffer.hpp
+++ b/src/audio/csoundbuffer.hpp
@@ -2,7 +2,6 @@
#define EE_AUDIOCSOUNDBUFFER_H
#include "base.hpp"
-#include "caudiodevice.hpp"
#include "caudioresource.hpp"
#include "csoundfile.hpp"
@@ -13,6 +12,7 @@ class cSound;
class EE_API cSoundBuffer : public cAudioResource {
public :
cSoundBuffer();
+
~cSoundBuffer();
/** Copy constructor */
@@ -46,7 +46,7 @@ class EE_API cSoundBuffer : public cAudioResource {
unsigned int GetChannelsCount() const;
/** Get the Sound Duration */
- eeFloat GetDuration() const;
+ Uint32 GetDuration() const;
/** Assignment operator */
cSoundBuffer& operator =(const cSoundBuffer& Other);
@@ -55,7 +55,7 @@ class EE_API cSoundBuffer : public cAudioResource {
unsigned int mBuffer; ///< OpenAL buffer identifier
std::vector mSamples; ///< Samples buffer
- eeFloat mDuration; ///< Sound duration, in seconds
+ Uint32 mDuration; ///< Sound duration, in miliseconds
typedef std::set SoundList;
mutable SoundList mSounds;
diff --git a/src/audio/csoundfile.cpp b/src/audio/csoundfile.cpp
index 8ab227bfd..432dc9e66 100755
--- a/src/audio/csoundfile.cpp
+++ b/src/audio/csoundfile.cpp
@@ -156,7 +156,7 @@ void cSoundFile::Write(const Int16*, std::size_t) {
cLog::instance()->Write( "Failed to write to sound file (not supported)" );
}
-void cSoundFile::Seek( float timeOffset ) {
+void cSoundFile::Seek( Uint32 timeOffset ) {
cLog::instance()->Write( "Trying to seek a file that doesn't support seeking." );
}
diff --git a/src/audio/csoundfile.hpp b/src/audio/csoundfile.hpp
index c788e890d..aa662380d 100755
--- a/src/audio/csoundfile.hpp
+++ b/src/audio/csoundfile.hpp
@@ -7,27 +7,34 @@ namespace EE { namespace Audio {
class EE_API cSoundFile {
public:
- static cSoundFile* CreateRead(const std::string& Filename);
- static cSoundFile* CreateRead(const char* Data, std::size_t SizeInBytes);
- static cSoundFile* CreateWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
+ static cSoundFile * CreateRead(const std::string& Filename);
+
+ static cSoundFile * CreateRead(const char* Data, std::size_t SizeInBytes);
+
+ static cSoundFile * CreateWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
virtual ~cSoundFile();
std::size_t GetSamplesCount() const;
+
unsigned int GetChannelsCount() const;
+
unsigned int GetSampleRate() const;
bool Restart();
virtual std::size_t Read(Int16* Data, std::size_t NbSamples);
+
virtual void Write(const Int16* Data, std::size_t NbSamples);
- virtual void Seek( float timeOffset );
+ virtual void Seek( Uint32 timeOffset );
protected :
cSoundFile();
virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
+
virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
+
virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
std::size_t mNbSamples;
diff --git a/src/audio/csoundfiledefault.cpp b/src/audio/csoundfiledefault.cpp
index 10b81b8cf..23e05c604 100755
--- a/src/audio/csoundfiledefault.cpp
+++ b/src/audio/csoundfiledefault.cpp
@@ -146,9 +146,9 @@ void cSoundFileDefault::Write( const Int16 * Data, std::size_t NbSamples ) {
sf_write_short( mFile, Data, NbSamples );
}
-void cSoundFileDefault::Seek(float timeOffset) {
+void cSoundFileDefault::Seek( Uint32 timeOffset ) {
if ( NULL != mFile ) {
- sf_count_t frameOffset = static_cast( timeOffset * mSampleRate );
+ sf_count_t frameOffset = static_cast( timeOffset * mSampleRate / 1000 );
sf_seek( mFile, frameOffset, SEEK_SET );
}
}
diff --git a/src/audio/csoundfiledefault.hpp b/src/audio/csoundfiledefault.hpp
index 8e02faa3b..a59f57379 100755
--- a/src/audio/csoundfiledefault.hpp
+++ b/src/audio/csoundfiledefault.hpp
@@ -13,6 +13,7 @@ namespace EE { namespace Audio {
class EE_API cSoundFileDefault : public cSoundFile {
public :
cSoundFileDefault();
+
~cSoundFileDefault();
/** Check if a given file is supported by this loader. */
@@ -22,12 +23,15 @@ class EE_API cSoundFileDefault : public cSoundFile {
static bool IsFileSupported(const char* Data, std::size_t SizeInBytes);
virtual std::size_t Read(Int16* Data, std::size_t NbSamples);
+
virtual void Write(const Int16* Data, std::size_t NbSamples);
- virtual void Seek( float timeOffset );
+ virtual void Seek( Uint32 timeOffset );
private :
virtual bool OpenRead( const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate );
+
virtual bool OpenRead( const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate );
+
virtual bool OpenWrite( const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate );
static int GetFormatFromFilename(const std::string& Filename);
diff --git a/src/audio/csoundfileogg.cpp b/src/audio/csoundfileogg.cpp
index 4b2318b70..c4d3e63f1 100755
--- a/src/audio/csoundfileogg.cpp
+++ b/src/audio/csoundfileogg.cpp
@@ -96,9 +96,9 @@ std::size_t cSoundFileOgg::Read( Int16 * Data, std::size_t NbSamples ) {
return 0;
}
-void cSoundFileOgg::Seek(float timeOffset) {
+void cSoundFileOgg::Seek( Uint32 timeOffset ) {
if ( NULL != mStream ) {
- unsigned int frameOffset = static_cast( timeOffset * mSampleRate );
+ Uint32 frameOffset = static_cast( timeOffset * mSampleRate / 1000 );
stb_vorbis_seek( mStream, frameOffset );
}
}
diff --git a/src/audio/csoundfileogg.hpp b/src/audio/csoundfileogg.hpp
index 5a5bc26a2..a60f74b8b 100755
--- a/src/audio/csoundfileogg.hpp
+++ b/src/audio/csoundfileogg.hpp
@@ -20,9 +20,10 @@ class EE_API cSoundFileOgg : public cSoundFile {
virtual std::size_t Read(Int16* Data, std::size_t NbSamples);
- virtual void Seek( float timeOffset );
+ virtual void Seek( Uint32 timeOffset );
private :
virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
+
virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
stb_vorbis * mStream; ///< Vorbis stream
diff --git a/src/audio/csoundstream.cpp b/src/audio/csoundstream.cpp
index b2f648ce6..7640b374b 100755
--- a/src/audio/csoundstream.cpp
+++ b/src/audio/csoundstream.cpp
@@ -1,4 +1,5 @@
#include "csoundstream.hpp"
+#include "caudiodevice.hpp"
namespace EE { namespace Audio {
@@ -17,11 +18,11 @@ cSoundStream::~cSoundStream() {
}
void cSoundStream::Initialize(unsigned int ChannelsCount, unsigned int SampleRate) {
- mChannelsCount = ChannelsCount;
- mSampleRate = SampleRate;
+ mChannelsCount = ChannelsCount;
+ mSampleRate = SampleRate;
// Deduce the format from the number of channels
- mFormat = cAudioDevice::instance()->GetFormatFromChannelsCount(ChannelsCount);
+ mFormat = cAudioDevice::GetFormatFromChannelsCount(ChannelsCount);
if ( mFormat == 0 ) { // Check if the format is valid
mChannelsCount = 0;
@@ -41,15 +42,19 @@ void cSoundStream::Play() {
return;
}
- if ( OnStart() ) { // Notify the derived class
- mIsStreaming = true; // Start updating the stream in a separate thread to avoid blocking the application
- Launch();
- }
+ OnSeek( 0 );
+
+ mSamplesProcessed = 0;
+ mIsStreaming = true; // Start updating the stream in a separate thread to avoid blocking the application
+ Launch();
+}
+
+void cSoundStream::Pause() {
+ ALCheck( alSourcePause( mSource ) );
}
void cSoundStream::Stop() {
mIsStreaming = false; // Wait for the thread to terminate
- mSamplesProcessed = 0;
Wait();
}
@@ -70,11 +75,11 @@ EE_SOUND_STATE cSoundStream::GetState() const {
return Status;
}
-eeFloat cSoundStream::GetPlayingOffset() const {
- return cSound::PlayingOffset() + static_cast(mSamplesProcessed) / mSampleRate / mChannelsCount;
+Uint32 cSoundStream::PlayingOffset() const {
+ return static_cast( cSound::PlayingOffset() ) * 1000 + 1000 * mSamplesProcessed / mSampleRate / mChannelsCount;
}
-void cSoundStream::SetPlayingOffset( float timeOffset ) {
+void cSoundStream::PlayingOffset( Uint32 timeOffset ) {
// Stop the stream
Stop();
@@ -82,7 +87,7 @@ void cSoundStream::SetPlayingOffset( float timeOffset ) {
OnSeek( timeOffset );
// Restart streaming
- mSamplesProcessed = static_cast( timeOffset * mSampleRate * mChannelsCount );
+ mSamplesProcessed = static_cast( timeOffset ) * mSampleRate * mChannelsCount / 1000;
mIsStreaming = true;
@@ -98,11 +103,10 @@ bool cSoundStream::Loop() const {
}
void cSoundStream::Run() {
- if ( !cAudioDevice::instance()->isCreated() )
- return;
-
ALCheck( alGenBuffers( BuffersCount, mBuffers ) );
- unsigned int EndBuffer = 0xFFFF;
+
+ for ( int i = 0; i < BuffersCount; ++i )
+ mEndBuffers[i] = false;
// Fill the queue
bool RequestStop = FillQueue();
@@ -122,7 +126,7 @@ void cSoundStream::Run() {
}
// Get the number of buffers that have been processed (ie. ready for reuse)
- ALint NbProcessed;
+ ALint NbProcessed = 0;
ALCheck( alGetSourcei( cSound::mSource, AL_BUFFERS_PROCESSED, &NbProcessed ) );
while ( NbProcessed-- ) {
@@ -130,30 +134,31 @@ void cSoundStream::Run() {
ALuint Buffer;
ALCheck( alSourceUnqueueBuffers( cSound::mSource, 1, &Buffer ) );
+ // Find its number
+ Uint32 bufferNum = 0;
+ for (int i = 0; i < BuffersCount; ++i) {
+ if ( mBuffers[i] == Buffer ) {
+ bufferNum = i;
+ break;
+ }
+ }
+
// Retrieve its size and add it to the samples count
- if ( Buffer == EndBuffer ) {
+ if ( mEndBuffers[bufferNum] ) {
// This was the last buffer: reset the sample count
mSamplesProcessed = 0;
- EndBuffer = 0xFFFF;
+ mEndBuffers[bufferNum] = false;
} else {
- ALint Size;
- ALCheck( alGetBufferi( Buffer, AL_SIZE, &Size ) );
- mSamplesProcessed += Size / sizeof(Int16);
+ ALint size, bits;
+ ALCheck( alGetBufferi( Buffer, AL_SIZE, &size ) );
+ ALCheck( alGetBufferi( Buffer, AL_BITS, &bits ) );
+ mSamplesProcessed += size / (bits / 8);
}
// Fill it and push it back into the playing queue
if ( !RequestStop ) {
- if ( FillAndPushBuffer( Buffer ) ) {
- // User requested to stop: check if we must loop or really stop
- if ( mLoop && OnStart() ) {
- // Looping: mark the current buffer as the last one
- // (to know when to reset the sample count)
- EndBuffer = Buffer;
- } else {
- // Not looping or restart failed: request stop
- RequestStop = true;
- }
- }
+ if ( FillAndPushBuffer( bufferNum ) )
+ RequestStop = true;
}
}
@@ -173,24 +178,42 @@ void cSoundStream::Run() {
ALCheck( alDeleteBuffers( BuffersCount, mBuffers ) );
}
-bool cSoundStream::FillAndPushBuffer( const unsigned int& Buffer) {
+bool cSoundStream::FillAndPushBuffer( const unsigned int& Buffer ) {
bool RequestStop = false;
// Acquire audio data
Chunk Data = {NULL, 0};
- if ( !OnGetData( Data ) )
- RequestStop = true;
+ if ( !OnGetData( Data ) ) {
+ // Mark the buffer as the last one (so that we know when to reset the playing position)
+ mEndBuffers[ Buffer ] = true;
+
+ // Check if the stream must loop or stop
+ if ( mLoop ) {
+ // Return to the beginning of the stream source
+ OnSeek( 0 );
+
+ // If we previously had no data, try to fill the buffer once again
+ if ( !Data.Samples || ( Data.NbSamples == 0 ) ) {
+ return FillAndPushBuffer( Buffer );
+ }
+ } else {
+ // Not looping: request stop
+ RequestStop = true;
+ }
+ }
// Create and fill the buffer, and push it to the queue
if ( Data.Samples && Data.NbSamples ) {
+ Uint32 buffer = mBuffers[ Buffer ];
+
// Fill the buffer
ALsizei Size = static_cast( Data.NbSamples ) * sizeof(Int16);
- ALCheck( alBufferData( Buffer, mFormat, Data.Samples, Size, mSampleRate ) );
+ ALCheck( alBufferData( buffer, mFormat, Data.Samples, Size, mSampleRate ) );
// Push it into the sound queue
- ALCheck( alSourceQueueBuffers( cSound::mSource, 1, &Buffer ) );
+ ALCheck( alSourceQueueBuffers( cSound::mSource, 1, &buffer ) );
}
return RequestStop;
@@ -201,7 +224,7 @@ bool cSoundStream::FillQueue() {
bool RequestStop = false;
for ( int i = 0; (i < BuffersCount) && !RequestStop; ++i ) {
- if ( FillAndPushBuffer( mBuffers[i] ) )
+ if ( FillAndPushBuffer( i ) )
RequestStop = true;
}
@@ -219,8 +242,8 @@ void cSoundStream::ClearQueue() {
ALCheck( alSourceUnqueueBuffers( cSound::mSource, 1, &Buffer ) );
}
-bool cSoundStream::OnStart() { // Called when the sound restarts
- return true; // Does nothing by default
+EE_SOUND_STATE cSoundStream::State() const {
+ return GetState();
}
}}
diff --git a/src/audio/csoundstream.hpp b/src/audio/csoundstream.hpp
index 06c982174..fe5af635d 100755
--- a/src/audio/csoundstream.hpp
+++ b/src/audio/csoundstream.hpp
@@ -2,7 +2,6 @@
#define EE_AUDIOCSOUNDSTREAM_H
#include "base.hpp"
-#include "caudiodevice.hpp"
#include "csound.hpp"
namespace EE { namespace Audio {
@@ -26,17 +25,22 @@ class EE_API cSoundStream : private cThread, private cSound {
virtual ~cSoundStream();
void Play();
+
+ void Pause();
+
void Stop();
unsigned int GetChannelsCount() const;
+
unsigned int GetSampleRate() const;
- EE_SOUND_STATE GetState() const;
- inline EE_SOUND_STATE State() const { return GetState(); };
+ EE_SOUND_STATE GetState() const;
- eeFloat GetPlayingOffset() const;
+ EE_SOUND_STATE State() const ;
- void SetPlayingOffset( float timeOffset );
+ Uint32 PlayingOffset() const;
+
+ void PlayingOffset( Uint32 timeOffset );
/** Set the stream loop state. This parameter is disabled by default
* @param Loop True to play in loop, false to play once
@@ -55,11 +59,9 @@ class EE_API cSoundStream : private cThread, private cSound {
private :
virtual void Run();
- virtual bool OnStart();
+ virtual bool OnGetData( Chunk& Data ) = 0;
- virtual bool OnGetData(Chunk& Data) = 0;
-
- virtual void OnSeek(float timeOffset) = 0;
+ virtual void OnSeek( float timeOffset ) = 0;
/** Fill a new buffer with audio data, and push it to the playing queue
* @param Buffer Buffer to fill
@@ -84,7 +86,8 @@ class EE_API cSoundStream : private cThread, private cSound {
unsigned int mSampleRate; ///< Frequency (samples / second)
unsigned long mFormat; ///< Format of the internal sound buffers
bool mLoop; ///< Loop flag (true to loop, false to play once)
- unsigned int mSamplesProcessed; ///< Number of buffers processed since beginning of the stream
+ Uint32 mSamplesProcessed; ///< Number of buffers processed since beginning of the stream
+ bool mEndBuffers[BuffersCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation
};
}}
diff --git a/src/audio/openal.cpp b/src/audio/openal.cpp
new file mode 100644
index 000000000..c0fbe9e12
--- /dev/null
+++ b/src/audio/openal.cpp
@@ -0,0 +1,46 @@
+#include "openal.hpp"
+#include "caudiodevice.hpp"
+
+namespace EE { namespace Audio {
+
+void ALCheckError(const std::string& File, unsigned int Line) {
+ // Get the last error
+ ALenum ErrorCode = alGetError();
+
+ if (ErrorCode != AL_NO_ERROR) {
+ std::string Error, Desc;
+
+ // Decode the error code
+ switch (ErrorCode) {
+ case AL_INVALID_NAME :
+ Error = "AL_INVALID_NAME";
+ Desc = "an unacceptable name has been specified";
+ break;
+ case AL_INVALID_ENUM :
+ Error = "AL_INVALID_ENUM";
+ Desc = "an unacceptable value has been specified for an enumerated argument";
+ break;
+ case AL_INVALID_VALUE :
+ Error = "AL_INVALID_VALUE";
+ Desc = "a numeric argument is out of range";
+ break;
+ case AL_INVALID_OPERATION :
+ Error = "AL_INVALID_OPERATION";
+ Desc = "the specified operation is not allowed in the current state";
+ break;
+ case AL_OUT_OF_MEMORY :
+ Error = "AL_OUT_OF_MEMORY";
+ Desc = "there is not enough memory left to execute the command";
+ break;
+ }
+
+ // Log the error
+ std::cerr << "An internal OpenAL call failed in " << File.substr(File.find_last_of("\\/") + 1) << " (" << Line << ") : " << Error << ", " << Desc << std::endl;
+ }
+}
+
+void EnsureALInit() {
+ static cAudioDevice GlobalDevice;
+}
+
+}}
diff --git a/src/audio/openal.hpp b/src/audio/openal.hpp
index 7c6dcfe33..40f612e48 100755
--- a/src/audio/openal.hpp
+++ b/src/audio/openal.hpp
@@ -1,6 +1,8 @@
#ifndef EE_OPENAL_H
#define EE_OPENAL_H
+#include "base.hpp"
+
#if EE_PLATFORM == EE_PLATFORM_MACOSX
#include
#include
@@ -21,40 +23,9 @@ namespace EE { namespace Audio {
#define ALCheck(Func) (Func)
#endif
-inline void ALCheckError(const std::string& File, unsigned int Line) {
- // Get the last error
- ALenum ErrorCode = alGetError();
- if (ErrorCode != AL_NO_ERROR) {
- std::string Error, Desc;
+void ALCheckError(const std::string& File, unsigned int Line);
- // Decode the error code
- switch (ErrorCode) {
- case AL_INVALID_NAME :
- Error = "AL_INVALID_NAME";
- Desc = "an unacceptable name has been specified";
- break;
- case AL_INVALID_ENUM :
- Error = "AL_INVALID_ENUM";
- Desc = "an unacceptable value has been specified for an enumerated argument";
- break;
- case AL_INVALID_VALUE :
- Error = "AL_INVALID_VALUE";
- Desc = "a numeric argument is out of range";
- break;
- case AL_INVALID_OPERATION :
- Error = "AL_INVALID_OPERATION";
- Desc = "the specified operation is not allowed in the current state";
- break;
- case AL_OUT_OF_MEMORY :
- Error = "AL_OUT_OF_MEMORY";
- Desc = "there is not enough memory left to execute the command";
- break;
- }
-
- // Log the error
- std::cerr << "An internal OpenAL call failed in " << File.substr(File.find_last_of("\\/") + 1) << " (" << Line << ") : " << Error << ", " << Desc << std::endl;
- }
-}
+void EnsureALInit();
}}
#endif
diff --git a/src/audio/tsoundmanager.hpp b/src/audio/tsoundmanager.hpp
index c4820171f..2f3ef2508 100755
--- a/src/audio/tsoundmanager.hpp
+++ b/src/audio/tsoundmanager.hpp
@@ -9,11 +9,14 @@ namespace EE { namespace Audio {
/** @brief A basic template to hold sounds and the respective buffer. */
template
-class tSoundManager{
+class tSoundManager {
public:
bool LoadFromFile( const T& id, const std::string& filepath );
+
bool LoadFromMemory( const T& id, const char* Data, std::size_t SizeInBytes );
+
bool LoadFromSamples( const T& id, const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate );
+
bool LoadFromPack( const T& id, cPack* Pack, const std::string& FilePackPath );
cSoundBuffer& GetBuffer( const T& id );
diff --git a/src/graphics/cconsole.cpp b/src/graphics/cconsole.cpp
index 5bbc3fe55..4c4f22f93 100755
--- a/src/graphics/cconsole.cpp
+++ b/src/graphics/cconsole.cpp
@@ -566,7 +566,7 @@ void cConsole::CmdSetVolume( const std::vector < String >& params ) {
bool Res = fromString( tFloat, params[1] );
if ( Res && ( tFloat >= 0.0f && tFloat <= 100.0f ) ) {
- EE::Audio::cAudioListener::instance()->GlobalVolume( tFloat );
+ EE::Audio::cAudioListener::GlobalVolume( tFloat );
PushText( "setvolume " + toStr( tFloat ) );
} else
PushText( "Valid parameters are between 0 and 100." );
diff --git a/src/graphics/ctexturefontloader.cpp b/src/graphics/ctexturefontloader.cpp
index 7834b03dc..24eb2ac95 100644
--- a/src/graphics/ctexturefontloader.cpp
+++ b/src/graphics/ctexturefontloader.cpp
@@ -17,7 +17,6 @@ cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoad
mFontLoaded( false )
{
mTexLoader = TexLoader;
- mTexLoader->Threaded( mThreaded );
}
cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const std::string& CoordinatesDatPath, const bool& VerticalDraw ) :
@@ -30,7 +29,6 @@ cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoad
mFontLoaded( false )
{
mTexLoader = TexLoader;
- mTexLoader->Threaded( mThreaded );
}
cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, cPack * Pack, const std::string& FilePackPath, const bool& VerticalDraw ) :
@@ -44,7 +42,6 @@ cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoad
mFontLoaded( false )
{
mTexLoader = TexLoader;
- mTexLoader->Threaded( mThreaded );
}
cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoader * TexLoader, const Uint8* CoordData, const Uint32& CoordDataSize, const bool& VerticalDraw ) :
@@ -58,7 +55,6 @@ cTextureFontLoader::cTextureFontLoader( const std::string FontName, cTextureLoad
mFontLoaded( false )
{
mTexLoader = TexLoader;
- mTexLoader->Threaded( mThreaded );
}
cTextureFontLoader::~cTextureFontLoader() {
@@ -68,16 +64,18 @@ cTextureFontLoader::~cTextureFontLoader() {
void cTextureFontLoader::Start() {
cObjectLoader::Start();
- mTexLoader->Threaded( mThreaded );
- mTexLoader->Load();
+ mTexLoader->Threaded( false );
- if ( !mThreaded )
+ if ( !mThreaded ) {
Update();
+ }
}
void cTextureFontLoader::Update() {
if ( !mLoaded ) {
if ( !mTexLoaded ) {
+ mTexLoader->Load();
+
mTexLoader->Update();
mTexLoaded = mTexLoader->IsLoaded();
@@ -145,6 +143,7 @@ void cTextureFontLoader::Unload() {
void cTextureFontLoader::Reset() {
cObjectLoader::Reset();
+ mFont = NULL;
mTexLoaded = false;
mFontLoaded = false;
}
diff --git a/src/system/cobjectloader.cpp b/src/system/cobjectloader.cpp
index 477249095..daac1ad31 100644
--- a/src/system/cobjectloader.cpp
+++ b/src/system/cobjectloader.cpp
@@ -15,24 +15,27 @@ cObjectLoader::~cObjectLoader()
}
void cObjectLoader::Load() {
- if ( mLoaded )
+ if ( mLoaded ) {
SetLoaded();
+ }
Launch();
}
void cObjectLoader::Load( ObjLoadCallback Cb ) {
- if ( Cb.IsSet() )
+ if ( Cb.IsSet() ) {
mLoadCbs.push_back( Cb );
+ }
Load();
}
void cObjectLoader::Launch() {
- if ( mThreaded )
+ if ( mThreaded ) {
cThread::Launch();
- else
+ } else {
Run();
+ }
}
void cObjectLoader::Start() {
@@ -70,8 +73,9 @@ void cObjectLoader::SetLoaded() {
if ( mLoadCbs.size() ) {
std::list::iterator it;
- for ( it = mLoadCbs.begin(); it != mLoadCbs.end(); it++ )
+ for ( it = mLoadCbs.begin(); it != mLoadCbs.end(); it++ ) {
(*it)( this );
+ }
mLoadCbs.clear();
}
diff --git a/src/system/cresourceloader.cpp b/src/system/cresourceloader.cpp
index 0c13defc9..03e5f823e 100644
--- a/src/system/cresourceloader.cpp
+++ b/src/system/cresourceloader.cpp
@@ -18,14 +18,10 @@ cResourceLoader::~cResourceLoader() {
void cResourceLoader::SetThreads() {
if ( THREADS_AUTO == mThreads ) {
mThreads = GetCPUCount();
- /**
- eeInt NumCpus = GetCPUCount() - 1;
- if ( NumCpus > 1 )
- mThreads = NumCpus;
- else
- mThreads = 1;
- */
+ if ( 1 == mThreads ) {
+ mThreaded = false;
+ }
}
}
@@ -38,8 +34,9 @@ Uint32 cResourceLoader::Count() const {
}
void cResourceLoader::Threaded( const bool& threaded ) {
- if ( !mLoading )
+ if ( !mLoading ) {
mThreaded = threaded;
+ }
}
void cResourceLoader::Add( cObjectLoader * Object ) {
@@ -99,18 +96,21 @@ void cResourceLoader::Load() {
Obj->Threaded( mThreaded );
if ( !Obj->IsLoaded() ) {
- if ( !Obj->IsLoading() )
+ if ( !Obj->IsLoading() ) {
Obj->Load();
+ }
- if ( Obj->IsLoading() )
+ if ( Obj->IsLoading() ) {
count++;
+ }
Obj->Update();
- if ( !Obj->IsLoaded() )
+ if ( !Obj->IsLoaded() ) {
AllLoaded = false;
- else
+ } else {
ObjsErase.push_back( Obj );
+ }
if ( mThreaded && mThreads == count ) {
AllLoaded = false;
@@ -126,8 +126,9 @@ void cResourceLoader::Load() {
mObjsLoaded.push_back( Obj );
}
- if ( AllLoaded )
+ if ( AllLoaded ) {
SetLoaded();
+ }
}
void cResourceLoader::Update() {
@@ -155,14 +156,15 @@ bool cResourceLoader::IsLoading() {
}
void cResourceLoader::SetLoaded() {
- mLoaded = true;
- mLoading = false;
+ mLoaded = true;
+ mLoading = false;
if ( mLoadCbs.size() ) {
std::list::iterator it;
- for ( it = mLoadCbs.begin(); it != mLoadCbs.end(); it++ )
+ for ( it = mLoadCbs.begin(); it != mLoadCbs.end(); it++ ) {
(*it)( this );
+ }
mLoadCbs.clear();
}
diff --git a/src/system/cthread.cpp b/src/system/cthread.cpp
index d19fa1878..5e89c8e78 100755
--- a/src/system/cthread.cpp
+++ b/src/system/cthread.cpp
@@ -25,7 +25,7 @@ void cThread::Launch() {
#if EE_PLATFORM == EE_PLATFORM_WIN
- mThread = reinterpret_cast( _beginthreadex( NULL, 0, &cThread::EntryPoint, this, 0, NULL ) );
+ mThread = reinterpret_cast( _beginthreadex( NULL, 0, &cThread::EntryPoint, this, 0, &mThreadId ) );
if ( !mThread )
mIsActive = false;
@@ -47,11 +47,15 @@ void cThread::Wait() {
if ( mIsActive ) { // Wait for the thread to finish, no timeout
#if EE_PLATFORM == EE_PLATFORM_WIN
+ eeASSERT( mThreadId != GetCurrentThreadId() ); // A thread cannot wait for itself!
+
WaitForSingleObject( mThread, INFINITE );
#elif defined( EE_PLATFORM_POSIX )
- pthread_join(mThread, NULL);
+ eeASSERT( pthread_equal( pthread_self(), mThread ) == 0 );
+
+ pthread_join( mThread, NULL );
#endif
diff --git a/src/system/cthread.hpp b/src/system/cthread.hpp
index 1656a69cb..c630edbd9 100755
--- a/src/system/cthread.hpp
+++ b/src/system/cthread.hpp
@@ -44,7 +44,8 @@ class EE_API cThread {
static unsigned int __stdcall EntryPoint(void* userData);
- HANDLE mThread;
+ HANDLE mThread;
+ unsigned int mThreadId;
#elif defined( EE_PLATFORM_POSIX )
diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp
index be3974325..1996a388a 100644
--- a/src/test/eetest.cpp
+++ b/src/test/eetest.cpp
@@ -28,6 +28,7 @@ void cEETest::Init() {
mCurDemo = 0xFFFFFF;
mMapEditor = NULL;
mETGEditor = NULL;
+ Mus = NULL;
MyPath = GetProcessPath();
@@ -43,6 +44,7 @@ void cEETest::Init() {
PartsNum = Ini.GetValueI( "EEPP", "ParticlesNum", 1000);
mUseShaders = Ini.GetValueB( "EEPP", "UseShaders", false );
mJoyEnabled = Ini.GetValueB( "EEPP", "JoystickEnabled", false );
+ mMusEnabled = Ini.GetValueB( "EEPP", "Music", false );
Int32 GLVersion = Ini.GetValueI( "EEPP", "GLVersion", 2 );
EEGL_version GLVer;
@@ -101,9 +103,8 @@ void cEETest::Init() {
Mus = eeNew( cMusic, () );
- if ( Mus->OpenFromPack( PAK, "music.ogg" ) ) {
- Mus->Loop(true);
- //Mus->Volume( 0.f );
+ if ( mMusEnabled && Mus->OpenFromPack( PAK, "music.ogg" ) ) {
+ Mus->Loop( true );
Mus->Play();
}
@@ -782,6 +783,7 @@ void cEETest::LoadTextures() {
mResLoad.Add( eeNew( cSoundLoader, ( &SndMng, "mysound", PAK, "sound.ogg" ) ) );
+ //mResLoad.Threaded( false );
mResLoad.Load( cb::Make1( this, &cEETest::OnTextureLoaded ) );
TN.resize(12);
@@ -1253,7 +1255,7 @@ void cEETest::Input() {
mWindow->FrameRateLimit( 10 );
- if ( Mus->State() == SOUND_PLAYING )
+ if ( mMusEnabled && Mus->State() == SOUND_PLAYING )
Mus->Pause();
} else {
@@ -1269,7 +1271,7 @@ void cEETest::Input() {
mWindow->FrameRateLimit( mLastFPSLimit );
- if ( Mus->State() == SOUND_PAUSED )
+ if ( mMusEnabled && Mus->State() == SOUND_PAUSED )
Mus->Play();
}
@@ -1495,25 +1497,6 @@ void cEETest::Process() {
End();
}
-void cEETest::End() {
- Wait();
-
- PhysicsDestroy();
-
- eeSAFE_DELETE( Mus );
- eeSAFE_DELETE( mTGL );
- eeSAFE_DELETE( mFBO );
- eeSAFE_DELETE( mVBO );
- eeSAFE_DELETE( mBoxSprite );
- eeSAFE_DELETE( mCircleSprite );
- eeSAFE_DELETE( PAK );
- eeSAFE_DELETE( PakTest );
-
- cLog::instance()->Save();
-
- cEngine::DestroySingleton();
-}
-
void cEETest::ParticlesCallback( cParticle * P, cParticleSystem * Me ) {
eeFloat x, y, radio;
eeVector2f MePos( Me->Position() );
@@ -1789,6 +1772,25 @@ void cEETest::PhysicsDestroy() {
mDemo[ mCurDemo ].destroy();
}
+void cEETest::End() {
+ Wait();
+
+ PhysicsDestroy();
+
+ eeSAFE_DELETE( Mus );
+ eeSAFE_DELETE( mTGL );
+ eeSAFE_DELETE( mFBO );
+ eeSAFE_DELETE( mVBO );
+ eeSAFE_DELETE( mBoxSprite );
+ eeSAFE_DELETE( mCircleSprite );
+ eeSAFE_DELETE( PAK );
+ eeSAFE_DELETE( PakTest );
+
+ cLog::instance()->Save();
+
+ cEngine::DestroySingleton();
+}
+
#if EE_PLATFORM == EE_PLATFORM_MACOSX
#ifdef EE_BACKEND_SDL_ACTIVE
#include
diff --git a/src/test/eetest.hpp b/src/test/eetest.hpp
index 1bdc8b4b2..72d2c523e 100644
--- a/src/test/eetest.hpp
+++ b/src/test/eetest.hpp
@@ -174,6 +174,7 @@ class cEETest : private cThread {
eeFloat mBlurFactor;
bool mUseShaders;
bool mJoyEnabled;
+ bool mMusEnabled;
Uint32 mLastFPSLimit;
bool mWasMinimized;
diff --git a/src/window/cengine.cpp b/src/window/cengine.cpp
index 4296e1267..37d40204a 100755
--- a/src/window/cengine.cpp
+++ b/src/window/cengine.cpp
@@ -66,8 +66,6 @@ cEngine::~cEngine() {
UI::cUIManager::DestroySingleton();
- Audio::cAudioListener::DestroySingleton();
-
Graphics::cGL::DestroySingleton();
cShaderProgramManager::DestroySingleton();
diff --git a/src/window/inputevent.hpp b/src/window/inputevent.hpp
index 20465d92b..45e0eaa28 100644
--- a/src/window/inputevent.hpp
+++ b/src/window/inputevent.hpp
@@ -6,9 +6,9 @@ namespace EE { namespace Window {
class InputEvent {
public:
inline InputEvent() {}
-
+
inline InputEvent( Uint32 type ) : Type( type ) {}
-
+
struct KeySym {
Uint32 sym; /** virtual keysym */
Uint32 mod; /** current key modifiers */
@@ -32,9 +32,9 @@ class InputEvent {
struct MouseMotionEvent {
Uint8 which; /** The mouse device index */
Uint8 state; /** The current button state */
- Uint16 x, y; /** The X/Y coordinates of the mouse */
- Int16 xrel; /** The relative motion in the X direction */
- Int16 yrel; /** The relative motion in the Y direction */
+ Int16 x, y; /** The X/Y coordinates of the mouse */
+ Int16 xrel; /** The relative motion in the X direction */
+ Int16 yrel; /** The relative motion in the Y direction */
};
/** Mouse button event structure */
@@ -42,7 +42,7 @@ class InputEvent {
Uint8 which; /** The mouse device index */
Uint8 button; /** The mouse button index */
Uint8 state; /** EE_PRESSED or EE_RELEASED */
- Uint16 x, y; /** The X/Y coordinates of the mouse at press time */
+ Int16 x, y; /** The X/Y coordinates of the mouse at press time */
};
/** Joystick axis motion event structure */
@@ -109,7 +109,7 @@ class InputEvent {
struct SysWMEvent {
SysWMmsg * msg;
};
-
+
enum EventType {
NoEvent = 0,
Active,
@@ -130,7 +130,7 @@ class InputEvent {
EventUser,
EventCount = 32
};
-
+
/** Event Type */
Uint32 Type;