diff options
author | Max Horn | 2009-03-06 07:25:37 +0000 |
---|---|---|
committer | Max Horn | 2009-03-06 07:25:37 +0000 |
commit | 018d19e0204c874a6198fdfe513595c0cf5ac619 (patch) | |
tree | 15ffc5e9cf4180e38f84be308c38979ac76ee3f3 | |
parent | 24dac898fe9596ee5d0b3fc5c563694c6e4f8657 (diff) | |
download | scummvm-rg350-018d19e0204c874a6198fdfe513595c0cf5ac619.tar.gz scummvm-rg350-018d19e0204c874a6198fdfe513595c0cf5ac619.tar.bz2 scummvm-rg350-018d19e0204c874a6198fdfe513595c0cf5ac619.zip |
SCI: Some cleanup to the SongIteratorMessage code
svn-id: r39151
-rw-r--r-- | engines/sci/engine/savegame.cfsml | 4 | ||||
-rw-r--r-- | engines/sci/engine/savegame.cpp | 4 | ||||
-rw-r--r-- | engines/sci/sfx/core.cpp | 13 | ||||
-rw-r--r-- | engines/sci/sfx/iterator.cpp | 58 | ||||
-rw-r--r-- | engines/sci/sfx/iterator.h | 98 |
5 files changed, 96 insertions, 81 deletions
diff --git a/engines/sci/engine/savegame.cfsml b/engines/sci/engine/savegame.cfsml index bd62cd9924..289d43eb1f 100644 --- a/engines/sci/engine/savegame.cfsml +++ b/engines/sci/engine/savegame.cfsml @@ -1026,9 +1026,9 @@ static void reconstruct_sounds(EngineState *s) { ff = (SongIterator *)new_fast_forward_iterator(base, seeker->restore_time); ff->init(ff); - msg = songit_make_message(seeker->handle, SIMSG_SET_LOOPS(seeker->loops)); + msg = SongIteratorMessage(seeker->handle, SIMSG_SET_LOOPS(seeker->loops)); songit_handle_message(&ff, msg); - msg = songit_make_message(seeker->handle, SIMSG_SET_HOLD(seeker->hold)); + msg = SongIteratorMessage(seeker->handle, SIMSG_SET_HOLD(seeker->hold)); songit_handle_message(&ff, msg); oldstatus = seeker->status; diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 085655b57f..e2a59d1d45 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -5122,9 +5122,9 @@ static void reconstruct_sounds(EngineState *s) { ff = (SongIterator *)new_fast_forward_iterator(base, seeker->restore_time); ff->init(ff); - msg = songit_make_message(seeker->handle, SIMSG_SET_LOOPS(seeker->loops)); + msg = SongIteratorMessage(seeker->handle, SIMSG_SET_LOOPS(seeker->loops)); songit_handle_message(&ff, msg); - msg = songit_make_message(seeker->handle, SIMSG_SET_HOLD(seeker->hold)); + msg = SongIteratorMessage(seeker->handle, SIMSG_SET_HOLD(seeker->hold)); songit_handle_message(&ff, msg); oldstatus = seeker->status; diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp index 71eb70a981..80f241ef7a 100644 --- a/engines/sci/sfx/core.cpp +++ b/engines/sci/sfx/core.cpp @@ -124,7 +124,7 @@ static void _dump_songs(sfx_state_t *self) { if (player) { fprintf(stderr, "Audio iterator:\n"); - player->iterator_message(songit_make_message(0, SIMSG_PRINT(1))); + player->iterator_message(SongIteratorMessage(0, SIMSG_PRINT(1))); } #endif } @@ -306,7 +306,7 @@ static void _update_multi_song(sfx_state_t *self) { } if (player && oldseeker->it) player->iterator_message - (songit_make_message(oldseeker->it->ID, SIMSG_STOP)); + (SongIteratorMessage(oldseeker->it->ID, SIMSG_STOP)); oldseeker->next_playing = NULL; /* Clear this pointer; we don't need the tag anymore */ } @@ -566,7 +566,7 @@ int sfx_add_song(sfx_state_t *self, SongIterator *it, int priority, song_handle_ _dump_songs(self); if (player) - player->iterator_message(songit_make_message(handle, SIMSG_STOP)); + player->iterator_message(SongIteratorMessage(handle, SIMSG_STOP)); if (song) { _sfx_set_song_status(self, song, SOUND_STATUS_STOPPED); @@ -663,8 +663,7 @@ void sfx_song_renice(sfx_state_t *self, song_handle_t handle, int priority) { void sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops) { song_t *song = song_lib_find(self->songlib, handle); - SongIteratorMessage msg - = songit_make_message(handle, SIMSG_SET_LOOPS(loops)); + SongIteratorMessage msg = SongIteratorMessage(handle, SIMSG_SET_LOOPS(loops)); ASSERT_SONG(song); #ifdef DEBUG_SONG_API @@ -672,7 +671,7 @@ void sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops) { handle, loops); #endif songit_handle_message(&(song->it), msg); - song->loops = ((BaseSongIterator *) song->it)->loops; + song->loops = ((BaseSongIterator *)song->it)->loops; if (player/* && player->send_iterator_message*/) /* FIXME: The above should be optional! */ @@ -682,7 +681,7 @@ void sfx_song_set_loops(sfx_state_t *self, song_handle_t handle, int loops) { void sfx_song_set_hold(sfx_state_t *self, song_handle_t handle, int hold) { song_t *song = song_lib_find(self->songlib, handle); SongIteratorMessage msg - = songit_make_message(handle, SIMSG_SET_HOLD(hold)); + = SongIteratorMessage(handle, SIMSG_SET_HOLD(hold)); ASSERT_SONG(song); song->hold = hold; diff --git a/engines/sci/sfx/iterator.cpp b/engines/sci/sfx/iterator.cpp index 390194bf5b..9153b5fc3b 100644 --- a/engines/sci/sfx/iterator.cpp +++ b/engines/sci/sfx/iterator.cpp @@ -121,7 +121,7 @@ static int _sci0_read_next_command(Sci0SongIterator *self, static int _sci0_get_pcm_data(Sci0SongIterator *self, - sfx_pcm_config_t *format, int *xoffset, unsigned int *xsize); + sfx_pcm_config_t *format, int *xoffset, uint *xsize); #define PARSE_FLAG_LOOPS_UNLIMITED (1 << 0) /* Unlimited # of loops? */ #define PARSE_FLAG_PARAMETRIC_CUE (1 << 1) /* Assume that cues take an additional "cue value" argument */ @@ -371,7 +371,7 @@ static int _sci_midi_process_state(BaseSongIterator *self, unsigned char *buf, i case SI_STATE_PCM_MAGIC_DELTA: { sfx_pcm_config_t format; int offset; - unsigned int size; + uint size; int delay; if (_sci0_get_pcm_data((Sci0SongIterator *) self, &format, &offset, &size)) return SI_FINISHED; /* 'tis broken */ @@ -470,12 +470,12 @@ static inline int _sci0_header_magic_p(unsigned char *data, int offset, int size static int _sci0_get_pcm_data(Sci0SongIterator *self, - sfx_pcm_config_t *format, int *xoffset, unsigned int *xsize) { + sfx_pcm_config_t *format, int *xoffset, uint *xsize) { int tries = 2; int found_it = 0; unsigned char *pcm_data; int size; - unsigned int offset = SCI0_MIDI_OFFSET; + uint offset = SCI0_MIDI_OFFSET; if (self->data[0] != 2) return 1; @@ -559,7 +559,7 @@ static Audio::AudioStream *makeStream(byte *data, int size, sfx_pcm_config_t con Audio::AudioStream *Sci0SongIterator::get_pcm_feed() { sfx_pcm_config_t conf; int offset; - unsigned int size; + uint size; if (_sci0_get_pcm_data(this, &conf, &offset, &size)) return NULL; @@ -716,7 +716,7 @@ static int _sci1_sample_init(Sci1SongIterator *self, int offset) { int begin; int end; - CHECK_FOR_END_ABSOLUTE((unsigned int)offset + 10); + CHECK_FOR_END_ABSOLUTE((uint)offset + 10); if (self->data[offset + 1] != 0) sciprintf("[iterator-1] In sample at offset 0x04x: Byte #1 is %02x instead of zero\n", self->data[offset + 1]); @@ -726,7 +726,7 @@ static int _sci1_sample_init(Sci1SongIterator *self, int offset) { begin = getInt16(self->data + offset + 6); end = getInt16(self->data + offset + 8); - CHECK_FOR_END_ABSOLUTE((unsigned int)(offset + 10 + length)); + CHECK_FOR_END_ABSOLUTE((uint)(offset + 10 + length)); sample = new Sci1Sample(); sample->delta = begin; @@ -759,7 +759,7 @@ static int _sci1_sample_init(Sci1SongIterator *self, int offset) { static int _sci1_song_init(Sci1SongIterator *self) { Sci1Sample *seeker; int last_time; - unsigned int offset = 0; + uint offset = 0; self->channels_nr = 0; self->next_sample = 0; // self->device_id = 0x0c; @@ -791,7 +791,7 @@ static int _sci1_song_init(Sci1SongIterator *self) { offset++; while (SONGDATA(0) != 0xff) { /* End of list? */ - unsigned int track_offset; + uint track_offset; int end; offset += 2; @@ -1283,7 +1283,7 @@ static int _cleanup_iterator_next(SongIterator *self, unsigned char *buf, int *r class CleanupSongIterator : public SongIterator { public: - CleanupSongIterator(unsigned int channels) { + CleanupSongIterator(uint channels) { channel_mask = channels; ID = 17; flags = 0; @@ -1299,7 +1299,7 @@ public: Audio::AudioStream *get_pcm_feed() { return NULL; } }; -SongIterator *new_cleanup_iterator(unsigned int channels) { +SongIterator *new_cleanup_iterator(uint channels) { CleanupSongIterator *it = new CleanupSongIterator(channels); return it; } @@ -1802,7 +1802,7 @@ int songit_next(SongIterator **it, unsigned char *buf, int *result, int mask) { return retval; } -SongIterator *songit_new(unsigned char *data, unsigned int size, int type, songit_id_t id) { +SongIterator *songit_new(unsigned char *data, uint size, int type, songit_id_t id) { BaseSongIterator *it; int i; @@ -1882,26 +1882,26 @@ void songit_free(SongIterator *it) { } } -SongIteratorMessage songit_make_message(songit_id_t id, int recipient, int type, int a1, int a2) { - SongIteratorMessage rv; - rv.ID = id; - rv.recipient = recipient; - rv.type = type; - rv.args[0].i = a1; - rv.args[1].i = a2; - - return rv; +SongIteratorMessage::SongIteratorMessage() { + ID = 0; + recipient = 0; + type = 0; } -SongIteratorMessage songit_make_ptr_message(songit_id_t id, int recipient, int type, void * a1, int a2) { - SongIteratorMessage rv; - rv.ID = id; - rv.recipient = recipient; - rv.type = type; - rv.args[0].p = a1; - rv.args[1].i = a2; +SongIteratorMessage::SongIteratorMessage(songit_id_t id, int r, int t, int a1, int a2) { + ID = id; + recipient = r; + type = t; + args[0].i = a1; + args[1].i = a2; +} - return rv; +SongIteratorMessage::SongIteratorMessage(songit_id_t id, int r, int t, void *a1, int a2) { + ID = id; + recipient = r; + type = t; + args[0].p = a1; + args[1].i = a2; } int songit_handle_message(SongIterator **it_reg_p, SongIteratorMessage msg) { diff --git a/engines/sci/sfx/iterator.h b/engines/sci/sfx/iterator.h index 737a8ab0d6..bb5617817c 100644 --- a/engines/sci/sfx/iterator.h +++ b/engines/sci/sfx/iterator.h @@ -59,19 +59,25 @@ struct fade_params_t { /* Helper defs for messages */ /* Base messages */ -#define _SIMSG_BASE 0 /* Any base decoder */ -#define _SIMSG_BASEMSG_SET_LOOPS 0 /* Set loops */ -#define _SIMSG_BASEMSG_CLONE 1 /* Clone object and data. Must provide the -** (possibly negative) number of ticks that have -** passed since the last delay time started being -** used */ -#define _SIMSG_BASEMSG_SET_PLAYMASK 2 /* Set the current playmask for filtering */ -#define _SIMSG_BASEMSG_SET_RHYTHM 3 /* Activate/deactivate rhythm channel */ -#define _SIMSG_BASEMSG_ACK_MORPH 4 /* Acknowledge self-morph */ -#define _SIMSG_BASEMSG_STOP 5 /* Stop iterator */ -#define _SIMSG_BASEMSG_PRINT 6 /* Print self to stderr, after printing param1 tabs */ -#define _SIMSG_BASEMSG_SET_HOLD 7 /* Set value of hold parameter to expect */ -#define _SIMSG_BASEMSG_SET_FADE 8 /* Set fade parameters */ +enum { + _SIMSG_BASE = 0, /* Any base decoder */ + _SIMSG_BASEMSG_SET_LOOPS = 0, /* Set loops */ + + /** + * Clone object and data. Must provide the (possibly negative) + * number of ticks that have passed since the last delay time + * started being used. + */ + _SIMSG_BASEMSG_CLONE = 1, + + _SIMSG_BASEMSG_SET_PLAYMASK = 2, /* Set the current playmask for filtering */ + _SIMSG_BASEMSG_SET_RHYTHM = 3, /* Activate/deactivate rhythm channel */ + _SIMSG_BASEMSG_ACK_MORPH = 4, /* Acknowledge self-morph */ + _SIMSG_BASEMSG_STOP = 5, /* Stop iterator */ + _SIMSG_BASEMSG_PRINT = 6, /* Print self to stderr, after printing param1 tabs */ + _SIMSG_BASEMSG_SET_HOLD = 7, /* Set value of hold parameter to expect */ + _SIMSG_BASEMSG_SET_FADE = 8 /* Set fade parameters */ +}; /* "Plastic" (discardable) wrapper messages */ #define _SIMSG_PLASTICWRAP 1 /* Any base decoder */ @@ -89,8 +95,8 @@ struct fade_params_t { /*#define SIMSG_SET_FADE(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_FADE,(x),0*/ /* Message transmission macro: Takes song reference, message reference */ -#define SIMSG_SEND(o, m) songit_handle_message(&(o), songit_make_message((o)->ID, m)) -#define SIMSG_SEND_FADE(o, m) songit_handle_message(&(o), songit_make_ptr_message((o)->ID, _SIMSG_BASE, _SIMSG_BASEMSG_SET_FADE, m, 0)) +#define SIMSG_SEND(o, m) songit_handle_message(&(o), SongIteratorMessage((o)->ID, m)) +#define SIMSG_SEND_FADE(o, m) songit_handle_message(&(o), SongIteratorMessage((o)->ID, _SIMSG_BASE, _SIMSG_BASEMSG_SET_FADE, m, 0)) /* Event listener interface */ struct listener_t { @@ -102,12 +108,41 @@ typedef unsigned long songit_id_t; struct SongIteratorMessage { songit_id_t ID; - unsigned int recipient; /* Type of iterator supposed to receive this */ - unsigned int type; + uint recipient; /* Type of iterator supposed to receive this */ + uint type; union { - unsigned int i; - void * p; + uint i; + void *p; } args[SONG_ITERATOR_MESSAGE_ARGUMENTS_NR]; + + + SongIteratorMessage(); + + /** + * Create a song iterator message. + * + * @param id: song ID the message is targeted to + * @param recipient_class: Message recipient class + * @param type message type + * @param a1 first message argument + * @param a2 second message argument + * + * @note You should only use this with the SIMSG_* macros + */ + SongIteratorMessage(songit_id_t id, int recipient_class, int type, int a1, int a2); + + /** + * Create a song iterator message, wherein the first parameter is a pointer. + * + * @param id: song ID the message is targeted to + * @param recipient_class: Message recipient class + * @param type message type + * @param a1 first message argument + * @param a2 second message argument + * + * @note You should only use this with the SIMSG_* macros + */ + SongIteratorMessage(songit_id_t id, int recipient_class, int type, void *a1, int a2); }; #define SONGIT_MAX_LISTENERS 2 @@ -117,7 +152,7 @@ public: songit_id_t ID; uint16 channel_mask; /* Bitmask of all channels this iterator will use */ fade_params_t fade; - unsigned int flags; + uint flags; int priority; /* Death listeners */ @@ -269,10 +304,10 @@ int songit_next(SongIterator **it, unsigned char *buf, int *result, int mask); ** or the number of loops remaining for SI_LOOP. */ -SongIterator *songit_new(unsigned char *data, unsigned int size, int type, songit_id_t id); +SongIterator *songit_new(unsigned char *data, uint size, int type, songit_id_t id); /* Constructs a new song iterator object ** Parameters: (byte *) data: The song data to iterate over -** (unsigned int) size: Number of bytes in the song +** (uint) size: Number of bytes in the song ** (int) type: One of the SCI_SONG_ITERATOR_TYPEs ** (songit_id_t) id: An ID for addressing the song iterator ** Returns : (SongIterator *) A newly allocated but uninitialized song @@ -295,25 +330,6 @@ void songit_free(SongIterator *it); ** Returns : (void) */ -SongIteratorMessage songit_make_message(songit_id_t id, - int recipient_class, int type, int a1, int a2); -/* Create a song iterator message -** Parameters: (songit_id_t) id: song ID the message is targetted to -** (int) recipient_class: Message recipient class -** (int) type: Message type -** (int x int) a1, a2: Arguments -** You should only use this with the SIMSG_* macros -*/ - -SongIteratorMessage songit_make_ptr_message(songit_id_t id, - int recipient_class, int type, void * a1, int a2); -/* Create a song iterator message, wherein the first parameter is a pointer -** Parameters: (songit_id_t) id: song ID the message is targetted to -** (int) recipient_class: Message recipient class -** (int) type: Message type -** (void* x int) a1, a2: Arguments -** You should only use this with the SIMSG_* macros -*/ int songit_handle_message(SongIterator **it_reg, SongIteratorMessage msg); /* Handles a message to the song iterator |