Просмотр исходного кода

Added play on start for audio sources
Fixed invalid documentation

BearishSun 9 лет назад
Родитель
Сommit
584feaa51c

+ 1 - 1
Documentation/Manuals/Native/resources.md

@@ -53,7 +53,7 @@ Once a resource is loaded it will stay loaded until all references (handles) to
 
 If you wish to keep a handle to a resource that doesn't keep it loaded, you can use @ref BansheeEngine::TResourceHandle<T, true> "WeakResourceHandle<T>". You retrieve such a handle by calling @ref BansheeEngine::TResourceHandle<T, WeakHandle>::getWeak "HResource::getWeak" method on a normal handle. You can convert a weak handle into a normal handle by calling @ref BansheeEngine::TResourceHandle<T, WeakHandle>::lock "HResource::lock". Before doing so you should verify that the resource is still loaded.
 
-Weak handles can also be used for referencing resources for serialization/deserialization, same as normal handles can. However a weak handle will never force the referenced resource to load, even if `loadDependencies` parameter is set to true when loading. You must call @ref BansheeEngine::Resources::load(const WeakResourceHandle<T>&, bool, bool) "Resource::load" to manually load such a resource.
+Weak handles can also be used for referencing resources for serialization/deserialization, same as normal handles can. However a weak handle will never force the referenced resource to load, even if `loadDependencies` parameter is set to true when loading. You must call @ref BansheeEngine::Resources::load(const WeakResourceHandle<T>&, ResourceLoadFlags) "Resource::load" to manually load such a resource.
 
 You can also force a resource to stay loaded, even after all the handles go out of scope. You do it by setting `keepInternalReference` of @ref BansheeEngine::Resources::load "Resource::load" or @ref BansheeEngine::Resources::loadAsync "Resource::loadAsync" to true. In order to free such a resource you should call @ref BansheeEngine::Resources::release "Resources::release". Be aware that each call to @ref BansheeEngine::Resources::load "Resource::load" or @ref BansheeEngine::Resources::loadAsync "Resource::loadAsync" with this parameter enabled will require a separate @ref BansheeEngine::Resources::release "Resources::release" call. @ref BansheeEngine::Resources::release "Resources::release" will not release the resource immediately if there are still active handles to it, it will merely remove the internal reference so the resource can be freed when the handles go out of scope.
 

+ 1 - 1
Source/BansheeCore/Include/BsAudioUtility.h

@@ -36,7 +36,7 @@ namespace BansheeEngine
 		 * @param[in]	inBitDepth	Size of a single sample in the @p input array, in bits.
 		 * @param[out]	output		Pre-allocated buffer to store the output samples in. Total size of the buffer should be
 		 *							@p numSamples * @p outBitDepth / 8.
-		 * @param[in]	inBitDepth	Size of a single sample in the @p output array, in bits.
+		 * @param[in]	outBitDepth	Size of a single sample in the @p output array, in bits.
 		 * @param[in]	numSamples	Total number of samples to process.
 		 */
 		static void convertBitDepth(const UINT8* input, UINT32 inBitDepth, UINT8* output, UINT32 outBitDepth, UINT32 numSamples);

+ 7 - 0
Source/BansheeCore/Include/BsCAudioSource.h

@@ -71,6 +71,12 @@ namespace BansheeEngine
 		/** @copydoc AudioSource::getTime */
 		float getTime() const;
 
+		/** Sets whether playback should start as soon as the component is enabled. */
+		void setPlayOnStart(bool enable) { mPlayOnStart = enable; }
+
+		/** Determines should playback start as soon as the component is enabled. */
+		bool getPlayOnStart() const { return mPlayOnStart; }
+
 		/** @copydoc AudioSource::play */
 		void play();
 
@@ -141,6 +147,7 @@ namespace BansheeEngine
 		UINT32 mPriority;
 		float mMinDistance;
 		float mAttenuation;
+		bool mPlayOnStart;
 
 		/************************************************************************/
 		/* 								RTTI		                     		*/

+ 1 - 0
Source/BansheeCore/Include/BsCAudioSourceRTTI.h

@@ -24,6 +24,7 @@ namespace BansheeEngine
 			BS_RTTI_MEMBER_PLAIN(mPriority, 4)
 			BS_RTTI_MEMBER_PLAIN(mMinDistance, 5)
 			BS_RTTI_MEMBER_PLAIN(mAttenuation, 6)
+			BS_RTTI_MEMBER_PLAIN(mPlayOnStart, 7)
 		BS_END_RTTI_MEMBERS
 	public:
 		CAudioSourceRTTI()

