aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-03-06 17:53:11 +0000
committerMax Horn2009-03-06 17:53:11 +0000
commit763275f2699f0718d45e7732efe25434161f0c7c (patch)
treeb9ae404134bc9d6ad8b474573a8a09402df71629
parente134281b5c7e25dc0d322cba108c646d35e5ae1e (diff)
downloadscummvm-rg350-763275f2699f0718d45e7732efe25434161f0c7c.tar.gz
scummvm-rg350-763275f2699f0718d45e7732efe25434161f0c7c.tar.bz2
scummvm-rg350-763275f2699f0718d45e7732efe25434161f0c7c.zip
SCI: Continued C++ification of SongIterator code
svn-id: r39158
-rw-r--r--engines/sci/engine/scriptdebug.cpp2
-rw-r--r--engines/sci/sfx/core.cpp2
-rw-r--r--engines/sci/sfx/iterator.cpp66
-rw-r--r--engines/sci/sfx/iterator.h14
-rw-r--r--engines/sci/sfx/iterator_internal.h6
-rw-r--r--engines/sci/sfx/player/polled.cpp7
-rw-r--r--engines/sci/sfx/player/realtime.cpp3
-rw-r--r--engines/sci/sfx/songlib.cpp4
8 files changed, 37 insertions, 67 deletions
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index f71b306ae1..ea10978db2 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -2436,7 +2436,7 @@ static int c_is_sample(EngineState *s) {
} else
sciprintf("Valid song, but not a sample.\n");
- songit_free(songit);
+ delete songit;
return 0;
}
diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp
index 7a649af0ce..01110bb32a 100644
--- a/engines/sci/sfx/core.cpp
+++ b/engines/sci/sfx/core.cpp
@@ -576,7 +576,7 @@ int sfx_add_song(sfx_state_t *self, SongIterator *it, int priority, song_handle_
|| 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 */
diff --git a/engines/sci/sfx/iterator.cpp b/engines/sci/sfx/iterator.cpp
index c4e1864f98..d16635c9a0 100644
--- a/engines/sci/sfx/iterator.cpp
+++ b/engines/sci/sfx/iterator.cpp
@@ -64,6 +64,15 @@ static unsigned char *sci_memchr(void *_data, int c, int n) {
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 @@ static void _base_init_channel(SongIteratorChannel *channel, int id, int offset,
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::init() {
}
-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 @@ SongIterator *Sci1SongIterator::handleMessage(SongIteratorMessage msg) {
return NULL;
}
+Sci1SongIterator::Sci1SongIterator() {
+ channel_mask = 0; // Defer channel allocation
+}
+
void Sci1SongIterator::init() {
fade.action = FADE_ACTION_NONE;
resetflag = 0;
@@ -1208,20 +1217,13 @@ void Sci1SongIterator::init() {
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 song_iterator_remove_death_listener(SongIterator *it, TeeSongIterato
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 @@ SongIterator *TeeSongIterator::handleMessage(SongIteratorMessage msg) {
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 songit_next(SongIterator **it, unsigned char *buf, int *result, int mask) {
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 @@ int songit_next(SongIterator **it, unsigned char *buf, int *result, int mask) {
if (retval == SI_FINISHED
&& (mask & IT_READER_MAY_FREE)) {
- songit_free(*it);
+ delete *it;
*it = NULL;
}
@@ -1786,15 +1787,6 @@ SongIterator::~SongIterator() {
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 @@ SongIterator *songit_new(byte *data, uint size, int type, songit_id_t id) {
return it;
}
-void songit_free(SongIterator *it) {
- if (it) {
- it->cleanup();
-
- delete it;
- }
-}
-
SongIteratorMessage::SongIteratorMessage() {
ID = 0;
recipient = 0;
diff --git a/engines/sci/sfx/iterator.h b/engines/sci/sfx/iterator.h
index 0f284ff859..38cb2c89ea 100644
--- a/engines/sci/sfx/iterator.h
+++ b/engines/sci/sfx/iterator.h
@@ -208,13 +208,6 @@ public:
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 @@ SongIterator *songit_new_tee(SongIterator *left, SongIterator *right);
*/
-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
diff --git a/engines/sci/sfx/iterator_internal.h b/engines/sci/sfx/iterator_internal.h
index e23eac9e2f..70cdab4e23 100644
--- a/engines/sci/sfx/iterator_internal.h
+++ b/engines/sci/sfx/iterator_internal.h
@@ -90,6 +90,9 @@ public:
int loops; /* Number of loops remaining */
int recover_delay;
+
+public:
+ ~BaseSongIterator();
};
/********************************/
@@ -108,7 +111,6 @@ public:
Audio::AudioStream *getAudioStream();
SongIterator *handleMessage(SongIteratorMessage msg);
void init();
- void cleanup();
int getTimepos();
};
@@ -145,12 +147,12 @@ public:
public:
Sci1SongIterator();
+ ~Sci1SongIterator();
int nextCommand(byte *buf, int *result);
Audio::AudioStream *getAudioStream();
SongIterator *handleMessage(SongIteratorMessage msg);
void init();
- void cleanup();
int getTimepos();
};
diff --git a/engines/sci/sfx/player/polled.cpp b/engines/sci/sfx/player/polled.cpp
index 1824393c46..8740736248 100644
--- a/engines/sci/sfx/player/polled.cpp
+++ b/engines/sci/sfx/player/polled.cpp
@@ -220,7 +220,7 @@ static int ppf_poll(int frame_size, byte *dest, int size) {
break;
case SI_FINISHED:
- songit_free(play_it);
+ delete play_it;
play_it = NULL;
return written; /* We're done... */
@@ -351,8 +351,7 @@ static int pp_stop() {
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_resume() {
static int pp_exit() {
seq->exit(seq);
- songit_free(play_it);
+ delete play_it;
play_it = NULL;
return SFX_OK;
diff --git a/engines/sci/sfx/player/realtime.cpp b/engines/sci/sfx/player/realtime.cpp
index 60968c809f..cfe3db1ed3 100644
--- a/engines/sci/sfx/player/realtime.cpp
+++ b/engines/sci/sfx/player/realtime.cpp
@@ -213,8 +213,7 @@ static int rt_stop(void) {
play_it = NULL;
- if (it)
- songit_free(it);
+ delete it;
if (seq && seq->allstop)
seq->allstop();
diff --git a/engines/sci/sfx/songlib.cpp b/engines/sci/sfx/songlib.cpp
index 7c424b5d98..0c19f0dbcf 100644
--- a/engines/sci/sfx/songlib.cpp
+++ b/engines/sci/sfx/songlib.cpp
@@ -81,7 +81,7 @@ static void _songfree_chain(song_t *song) {
/* 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 @@ int song_lib_remove(songlib_t songlib, song_handle_t handle) {
retval = goner->status;
- songit_free(goner->it);
+ delete goner->it;
free(goner);
return retval;