Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F127074
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/sound.cpp b/util/sound.cpp
index c8cfb0a7..5a2e4cff 100644
--- a/util/sound.cpp
+++ b/util/sound.cpp
@@ -1,50 +1,72 @@
#include <allegro.h>
#include <string>
#include "sound.h"
#include "load_exception.h"
using namespace std;
+Sound::Sound():
+my_sound( NULL ),
+own( NULL ){
+}
+
Sound::Sound( const string & path ) throw( LoadException ):
my_sound( NULL ),
own( NULL ){
my_sound = load_sample( path.c_str() );
if ( !my_sound ){
string xf( "Could not load " );
xf += path;
throw LoadException( xf );
}
own = new int;
*own = 1;
-
}
Sound::Sound( const Sound & copy ):
my_sound( NULL ),
own( NULL ){
own = copy.own;
if ( own ){
*own += 1;
}
my_sound = copy.my_sound;
}
-void Sound::play(){
- if ( my_sound )
- play_sample( my_sound, 255, 128, 1000, false );
-}
-
-Sound::~Sound(){
+void Sound::destroy(){
if ( own ){
*own -= 1;
-
if ( *own == 0 ){
delete own;
destroy_sample( my_sound );
+ own = NULL;
}
}
}
+
+Sound & Sound::operator=( const Sound & rhs ){
+ if ( own ){
+ destroy();
+ }
+ own = rhs.own;
+ if ( own ){
+ *own += 1;
+ }
+ my_sound = rhs.my_sound;
+
+ return *this;
+}
+
+void Sound::play(){
+ if ( my_sound ){
+ play_sample( my_sound, 255, 128, 1000, false );
+ }
+}
+
+Sound::~Sound(){
+ destroy();
+}
diff --git a/util/sound.h b/util/sound.h
index b488fd5d..38ad78d9 100644
--- a/util/sound.h
+++ b/util/sound.h
@@ -1,28 +1,35 @@
#ifndef _pain_sound_h
#define _pain_sound_h
#include <string>
#include "load_exception.h"
struct SAMPLE;
using namespace std;
/* a sound! */
class Sound{
public:
+ Sound();
Sound( const string & path ) throw( LoadException );
Sound( const Sound & copy );
+ Sound & operator=( const Sound & rhs );
+
void play();
virtual ~Sound();
protected:
+ void destroy();
+
SAMPLE * my_sound;
+
+ /* reference counting */
int * own;
};
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 2:19 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69430
Default Alt Text
(1 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline