SCI: Continued C++ification of SongIterator code
svn-id: r39158
This commit is contained in:
parent
e134281b5c
commit
763275f269
8 changed files with 37 additions and 67 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -207,13 +207,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.
|
||||
*/
|
||||
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue