SCI: SongIterator::Message only needs to transfer a single argument, so get rid of the second slot

svn-id: r39290
This commit is contained in:
Max Horn 2009-03-10 02:57:30 +00:00
parent 6b58973536
commit 7f1a9b385d
2 changed files with 53 additions and 72 deletions

View File

@ -589,17 +589,17 @@ Audio::AudioStream *Sci0SongIterator::getAudioStream() {
} }
SongIterator *Sci0SongIterator::handleMessage(Message msg) { SongIterator *Sci0SongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_BASE) { if (msg._class == _SIMSG_BASE) {
switch (msg.type) { switch (msg._type) {
case _SIMSG_BASEMSG_PRINT: case _SIMSG_BASEMSG_PRINT:
print_tabs_id(msg.args[0].i, ID); print_tabs_id(msg._arg.i, ID);
fprintf(stderr, "SCI0: dev=%d, active-chan=%d, size=%d, loops=%d\n", fprintf(stderr, "SCI0: dev=%d, active-chan=%d, size=%d, loops=%d\n",
_deviceId, active_channels, _size, loops); _deviceId, active_channels, _size, loops);
break; break;
case _SIMSG_BASEMSG_SET_LOOPS: case _SIMSG_BASEMSG_SET_LOOPS:
loops = msg.args[0].i; loops = msg._arg.i;
break; break;
case _SIMSG_BASEMSG_STOP: { case _SIMSG_BASEMSG_STOP: {
@ -612,7 +612,7 @@ SongIterator *Sci0SongIterator::handleMessage(Message msg) {
case _SIMSG_BASEMSG_SET_PLAYMASK: { case _SIMSG_BASEMSG_SET_PLAYMASK: {
int i; int i;
_deviceId = msg.args[0].i; _deviceId = msg._arg.i;
/* Set all but the rhytm channel mask bits */ /* Set all but the rhytm channel mask bits */
channel.playmask &= ~(1 << MIDI_RHYTHM_CHANNEL); channel.playmask &= ~(1 << MIDI_RHYTHM_CHANNEL);
@ -626,12 +626,12 @@ SongIterator *Sci0SongIterator::handleMessage(Message msg) {
case _SIMSG_BASEMSG_SET_RHYTHM: case _SIMSG_BASEMSG_SET_RHYTHM:
channel.playmask &= ~(1 << MIDI_RHYTHM_CHANNEL); channel.playmask &= ~(1 << MIDI_RHYTHM_CHANNEL);
if (msg.args[0].i) if (msg._arg.i)
channel.playmask |= (1 << MIDI_RHYTHM_CHANNEL); channel.playmask |= (1 << MIDI_RHYTHM_CHANNEL);
break; break;
case _SIMSG_BASEMSG_SET_FADE: { case _SIMSG_BASEMSG_SET_FADE: {
fade_params_t *fp = (fade_params_t *) msg.args[0].p; fade_params_t *fp = (fade_params_t *) msg._arg.p;
fade.action = fp->action; fade.action = fp->action;
fade.final_volume = fp->final_volume; fade.final_volume = fp->final_volume;
fade.ticks_per_step = fp->ticks_per_step; fade.ticks_per_step = fp->ticks_per_step;
@ -1076,8 +1076,8 @@ int Sci1SongIterator::nextCommand(byte *buf, int *result) {
} }
SongIterator *Sci1SongIterator::handleMessage(Message msg) { SongIterator *Sci1SongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_BASE) { /* May extend this in the future */ if (msg._class == _SIMSG_BASE) { /* May extend this in the future */
switch (msg.type) { switch (msg._type) {
case _SIMSG_BASEMSG_PRINT: { case _SIMSG_BASEMSG_PRINT: {
int playmask = 0; int playmask = 0;
@ -1086,7 +1086,7 @@ SongIterator *Sci1SongIterator::handleMessage(Message msg) {
for (i = 0; i < _numChannels; i++) for (i = 0; i < _numChannels; i++)
playmask |= _channels[i].playmask; playmask |= _channels[i].playmask;
print_tabs_id(msg.args[0].i, ID); print_tabs_id(msg._arg.i, ID);
fprintf(stderr, "SCI1: chan-nr=%d, playmask=%04x\n", fprintf(stderr, "SCI1: chan-nr=%d, playmask=%04x\n",
_numChannels, playmask); _numChannels, playmask);
} }
@ -1111,13 +1111,13 @@ SongIterator *Sci1SongIterator::handleMessage(Message msg) {
_deviceId _deviceId
= sci0_to_sci1_device_map = sci0_to_sci1_device_map
[sci_ffs(msg.args[0].i & 0xff) - 1] [sci_ffs(msg._arg.i & 0xff) - 1]
[sfx_pcm_available()] [sfx_pcm_available()]
; ;
if (_deviceId == 0xff) { if (_deviceId == 0xff) {
sciprintf("[iterator-1] Warning: Device %d(%d) not supported", sciprintf("[iterator-1] Warning: Device %d(%d) not supported",
msg.args[0].i & 0xff, sfx_pcm_available()); msg._arg.i & 0xff, sfx_pcm_available());
} }
if (_initialised) { if (_initialised) {
int i; int i;
@ -1152,20 +1152,20 @@ SongIterator *Sci1SongIterator::handleMessage(Message msg) {
case _SIMSG_BASEMSG_SET_LOOPS: case _SIMSG_BASEMSG_SET_LOOPS:
if (msg.ID == ID) if (msg.ID == ID)
loops = (msg.args[0].i > 32767) ? 99 : 0; loops = (msg._arg.i > 32767) ? 99 : 0;
/* 99 is arbitrary, but we can't use '1' because of /* 99 is arbitrary, but we can't use '1' because of
** the way we're testing in the decoding section. */ ** the way we're testing in the decoding section. */
break; break;
case _SIMSG_BASEMSG_SET_HOLD: case _SIMSG_BASEMSG_SET_HOLD:
_hold = msg.args[0].i; _hold = msg._arg.i;
break; break;
case _SIMSG_BASEMSG_SET_RHYTHM: case _SIMSG_BASEMSG_SET_RHYTHM:
/* Ignore */ /* Ignore */
break; break;
case _SIMSG_BASEMSG_SET_FADE: { case _SIMSG_BASEMSG_SET_FADE: {
fade_params_t *fp = (fade_params_t *) msg.args[0].p; fade_params_t *fp = (fade_params_t *) msg._arg.p;
fade.action = fp->action; fade.action = fp->action;
fade.final_volume = fp->final_volume; fade.final_volume = fp->final_volume;
fade.ticks_per_step = fp->ticks_per_step; fade.ticks_per_step = fp->ticks_per_step;
@ -1174,7 +1174,7 @@ SongIterator *Sci1SongIterator::handleMessage(Message msg) {
} }
default: default:
warning(SIPFX "Unsupported command %d to SCI1 iterator", msg.type); warning(SIPFX "Unsupported command %d to SCI1 iterator", msg._type);
} }
return this; return this;
} }
@ -1247,8 +1247,8 @@ public:
}; };
SongIterator *CleanupSongIterator::handleMessage(Message msg) { SongIterator *CleanupSongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_BASEMSG_PRINT && msg.type == _SIMSG_BASEMSG_PRINT) { if (msg._class == _SIMSG_BASEMSG_PRINT && msg._type == _SIMSG_BASEMSG_PRINT) {
print_tabs_id(msg.args[0].i, ID); print_tabs_id(msg._arg.i, ID);
fprintf(stderr, "CLEANUP\n"); fprintf(stderr, "CLEANUP\n");
} }
@ -1300,8 +1300,8 @@ Audio::AudioStream *FastForwardSongIterator::getAudioStream() {
} }
SongIterator *FastForwardSongIterator::handleMessage(Message msg) { SongIterator *FastForwardSongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_PLASTICWRAP) { if (msg._class == _SIMSG_PLASTICWRAP) {
assert(msg.type == _SIMSG_PLASTICWRAP_ACK_MORPH); assert(msg._type == _SIMSG_PLASTICWRAP_ACK_MORPH);
if (_delta <= 0) { if (_delta <= 0) {
SongIterator *it = _delegate; SongIterator *it = _delegate;
@ -1313,10 +1313,10 @@ SongIterator *FastForwardSongIterator::handleMessage(Message msg) {
return this; return this;
} }
if (msg.recipient == _SIMSG_BASE && msg.type == _SIMSG_BASEMSG_PRINT) { if (msg._class == _SIMSG_BASE && msg._type == _SIMSG_BASEMSG_PRINT) {
print_tabs_id(msg.args[0].i, ID); print_tabs_id(msg._arg.i, ID);
fprintf(stderr, "FASTFORWARD:\n"); fprintf(stderr, "FASTFORWARD:\n");
msg.args[0].i++; msg._arg.i++;
} }
// And continue with the delegate // And continue with the delegate
@ -1600,8 +1600,8 @@ Audio::AudioStream *TeeSongIterator::getAudioStream() {
} }
SongIterator *TeeSongIterator::handleMessage(Message msg) { SongIterator *TeeSongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_PLASTICWRAP) { if (msg._class == _SIMSG_PLASTICWRAP) {
assert(msg.type == _SIMSG_PLASTICWRAP_ACK_MORPH); assert(msg._type == _SIMSG_PLASTICWRAP_ACK_MORPH);
SongIterator *old_it; SongIterator *old_it;
if (!(_status & (TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE))) { if (!(_status & (TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE))) {
@ -1625,10 +1625,10 @@ SongIterator *TeeSongIterator::handleMessage(Message msg) {
return this; return this;
} }
if (msg.recipient == _SIMSG_BASE && msg.type == _SIMSG_BASEMSG_PRINT) { if (msg._class == _SIMSG_BASE && msg._type == _SIMSG_BASEMSG_PRINT) {
print_tabs_id(msg.args[0].i, ID); print_tabs_id(msg._arg.i, ID);
fprintf(stderr, "TEE:\n"); fprintf(stderr, "TEE:\n");
msg.args[0].i++; msg._arg.i++;
} }
// And continue with the children // And continue with the children
@ -1674,7 +1674,8 @@ int songit_next(SongIterator **it, byte *buf, int *result, int mask) {
fprintf(stderr, " Morphing %p (stored at %p)\n", (void *)*it, (void *)it); fprintf(stderr, " Morphing %p (stored at %p)\n", (void *)*it, (void *)it);
if (!SIMSG_SEND((*it), SIMSG_ACK_MORPH)) { if (!SIMSG_SEND((*it), SIMSG_ACK_MORPH)) {
BREAKPOINT(); BREAKPOINT();
} else fprintf(stderr, "SI_MORPH successful\n"); } else
fprintf(stderr, "SI_MORPH successful\n");
} }
if (retval == SI_FINISHED) if (retval == SI_FINISHED)
@ -1704,8 +1705,7 @@ int songit_next(SongIterator **it, byte *buf, int *result, int mask) {
|| (retval == SI_FINISHED) || (retval == SI_FINISHED)
)); ));
if (retval == SI_FINISHED if (retval == SI_FINISHED && (mask & IT_READER_MAY_FREE)) {
&& (mask & IT_READER_MAY_FREE)) {
delete *it; delete *it;
*it = NULL; *it = NULL;
} }
@ -1763,28 +1763,6 @@ SongIterator *songit_new(byte *data, uint size, int type, songit_id_t id) {
return it; return it;
} }
SongIterator::Message::Message() {
ID = 0;
recipient = 0;
type = 0;
}
SongIterator::Message::Message(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;
}
SongIterator::Message::Message(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, SongIterator::Message msg) { int songit_handle_message(SongIterator **it_reg_p, SongIterator::Message msg) {
SongIterator *it = *it_reg_p; SongIterator *it = *it_reg_p;
SongIterator *newit; SongIterator *newit;

View File

@ -81,18 +81,17 @@ enum {
}; };
/* Messages */ /* Messages */
#define SIMSG_SET_LOOPS(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_LOOPS,(x),0 #define SIMSG_SET_LOOPS(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_LOOPS,(x)
#define SIMSG_SET_PLAYMASK(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_PLAYMASK,(x),0 #define SIMSG_SET_PLAYMASK(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_PLAYMASK,(x)
#define SIMSG_SET_RHYTHM(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_RHYTHM,(x),0 #define SIMSG_SET_RHYTHM(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_RHYTHM,(x)
#define SIMSG_ACK_MORPH _SIMSG_PLASTICWRAP,_SIMSG_PLASTICWRAP_ACK_MORPH,0,0 #define SIMSG_ACK_MORPH _SIMSG_PLASTICWRAP,_SIMSG_PLASTICWRAP_ACK_MORPH,0
#define SIMSG_STOP _SIMSG_BASE,_SIMSG_BASEMSG_STOP,0,0 #define SIMSG_STOP _SIMSG_BASE,_SIMSG_BASEMSG_STOP,0
#define SIMSG_PRINT(indentation) _SIMSG_BASE,_SIMSG_BASEMSG_PRINT,(indentation),0 #define SIMSG_PRINT(indentation) _SIMSG_BASE,_SIMSG_BASEMSG_PRINT,(indentation)
#define SIMSG_SET_HOLD(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_HOLD,(x),0 #define SIMSG_SET_HOLD(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_HOLD,(x)
/*#define SIMSG_SET_FADE(x) _SIMSG_BASE,_SIMSG_BASEMSG_SET_FADE,(x),0*/
/* Message transmission macro: Takes song reference, message reference */ /* Message transmission macro: Takes song reference, message reference */
#define SIMSG_SEND(o, m) songit_handle_message(&(o), SongIterator::Message((o)->ID, m)) #define SIMSG_SEND(o, m) songit_handle_message(&(o), SongIterator::Message((o)->ID, m))
#define SIMSG_SEND_FADE(o, m) songit_handle_message(&(o), SongIterator::Message((o)->ID, _SIMSG_BASE, _SIMSG_BASEMSG_SET_FADE, m, 0)) #define SIMSG_SEND_FADE(o, m) songit_handle_message(&(o), SongIterator::Message((o)->ID, _SIMSG_BASE, _SIMSG_BASEMSG_SET_FADE, m))
typedef unsigned long songit_id_t; typedef unsigned long songit_id_t;
@ -105,14 +104,14 @@ class SongIterator {
public: public:
struct Message { struct Message {
songit_id_t ID; songit_id_t ID;
uint recipient; /* Type of iterator supposed to receive this */ uint _class; /* Type of iterator supposed to receive this */
uint type; uint _type;
union { union {
uint i; uint i;
void *p; void *p;
} args[SONG_ITERATOR_MESSAGE_ARGUMENTS_NR]; } _arg;
Message(); Message() : ID(0), _class(0xFFFF), _type(0xFFFF) {}
/** /**
* Create a song iterator message. * Create a song iterator message.
@ -120,12 +119,14 @@ public:
* @param id: song ID the message is targeted to * @param id: song ID the message is targeted to
* @param recipient_class: Message recipient class * @param recipient_class: Message recipient class
* @param type message type * @param type message type
* @param a1 first message argument * @param a argument
* @param a2 second message argument
* *
* @note You should only use this with the SIMSG_* macros * @note You should only use this with the SIMSG_* macros
*/ */
Message(songit_id_t id, int recipient_class, int type, int a1, int a2); Message(songit_id_t id, int recipient_class, int type, int a)
: ID(id), _class(recipient_class), _type(type) {
_arg.i = a;
}
/** /**
* Create a song iterator message, wherein the first parameter is a pointer. * Create a song iterator message, wherein the first parameter is a pointer.
@ -133,12 +134,14 @@ public:
* @param id: song ID the message is targeted to * @param id: song ID the message is targeted to
* @param recipient_class: Message recipient class * @param recipient_class: Message recipient class
* @param type message type * @param type message type
* @param a1 first message argument * @param a argument
* @param a2 second message argument
* *
* @note You should only use this with the SIMSG_* macros * @note You should only use this with the SIMSG_* macros
*/ */
Message(songit_id_t id, int recipient_class, int type, void *a1, int a2); Message(songit_id_t id, int recipient_class, int type, void *a)
: ID(id), _class(recipient_class), _type(type) {
_arg.p = a;
}
}; };
public: public: