[Scummvm-cvs-logs] CVS: scummvm/scumm imuse.h,1.21,1.22 imuse.cpp,2.6,2.7

Jamieson Christian jamieson630 at users.sourceforge.net
Sat Dec 21 13:10:07 CET 2002


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1:/tmp/cvs-serv31178/scummvm/scumm

Modified Files:
	imuse.h imuse.cpp 
Log Message:
IMuseMonitor functionality now built into IMuse itself.
IMuseInternal no longer derives from IMuse.
This eliminates a couple layers of indirection and speeds things up.
Miscellaneous source cleanup.

Index: imuse.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- imuse.h	11 Dec 2002 01:25:15 -0000	1.21
+++ imuse.h	21 Dec 2002 21:09:35 -0000	1.22
@@ -31,40 +31,42 @@
 class SoundMixer;
 
 class IMuse {
+private:
+	OSystem *_system;
+	IMuseInternal *_target;
+	void *_mutex;
+
+	IMuse (OSystem *system, IMuseInternal *target);
+	void in();
+	void out();
+
 public:
+	~IMuse();
+
 	enum {
 		PROP_TEMPO_BASE = 1,
 	};
 
-	IMuse() { }
-	virtual ~IMuse() { };
-
-	virtual void on_timer() = 0; // For the MacOS 9 port only
-	virtual void pause(bool paused) = 0;
-	virtual int save_or_load(Serializer *ser, Scumm *scumm) = 0;
-	virtual int set_music_volume(uint vol) = 0;
-	virtual int get_music_volume() = 0;
-	virtual int set_master_volume(uint vol) = 0;
-	virtual int get_master_volume() = 0;
-	virtual bool start_sound(int sound) = 0;
-	virtual int stop_sound(int sound) = 0;
-	virtual int stop_all_sounds() = 0;
-	virtual int get_sound_status(int sound) = 0;
-	virtual bool get_sound_active(int sound) = 0;
-	virtual int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h) = 0;
-	virtual int clear_queue() = 0;
-	virtual void setBase(byte **base) = 0;
-	virtual uint32 property(int prop, uint32 value) = 0;
+	void on_timer();
+	void pause(bool paused);
+	int save_or_load(Serializer *ser, Scumm *scumm);
+	int set_music_volume(uint vol);
+	int get_music_volume();
+	int set_master_volume(uint vol);
+	int get_master_volume();
+	bool start_sound(int sound);
+	int stop_sound(int sound);
+	int stop_all_sounds();
+	int get_sound_status(int sound);
+	bool get_sound_active(int sound);
+	int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h);
+	int clear_queue();
+	void setBase(byte **base);
+	uint32 property(int prop, uint32 value);
 
 	// Factory methods
 	static IMuse *create(OSystem *syst, MidiDriver *midi, SoundMixer *mixer);
-
-	static IMuse *create_adlib(OSystem *syst, SoundMixer *mixer) {
-		return create(syst, NULL, mixer);
-	}
-	static IMuse *create_midi(OSystem *syst, MidiDriver *midi) {
-		return create(syst, midi, NULL);
-	}
+	static IMuse *create_midi(OSystem *syst, MidiDriver *midi) { return create(syst, midi, NULL); }
 };
 
 #define MAX_DIGITAL_CHANNELS 8

Index: imuse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/imuse.cpp,v
retrieving revision 2.6
retrieving revision 2.7
diff -u -d -r2.6 -r2.7
--- imuse.cpp	21 Dec 2002 20:10:47 -0000	2.6
+++ imuse.cpp	21 Dec 2002 21:09:36 -0000	2.7
@@ -50,40 +50,6 @@
 // they will only be used from this file, so it will reduce
 // compile time.
 
-// IMuseMonitor serves as a front-end to IMuseInternal and
-// ensures that only one thread accesses the object at a time.
-// This is necessary to prevent scripts and the MIDI parser
-// from yanking objects out from underneath each other.
-class IMuseMonitor : public IMuse {
-private:
-	OSystem *_system;
-	IMuse *_target;
-	void *_mutex;
-
-	void in() { _system->lock_mutex (_mutex); }
-	void out() { _system->unlock_mutex (_mutex); }
-public:
-	IMuseMonitor (OSystem *system, IMuse *target) : _system (system), _target (target) { _mutex = system->create_mutex(); }
-	virtual ~IMuseMonitor() { _system->delete_mutex (_mutex); };
-
-	void on_timer() { in(); _target->on_timer(); out(); }
-	void pause(bool paused) { in(); _target->pause (paused); out(); }
-	int save_or_load(Serializer *ser, Scumm *scumm) { in(); int ret = _target->save_or_load (ser, scumm); out(); return ret; }
-	int set_music_volume(uint vol) { in(); int ret = _target->set_music_volume (vol); out(); return ret; }
-	int get_music_volume() { in(); int ret = _target->get_music_volume(); out(); return ret; }
-	int set_master_volume(uint vol) { in(); int ret = _target->set_master_volume (vol); out(); return ret; }
-	int get_master_volume() { in(); int ret = _target->get_master_volume(); out(); return ret; }
-	bool start_sound(int sound) { in(); bool ret = _target->start_sound (sound); out(); return ret; }
-	int stop_sound(int sound) { in(); int ret = _target->stop_sound (sound); out(); return ret; }
-	int stop_all_sounds() { in(); int ret = _target->stop_all_sounds(); out(); return ret; }
-	int get_sound_status(int sound) { in(); int ret = _target->get_sound_status (sound); out(); return ret; }
-	bool get_sound_active(int sound) { in(); bool ret = _target->get_sound_active (sound); out(); return ret; }
-	int32 do_command(int a, int b, int c, int d, int e, int f, int g, int h) { in(); int32 ret = _target->do_command (a,b,c,d,e,f,g,h); out(); return ret; }
-	int clear_queue() { in(); int ret = _target->clear_queue(); out(); return ret; }
-	void setBase(byte **base) { in(); _target->setBase (base); out(); }
-	uint32 property(int prop, uint32 value) { in(); uint32 ret = _target->property (prop, value); out(); return ret; }
-};
-
 class IMuseDriver;
 struct Part;
 
