From: <and...@us...> - 2008-01-11 00:09:04
|
Revision: 538 http://python-ogre.svn.sourceforge.net/python-ogre/?rev=538&view=rev Author: andy_miller Date: 2008-01-10 16:08:48 -0800 (Thu, 10 Jan 2008) Log Message: ----------- Updates to the OgreAL library source Modified Paths: -------------- trunk/python-ogre/ThirdParty/ogreal/OgreALPrereqs.h trunk/python-ogre/ThirdParty/ogreal/OgreALSound.cpp trunk/python-ogre/ThirdParty/ogreal/OgreALSound.h trunk/python-ogre/ThirdParty/ogreal/OgreALSoundManager.cpp trunk/python-ogre/ThirdParty/ogreal/OgreALSoundManager.h Modified: trunk/python-ogre/ThirdParty/ogreal/OgreALPrereqs.h =================================================================== --- trunk/python-ogre/ThirdParty/ogreal/OgreALPrereqs.h 2008-01-11 00:08:11 UTC (rev 537) +++ trunk/python-ogre/ThirdParty/ogreal/OgreALPrereqs.h 2008-01-11 00:08:48 UTC (rev 538) @@ -42,16 +42,8 @@ #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 # include "al.h" # include "alc.h" - # include "xram.h" - # if OGRE_COMPILER == OGRE_COMPILER_MSVC -// # ifdef OGREAL_EXPORT -// # define OgreAL_Export __declspec(dllexport) -// # else -// # define OgreAL_Export __declspec(dllimport) -// # endif -// # else -// # define OgreAL_Export - # endif + # include "xram.h" + # define OgreAL_Export #elif OGRE_COMPILER == OGRE_COMPILER_GNUC # include "AL/al.h" # include "AL/alc.h" Modified: trunk/python-ogre/ThirdParty/ogreal/OgreALSound.cpp =================================================================== --- trunk/python-ogre/ThirdParty/ogreal/OgreALSound.cpp 2008-01-11 00:08:11 UTC (rev 537) +++ trunk/python-ogre/ThirdParty/ogreal/OgreALSound.cpp 2008-01-11 00:08:48 UTC (rev 538) @@ -59,6 +59,8 @@ mGain(1.0), mMaxGain(1.0), mMinGain(0.0), + mFadeMode(FADE_NONE), + mFadeTime(0.0), mMaxDistance(3400.0), mRolloffFactor(1.0), mReferenceDistance(150.0), @@ -96,6 +98,8 @@ mPitch(1.0), mGain(1.0), mMaxGain(1.0), mMinGain(0.0), + mFadeMode(FADE_NONE), + mFadeTime(0.0), mMaxDistance(3400.0), mRolloffFactor(1.0), mReferenceDistance(150.0), @@ -133,6 +137,8 @@ mLoop(loop?AL_TRUE:AL_FALSE), mPitch(1.0), mGain(1.0), mMaxGain(1.0), mMinGain(0.0), + mFadeMode(FADE_NONE), + mFadeTime(0.0), mMaxDistance(3400.0), mRolloffFactor(1.0), mReferenceDistance(150.0), @@ -325,6 +331,51 @@ return (state == AL_INITIAL); } + bool Sound::fadeIn(Ogre::Real fadeTime) + { + // Don't interrupt a current fade + if(!isPlaying() && mFadeMode == FADE_NONE) + { + // This won't work as expected when the sound is attached to a node, + // so disallow it. + if(mParentNode) + { + Ogre::LogManager::getSingleton().logMessage("Cannot fade a Sound that is attached to a node"); + return false; + } + + mFadeMode = FADE_IN; + mFadeTime = fadeTime; + mRunning = 0.0; + // Start at min gain.. + setGain(mMinGain); + // ..and play + return play(); + } + return false; + } + + bool Sound::fadeOut(Ogre::Real fadeTime) + { + // Don't interrupt a current fade + if(isPlaying() && mFadeMode == FADE_NONE) + { + // This won't work as expected when the sound is attached to a node, + // so disallow it. + if(mParentNode) + { + Ogre::LogManager::getSingleton().logMessage("Cannot fade a Sound that is attached to a node"); + return false; + } + + mFadeMode = FADE_OUT; + mFadeTime = fadeTime; + mRunning = 0.0; + return true; + } + return false; + } + void Sound::setPitch(Ogre::Real pitch) { if(pitch <= 0) return; @@ -577,6 +628,41 @@ mLocalTransformDirty = false; } + void Sound::_updateFading() + { + if(mFadeMode != FADE_NONE) + { + mRunning += SoundManager::getSingletonPtr()->_getLastDeltaTime(); + // Calculate volume between min and max Gain over fade time + Ogre::Real delta = mMaxGain - mMinGain; + Ogre::Real gain; + + if(mFadeMode == FADE_IN) + { + gain = mMinGain + (delta * mRunning / mFadeTime); + // Clamp & stop if needed + if (gain > mMaxGain) + { + gain = mMaxGain; + mFadeMode = FADE_NONE; + } + } + else if(mFadeMode == FADE_OUT) + { + gain = mMaxGain - (delta * mRunning / mFadeTime); + // Clamp & stop if needed + if(gain < mMinGain) + { + gain = mMinGain; + mFadeMode = FADE_NONE; + } + } + + // Set the adjusted gain + setGain(gain); + } + } + bool Sound::updateSound() { _update(); @@ -588,6 +674,9 @@ alSource3f(mSource, AL_DIRECTION, mDerivedDirection.x, mDerivedDirection.y, mDerivedDirection.z); CheckError(alGetError(), "Failed to set Direction"); + + // Fading + _updateFading(); } return true; Modified: trunk/python-ogre/ThirdParty/ogreal/OgreALSound.h =================================================================== --- trunk/python-ogre/ThirdParty/ogreal/OgreALSound.h 2008-01-11 00:08:11 UTC (rev 537) +++ trunk/python-ogre/ThirdParty/ogreal/OgreALSound.h 2008-01-11 00:08:48 UTC (rev 538) @@ -87,6 +87,10 @@ virtual bool isStopped() const; /** Returns true if the source does not have a state yet, otherwise false */ virtual bool isInitial() const; + /** Starts playing the song while fading in.*/ + bool fadeIn(Ogre::Real fadeTime); + /** Fades out, but keeps playing at volume 0, so it can be faded in again.*/ + bool fadeOut(Ogre::Real fadeTime); /** * Sets the pitch multiplier. @@ -376,6 +380,18 @@ private: void _update() const; + void _updateFading(); + + enum FadeMode + { + FADE_NONE, + FADE_IN, + FADE_OUT + }; + + FadeMode mFadeMode; + Ogre::Real mFadeTime; + Ogre::Real mRunning; }; /** Factory object for creating sounds */ Modified: trunk/python-ogre/ThirdParty/ogreal/OgreALSoundManager.cpp =================================================================== --- trunk/python-ogre/ThirdParty/ogreal/OgreALSoundManager.cpp 2008-01-11 00:08:11 UTC (rev 537) +++ trunk/python-ogre/ThirdParty/ogreal/OgreALSoundManager.cpp 2008-01-11 00:08:48 UTC (rev 538) @@ -64,7 +64,8 @@ mSpeedOfSound(343.3), mMaxNumSources(0), mMajorVersion(0), - mMinorVersion(0) + mMinorVersion(0), + mLastDeltaTime(0.0) { Ogre::LogManager::getSingleton().logMessage("*-*-* OgreAL Initialization"); @@ -385,6 +386,8 @@ bool SoundManager::frameStarted(const Ogre::FrameEvent& evt) { + // Do this before any fading gets updated + mLastDeltaTime = evt.timeSinceLastFrame; updateSounds(); return true; } Modified: trunk/python-ogre/ThirdParty/ogreal/OgreALSoundManager.h =================================================================== --- trunk/python-ogre/ThirdParty/ogreal/OgreALSoundManager.h 2008-01-11 00:08:11 UTC (rev 537) +++ trunk/python-ogre/ThirdParty/ogreal/OgreALSoundManager.h 2008-01-11 00:08:48 UTC (rev 538) @@ -181,8 +181,11 @@ void _removeBufferRef(const Ogre::String& bufferName); /** Adds a BufferRef to the BufferMap to be used later */ void _addBufferRef(const Ogre::String& bufferName, BufferRef buffer); - + /** Used by the fading: returns the time since last frame. */ + Ogre::Real _getLastDeltaTime() const {return mLastDeltaTime;} + /** Requests a dynamically allocated Source. */ SourceRef _requestSource(Sound *sound); + /** Releases a dynamically allocated Source. */ SourceRef _releaseSource(Sound *sound); static const Ogre::String FILE_TYPE; @@ -243,6 +246,8 @@ ALCcontext *mContext; ALCdevice *mDevice; + Ogre::Real mLastDeltaTime; + // Mutex so we can protect against corruption OGREAL_AUTO_MUTEX This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |