[Scummvm-cvs-logs] SF.net SVN: scummvm:[39158] scummvm/trunk/engines/sci

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Mar 6 18:53:11 CET 2009


Revision: 39158
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39158&view=rev
Author:   fingolfin
Date:     2009-03-06 17:53:11 +0000 (Fri, 06 Mar 2009)

Log Message:
-----------
SCI: Continued C++ification of SongIterator code

Modified Paths:
--------------
    scummvm/trunk/engines/sci/engine/scriptdebug.cpp
    scummvm/trunk/engines/sci/sfx/core.cpp
    scummvm/trunk/engines/sci/sfx/iterator.cpp
    scummvm/trunk/engines/sci/sfx/iterator.h
    scummvm/trunk/engines/sci/sfx/iterator_internal.h
    scummvm/trunk/engines/sci/sfx/player/polled.cpp
    scummvm/trunk/engines/sci/sfx/player/realtime.cpp
    scummvm/trunk/engines/sci/sfx/songlib.cpp

Modified: scummvm/trunk/engines/sci/engine/scriptdebug.cpp
===================================================================
--- scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-06 17:39:46 UTC (rev 39157)
+++ scummvm/trunk/engines/sci/engine/scriptdebug.cpp	2009-03-06 17:53:11 UTC (rev 39158)
@@ -2436,7 +2436,7 @@
 	} else
 		sciprintf("Valid song, but not a sample.\n");
 
-	songit_free(songit);
+	delete songit;
 
 	return 0;
 }

Modified: scummvm/trunk/engines/sci/sfx/core.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/core.cpp	2009-03-06 17:39:46 UTC (rev 39157)
+++ scummvm/trunk/engines/sci/sfx/core.cpp	2009-03-06 17:53:11 UTC (rev 39158)
@@ -576,7 +576,7 @@
 		        || song->status == SOUND_STATUS_SUSPENDED) {
 			warning("Unexpected (error): Song %ld still playing/suspended (%d)",
 			        handle, song->status);
-			songit_free(it);
+			delete it;
 			return -1;
 		} else
 			song_lib_remove(self->songlib, handle); /* No duplicates */

Modified: scummvm/trunk/engines/sci/sfx/iterator.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator.cpp	2009-03-06 17:39:46 UTC (rev 39157)
+++ scummvm/trunk/engines/sci/sfx/iterator.cpp	2009-03-06 17:53:11 UTC (rev 39158)
@@ -64,6 +64,15 @@
 		return NULL;
 }
 
+BaseSongIterator::~BaseSongIterator() {
+#ifdef DEBUG_VERBOSE
+	fprintf(stderr, "** FREEING it %p: data at %p\n", this, data);
+#endif
+	if (data)
+		sci_refcount_decref(data);
+	data = NULL;
+}
+
 /************************************/
 /*-- SCI0 iterator implementation --*/
 /************************************/
@@ -651,6 +660,11 @@
 	channel->saw_notes = 0;
 }
 
+Sci0SongIterator::Sci0SongIterator() {
+	channel_mask = 0xffff;	// Allocate all channels by default
+	channel.state = SI_STATE_UNINITIALISED;
+}
+
 void Sci0SongIterator::init() {
 	fade.action = FADE_ACTION_NONE;
 	resetflag = 0;
@@ -668,15 +682,6 @@
 }
 
 
-void Sci0SongIterator::cleanup() {
-#ifdef DEBUG_VERBOSE
-	fprintf(stderr, "** FREEING it %p: data at %p\n", this, data);
-#endif
-	if (data)
-		sci_refcount_decref(data);
-	data = NULL;
-}
-
 /***************************/
 /*-- SCI1 song iterators --*/
 /***************************/
@@ -1190,6 +1195,10 @@
 	return NULL;
 }
 
+Sci1SongIterator::Sci1SongIterator() {
+	channel_mask = 0; // Defer channel allocation
+}
+
 void Sci1SongIterator::init() {
 	fade.action = FADE_ACTION_NONE;
 	resetflag = 0;
@@ -1208,20 +1217,13 @@
 	memset(importance, 0, sizeof(importance));
 }
 
-void Sci1SongIterator::cleanup() {
+Sci1SongIterator::~Sci1SongIterator() {
 	Sci1Sample *sample_seeker = _nextSample;
 	while (sample_seeker) {
 		Sci1Sample *old_sample = sample_seeker;
 		sample_seeker = sample_seeker->next;
 		delete old_sample;
 	}
-
-#ifdef DEBUG_VERBOSE
-	fprintf(stderr, "** FREEING it %p: data at %p\n", this, data);
-#endif
-	if (data)
-		sci_refcount_decref(data);
-	data = NULL;
 }
 
 int Sci1SongIterator::getTimepos() {
@@ -1407,8 +1409,7 @@
 static void _tee_free(TeeSongIterator *it) {
 	int i;
 	for (i = TEE_LEFT; i <= TEE_RIGHT; i++)
-		if (it->_children[i].it)
-			songit_free(it->_children[i].it);
+		delete it->_children[i].it;
 }
 #endif
 
@@ -1615,15 +1616,15 @@
 
 		case _SIMSG_PLASTICWRAP_ACK_MORPH:
 			if (!(_status & (TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE))) {
-				songit_free(this);
+				delete this;
 				return NULL;
 			} else if (!(_status & TEE_LEFT_ACTIVE)) {
-				songit_free(_children[TEE_LEFT].it);
+				delete _children[TEE_LEFT].it;
 				old_it = _children[TEE_RIGHT].it;
 				delete this;
 				return old_it;
 			} else if (!(_status & TEE_RIGHT_ACTIVE)) {
-				songit_free(_children[TEE_RIGHT].it);
+				delete _children[TEE_RIGHT].it;
 				old_it = _children[TEE_LEFT].it;
 				delete this;
 				return old_it;
@@ -1746,7 +1747,7 @@
 			int channel_mask = (*it)->channel_mask;
 
 			if (mask & IT_READER_MAY_FREE)
-				songit_free(*it);
+				delete *it;
 			*it = new_cleanup_iterator(channel_mask);
 			retval = -9999; /* Continue */
 		}
@@ -1764,7 +1765,7 @@
 
 	if (retval == SI_FINISHED
 	        && (mask & IT_READER_MAY_FREE)) {
-		songit_free(*it);
+		delete *it;
 		*it = NULL;
 	}
 
@@ -1786,15 +1787,6 @@
 			songit_tee_death_notification(_deathListeners[i], this);
 }
 
-Sci0SongIterator::Sci0SongIterator() {
-	channel_mask = 0xffff;	// Allocate all channels by default
-	channel.state = SI_STATE_UNINITIALISED;
-}
-
-Sci1SongIterator::Sci1SongIterator() {
-	channel_mask = 0; // Defer channel allocation
-}
-
 SongIterator *songit_new(byte *data, uint size, int type, songit_id_t id) {
 	BaseSongIterator *it;
 	int i;
@@ -1838,14 +1830,6 @@
 	return it;
 }
 
-void songit_free(SongIterator *it) {
-	if (it) {
-		it->cleanup();
-
-		delete it;
-	}
-}
-
 SongIteratorMessage::SongIteratorMessage() {
 	ID = 0;
 	recipient = 0;

Modified: scummvm/trunk/engines/sci/sfx/iterator.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator.h	2009-03-06 17:39:46 UTC (rev 39157)
+++ scummvm/trunk/engines/sci/sfx/iterator.h	2009-03-06 17:53:11 UTC (rev 39158)
@@ -208,13 +208,6 @@
 	virtual void init() {}
 
 	/**
-	 * Frees any content of the iterator structure.
-	 * Does not physically free(self) yet. May be NULL if nothing needs to be done.
-	 * Must not recurse on its delegate.
-	 */
-	virtual void cleanup() {}
-
-	/**
 	 * Gets the song position to store in a savegame.
 	 */
 	virtual int getTimepos() = 0;
@@ -286,13 +279,6 @@
 */
 
 
-void songit_free(SongIterator *it);
-/* Frees a song iterator and the song it wraps
-** Parameters: (SongIterator *) it: The song iterator to free
-** Returns   : (void)
-*/
-
-
 int songit_handle_message(SongIterator **it_reg, SongIteratorMessage msg);
 /* Handles a message to the song iterator
 ** Parameters: (SongIterator **): A reference to the variable storing the song iterator

Modified: scummvm/trunk/engines/sci/sfx/iterator_internal.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator_internal.h	2009-03-06 17:39:46 UTC (rev 39157)
+++ scummvm/trunk/engines/sci/sfx/iterator_internal.h	2009-03-06 17:53:11 UTC (rev 39158)
@@ -90,6 +90,9 @@
 
 	int loops; /* Number of loops remaining */
 	int recover_delay;
+
+public:
+	~BaseSongIterator();
 };
 
 /********************************/
@@ -108,7 +111,6 @@
 	Audio::AudioStream *getAudioStream();
 	SongIterator *handleMessage(SongIteratorMessage msg);
 	void init();
-	void cleanup();
 	int getTimepos();
 };
 