@@ -385,8 +351,9 @@
 // WARNING: This is the internal variant of the IMUSE class.
 // imuse.h contains a public version of the same class.
 // the public version, only contains a set of methods.
-class IMuseInternal : public IMuse {
+class IMuseInternal {
 	friend struct Player;
+
 private:
 	IMuseDriver * _driver;
 
@@ -396,7 +363,6 @@
 	byte _hardware_type;
 
 private:
-
 	bool _paused;
 	bool _active_volume_faders;
 	bool _initialized;
@@ -413,11 +379,11 @@
 
 	byte _queue_marker;
 	byte _queue_cleared;
-	byte _master_volume;					// Master volume. 0-255
-	byte _music_volume;						// Global music volume. 0-255
+	byte _master_volume; // Master volume. 0-255
+	byte _music_volume; // Global music volume. 0-255
 
 	uint16 _trigger_count;
-	ImTrigger _snm_triggers[16];	// Sam & Max triggers
+	ImTrigger _snm_triggers[16]; // Sam & Max triggers
 	uint16 _snm_trigger_index;
 
 	uint16 _channel_volume[8];
@@ -3778,15 +3744,49 @@
 
 
 
+////////////////////////////////////////////////////////////
+//
+// IMuse implementation
+//
+// IMuse actually serves as a concurency monitor front-end
+// to IMuseInternal and ensures that only one thread
+// accesses the object at a time. This is necessary to
+// prevent scripts and the MIDI parser from yanking objects
+// out from underneath each other.
+//
+////////////////////////////////////////////////////////////
+
+IMuse::IMuse (OSystem *system, IMuseInternal *target) : _system (system), _target (target) { _mutex = system->create_mutex(); }
+IMuse::~IMuse() { if (_mutex) _system->delete_mutex (_mutex); if (_target) delete _target; }
+inline void IMuse::in() { _system->lock_mutex (_mutex); }
+inline void IMuse::out() { _system->unlock_mutex (_mutex); }
+
+void IMuse::on_timer() { in(); _target->on_timer(); out(); }
+void IMuse::pause(bool paused) { in(); _target->pause (paused); out(); }
+int IMuse::save_or_load(Serializer *ser, Scumm *scumm) { in(); int ret = _target->save_or_load (ser, scumm); out(); return ret; }
+int IMuse::set_music_volume(uint vol) { in(); int ret = _target->set_music_volume (vol); out(); return ret; }
+int IMuse::get_music_volume() { in(); int ret = _target->get_music_volume(); out(); return ret; }
+int IMuse::set_master_volume(uint vol) { in(); int ret = _target->set_master_volume (vol); out(); return ret; }
+int IMuse::get_master_volume() { in(); int ret = _target->get_master_volume(); out(); return ret; }
+bool IMuse::start_sound(int sound) { in(); bool ret = _target->start_sound (sound); out(); return ret; }
+int IMuse::stop_sound(int sound) { in(); int ret = _target->stop_sound (sound); out(); return ret; }
+int IMuse::stop_all_sounds() { in(); int ret = _target->stop_all_sounds(); out(); return ret; }
+int IMuse::get_sound_status(int sound) { in(); int ret = _target->get_sound_status (sound); out(); return ret; }
+bool IMuse::get_sound_active(int sound) { in(); bool ret = _target->get_sound_active (sound); out(); return ret; }
+int32 IMuse::do_command(int a, int b, int c, int d, int e, int f, int g, int h) { in(); int32 ret = _target->do_command (a,b,c,d,e,f,g,h); out(); return ret; }
+int IMuse::clear_queue() { in(); int ret = _target->clear_queue(); out(); return ret; }
+void IMuse::setBase(byte **base) { in(); _target->setBase (base); out(); }
+uint32 IMuse::property(int prop, uint32 value) { in(); uint32 ret = _target->property (prop, value); out(); return ret; }
+
 // The IMuse::create method provides a front-end factory
 // for creating IMuseInternal without exposing that class
 // to the client.
-IMuse *IMuse::create(OSystem *syst, MidiDriver *midi, SoundMixer *mixer)
+IMuse *IMuse::create (OSystem *syst, MidiDriver *midi, SoundMixer *mixer)
 {
-	IMuse *engine = (IMuse *) IMuseInternal::create (syst, midi, mixer);
+	IMuseInternal *engine = IMuseInternal::create (syst, midi, mixer);
 	if (midi)
 		midi->property (MidiDriver::PROP_SMALLHEADER, (g_scumm->_features & GF_SMALL_HEADER) ? 1 : 0);
-	return (IMuse *) new IMuseMonitor (syst, engine);
+	return new IMuse (syst, engine);
 }
 
 





More information about the Scummvm-git-logs mailing list