فهرست منبع

Merge pull request #1242 from marauder2k9-torque/SFXResource-fix

SFXResource was unnecessarily creating SFXFileStreams
Brian Roberts 1 سال پیش
والد
کامیت
4ee2a4a2b3
2فایلهای تغییر یافته به همراه12 افزوده شده و 9 حذف شده
  1. 5 4
      Engine/source/sfx/sfxResource.cpp
  2. 7 5
      Engine/source/sfx/sfxResource.h

+ 5 - 4
Engine/source/sfx/sfxResource.cpp

@@ -64,10 +64,11 @@ Resource< SFXResource > SFXResource::load( String filename )
    return ResourceManager::get().load( filename );
 }
 
-SFXResource::SFXResource( String fileName, SFXStream *stream )
+SFXResource::SFXResource( String fileName, const ThreadSafeRef<SFXStream>& stream)
    : mFileName( fileName ),
      mFormat( stream->getFormat() ),
-     mDuration( stream->getDuration() )
+     mDuration( stream->getDuration() ),
+     mStream(stream)
 {
 }
 
@@ -76,7 +77,7 @@ bool SFXResource::exists( String filename )
    return SFXFileStream::exists( filename );
 }
 
-SFXStream* SFXResource::openStream()
+ThreadSafeRef<SFXStream> SFXResource::openStream()
 {
-   return SFXFileStream::create( mFileName );
+   return mStream;
 }

+ 7 - 5
Engine/source/sfx/sfxResource.h

@@ -30,9 +30,9 @@
    #include "core/resource.h"
 #endif
 
-
-class SFXStream;
-
+#ifndef _SFXSTREAM_H_
+#include "sfx/sfxStream.h"
+#endif
 
 /// This is the base class for all sound file resources including
 /// streamed sound files.  It acts much like an always in-core
@@ -68,10 +68,12 @@ class SFXResource
 
       /// The length of the sample in milliseconds.
       U32 mDuration;
+
+      ThreadSafeRef<SFXStream> mStream;
       
       /// Construct a resource instance for the given file.  Format and duration
       /// are read from the given stream.
-      SFXResource( String fileName, SFXStream* stream );
+      SFXResource( String fileName, const ThreadSafeRef<SFXStream>& stream);
       
    public:
 
@@ -103,7 +105,7 @@ class SFXResource
       const SFXFormat& getFormat() const { return mFormat; }
 
       /// Open a stream for reading the resource's sample data.
-      SFXStream* openStream();
+      ThreadSafeRef<SFXStream> openStream();
 
       // Internal.
       struct _NewHelper;