@@ -145,12 +147,12 @@
 
 public:
 	Sci1SongIterator();
+	~Sci1SongIterator();
 
 	int nextCommand(byte *buf, int *result);
 	Audio::AudioStream *getAudioStream();
 	SongIterator *handleMessage(SongIteratorMessage msg);
 	void init();
-	void cleanup();
 	int getTimepos();
 };
 

Modified: scummvm/trunk/engines/sci/sfx/player/polled.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/player/polled.cpp	2009-03-06 17:39:46 UTC (rev 39157)
+++ scummvm/trunk/engines/sci/sfx/player/polled.cpp	2009-03-06 17:53:11 UTC (rev 39158)
@@ -220,7 +220,7 @@
 				break;
 
 			case SI_FINISHED:
-				songit_free(play_it);
+				delete play_it;
 				play_it = NULL;
 				return written; /* We're done... */
 
@@ -351,8 +351,7 @@
 
 	play_it = NULL;
 	warning("[play] Now stopping it %p", (void *)it);
-	if (it)
-		songit_free(it);
+	delete it;
 
 	seq->allstop(seq);
 
@@ -392,7 +391,7 @@
 
 static int pp_exit() {
 	seq->exit(seq);
-	songit_free(play_it);
+	delete play_it;
 	play_it = NULL;
 
 	return SFX_OK;

Modified: scummvm/trunk/engines/sci/sfx/player/realtime.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/player/realtime.cpp	2009-03-06 17:39:46 UTC (rev 39157)
+++ scummvm/trunk/engines/sci/sfx/player/realtime.cpp	2009-03-06 17:53:11 UTC (rev 39158)
@@ -213,8 +213,7 @@
 
 	play_it = NULL;
 
-	if (it)
-		songit_free(it);
+	delete it;
 	if (seq && seq->allstop)
 		seq->allstop();
 

Modified: scummvm/trunk/engines/sci/sfx/songlib.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/songlib.cpp	2009-03-06 17:39:46 UTC (rev 39157)
+++ scummvm/trunk/engines/sci/sfx/songlib.cpp	2009-03-06 17:53:11 UTC (rev 39158)
@@ -81,7 +81,7 @@
 	/* Recursively free a chain of songs */
 	if (song) {
 		_songfree_chain(song->next);
-		songit_free(song->it);
+		delete song->it;
 		song->it = NULL;
 		free(song);
 	}
@@ -155,7 +155,7 @@
 
 	retval = goner->status;
 
-	songit_free(goner->it);
+	delete goner->it;
 	free(goner);
 
 	return retval;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list