+ 6 - 6
Source/BansheeCore/Include/BsResources.h

@@ -88,7 +88,7 @@ namespace BansheeEngine
 		 *			
 		 * @param[in]	filePath	File path to the resource to load. This can be absolute or relative to the working 
 		 *							folder.
-		 * @param[in]	flags		Flags used to control the load process.
+		 * @param[in]	loadFlags	Flags used to control the load process.
 		 *			
 		 * @see		release(ResourceHandleBase&), unloadAllUnused()
 		 */
@@ -120,7 +120,7 @@ namespace BansheeEngine
 		 * done.
 		 *
 		 * @param[in]	filePath	Full pathname of the file.
-		 * @param[in]	flags		Flags used to control the load process.
+		 * @param[in]	loadFlags	Flags used to control the load process.
 		 *
 		 * @note	
 		 * You can use returned invalid handle in many engine systems as the engine will check for handle validity before 
@@ -140,10 +140,10 @@ namespace BansheeEngine
 		/**
 		 * Loads the resource with the given UUID. Returns an empty handle if resource can't be loaded.
 		 *
-		 * @param[in]	uuid	UUID of the resource to load.
-		 * @param[in]	async	If true resource will be loaded asynchronously. Handle to non-loaded resource will be
-		 *						returned immediately while loading will continue in the background.		
-		 * @param[in]	flags	Flags used to control the load process.
+		 * @param[in]	uuid		UUID of the resource to load.
+		 * @param[in]	async		If true resource will be loaded asynchronously. Handle to non-loaded resource will be
+		 *							returned immediately while loading will continue in the background.		
+		 * @param[in]	loadFlags	Flags used to control the load process.
 		 *													
 		 * @see		load(const Path&, bool)
 		 */

+ 4 - 0
Source/BansheeCore/Source/BsCAudioSource.cpp

@@ -11,6 +11,7 @@ namespace BansheeEngine
 {
 	CAudioSource::CAudioSource(const HSceneObject& parent)
 		: Component(parent), mVolume(1.0f), mPitch(1.0f), mLoop(false), mPriority(0), mMinDistance(1.0f), mAttenuation(1.0f)
+		, mPlayOnStart(true)
 	{
 		setName("AudioSource");
 
@@ -152,6 +153,9 @@ namespace BansheeEngine
 	void CAudioSource::onEnabled()
 	{
 		restoreInternal();
+
+		if (mPlayOnStart)
+			play();
 	}
 
 	void CAudioSource::onTransformChanged(TransformChangedFlags flags)

+ 1 - 0
Source/BansheeUtility/Include/BsFileSerializer.h

@@ -24,6 +24,7 @@ namespace BansheeEngine
 		 * Parses the provided object, serializes all of its data as specified by its RTTIType and saves the serialized 
 		 * data to the provided file location.
 		 *
+		 * @param[in]	object		Object to encode.
 		 * @param[in]	params		Optional parameters to be passed to the serialization callbacks on the objects being
 		 *							serialized.
 		 */

+ 2 - 0
Source/BansheeUtility/Include/BsMemorySerializer.h

@@ -45,6 +45,8 @@ namespace BansheeEngine
 		/** 
 		 * Deserializes an IReflectable object by reading the binary data from the provided memory location. 
 		 *
+		 * @param[in]	buffer		Previously allocated buffer to store the data in.
+		 * @param[in]	bufferSize	Size of the @p buffer in bytes.
 		 * @param[in]	params		Optional parameters to be passed to the serialization callbacks on the objects being
 		 *							serialized.
 		 */

+ 13 - 0
Source/MBansheeEngine/Audio/AudioSource.cs

@@ -190,6 +190,15 @@ namespace BansheeEngine
             }
         }
 
+        /// <summary>
+        /// Determines if the playback of the audio clip should start as soon as the component is initialized.
+        /// </summary>
+        public bool PlayOnStart
+        {
+            get { return serializableData.playOnStart; }
+            set { serializableData.playOnStart = value; }
+        }
+
         /// <summary>
         /// Returns the current state of the audio playback (playing/paused/stopped).
         /// </summary>
@@ -256,6 +265,9 @@ namespace BansheeEngine
         private void OnEnable()
         {
             RestoreNative();
+
+            if (serializableData.playOnStart)
+                Play();
         }
 
         private void OnDisable()
@@ -320,6 +332,7 @@ namespace BansheeEngine
             public uint priority = 0;
             public float minDistance = 1.0f;
             public float attenuation = 1.0f;
+            public bool playOnStart = true;
         }
     }