aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/engine/ksound.cpp1
-rw-r--r--engines/sci/engine/savegame.cpp6
-rw-r--r--engines/sci/sfx/core.cpp14
-rw-r--r--engines/sci/sfx/iterator.cpp128
-rw-r--r--engines/sci/sfx/iterator.h105
-rw-r--r--engines/sci/sfx/iterator_internal.h8
-rw-r--r--engines/sci/sfx/player.h9
-rw-r--r--engines/sci/sfx/player/polled.cpp2
-rw-r--r--engines/sci/sfx/player/realtime.cpp2
-rw-r--r--engines/sci/sfx/test-iterator.cpp2
10 files changed, 127 insertions, 150 deletions
diff --git a/engines/sci/engine/ksound.cpp b/engines/sci/engine/ksound.cpp
index 855ef7fa57..fbedf79504 100644
--- a/engines/sci/engine/ksound.cpp
+++ b/engines/sci/engine/ksound.cpp
@@ -25,7 +25,6 @@
#include "sci/engine/state.h"
#include "sci/sfx/player.h"
-#include "sci/sfx/iterator.h"
#include "sci/engine/kernel.h"
namespace Sci {
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index afee660a16..8831f43707 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -5115,16 +5115,16 @@ static void reconstruct_sounds(EngineState *s) {
while (seeker) {
SongIterator *base, *ff;
int oldstatus;
- SongIteratorMessage msg;
+ SongIterator::Message msg;
base = ff = build_iterator(s, seeker->resource_num, it_type, seeker->handle);
if (seeker->restore_behavior == RESTORE_BEHAVIOR_CONTINUE)
ff = new_fast_forward_iterator(base, seeker->restore_time);
ff->init();
- msg = SongIteratorMessage(seeker->handle, SIMSG_SET_LOOPS(seeker->loops));
+ msg = SongIterator::Message(seeker->handle, SIMSG_SET_LOOPS(seeker->loops));
songit_handle_message(&ff, msg);
- msg = SongIteratorMessage(seeker->handle, SIMSG_SET_HOLD(seeker->hold));
+ msg = SongIterator::Message(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 66ffdc236d..ec9360795f 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(SongIteratorMessage(0, SIMSG_PRINT(1)));
+ player->iterator_message(SongIterator::Message(0, SIMSG_PRINT(1)));
}
#endif
}
@@ -305,7 +305,7 @@ static void _update_multi_song(sfx_state_t *self) {
}
if (player && oldseeker->it)
player->iterator_message
- (SongIteratorMessage(oldseeker->it->ID, SIMSG_STOP));
+ (SongIterator::Message(oldseeker->it->ID, SIMSG_STOP));
oldseeker->next_playing = NULL; /* Clear this pointer; we don't need the tag anymore */
}
@@ -496,7 +496,7 @@ int sfx_poll_specific(sfx_state_t *self, song_handle_t handle, int *cue) {
if (song->_wakeupTime.frameDiff(ctime) > 0)
return 0; /* Patience, young hacker! */
- unsigned char buf[8];
+ byte buf[8];
int result = songit_next(&(song->it), buf, cue, IT_READER_MASK_ALL);
switch (result) {
@@ -560,7 +560,7 @@ int sfx_add_song(sfx_state_t *self, SongIterator *it, int priority, song_handle_
_dump_songs(self);
if (player)
- player->iterator_message(SongIteratorMessage(handle, SIMSG_STOP));
+ player->iterator_message(SongIterator::Message(handle, SIMSG_STOP));
if (song) {
_sfx_set_song_status(self, song, SOUND_STATUS_STOPPED);
@@ -657,7 +657,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 = SongIteratorMessage(handle, SIMSG_SET_LOOPS(loops));
+ SongIterator::Message msg = SongIterator::Message(handle, SIMSG_SET_LOOPS(loops));
ASSERT_SONG(song);
#ifdef DEBUG_SONG_API
@@ -674,8 +674,8 @@ 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
- = SongIteratorMessage(handle, SIMSG_SET_HOLD(hold));
+ SongIterator::Message msg
+ = SongIterator::Message(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 c99d22e903..80c32d76bb 100644
--- a/engines/sci/sfx/iterator.cpp
+++ b/engines/sci/sfx/iterator.cpp
@@ -588,7 +588,7 @@ Audio::AudioStream *Sci0SongIterator::getAudioStream() {
return makeStream(_data + offset + SCI0_PCM_DATA_OFFSET, size, conf);
}
-SongIterator *Sci0SongIterator::handleMessage(SongIteratorMessage msg) {
+SongIterator *Sci0SongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_BASE) {
switch (msg.type) {
@@ -1075,7 +1075,7 @@ int Sci1SongIterator::nextCommand(byte *buf, int *result) {
return retval;
}
-SongIterator *Sci1SongIterator::handleMessage(SongIteratorMessage msg) {
+SongIterator *Sci1SongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_BASE) { /* May extend this in the future */
switch (msg.type) {
@@ -1241,12 +1241,12 @@ public:
int nextCommand(byte *buf, int *result);
Audio::AudioStream *getAudioStream() { return NULL; }
- SongIterator *handleMessage(SongIteratorMessage msg);
+ SongIterator *handleMessage(Message msg);
int getTimepos() { return 0; }
SongIterator *clone(int delta) { return new CleanupSongIterator(*this); }
};
-SongIterator *CleanupSongIterator::handleMessage(SongIteratorMessage msg) {
+SongIterator *CleanupSongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_BASEMSG_PRINT && msg.type == _SIMSG_BASEMSG_PRINT) {
print_tabs_id(msg.args[0].i, ID);
fprintf(stderr, "CLEANUP\n");
@@ -1299,36 +1299,28 @@ Audio::AudioStream *FastForwardSongIterator::getAudioStream() {
return _delegate->getAudioStream();
}
-SongIterator *FastForwardSongIterator::handleMessage(SongIteratorMessage msg) {
- if (msg.recipient == _SIMSG_PLASTICWRAP)
- switch (msg.type) {
-
- case _SIMSG_PLASTICWRAP_ACK_MORPH:
- if (_delta <= 0) {
- SongIterator *it = _delegate;
- delete this;
- return it;
- }
- break;
+SongIterator *FastForwardSongIterator::handleMessage(Message msg) {
+ if (msg.recipient == _SIMSG_PLASTICWRAP) {
+ assert(msg.type == _SIMSG_PLASTICWRAP_ACK_MORPH);
- default:
- BREAKPOINT();
+ if (_delta <= 0) {
+ SongIterator *it = _delegate;
+ delete this;
+ return it;
}
- else if (msg.recipient == _SIMSG_BASE) {
- switch (msg.type) {
- case _SIMSG_BASEMSG_PRINT:
- print_tabs_id(msg.args[0].i, ID);
- fprintf(stderr, "PLASTICWRAP:\n");
- msg.args[0].i++;
- songit_handle_message(&_delegate, msg);
- break;
+ warning("[ff-iterator] Morphing without need");
+ return this;
+ }
- default:
- songit_handle_message(&_delegate, msg);
- }
- } else
- songit_handle_message(&_delegate, msg);
+ if (msg.recipient == _SIMSG_BASE && msg.type == _SIMSG_BASEMSG_PRINT) {
+ print_tabs_id(msg.args[0].i, ID);
+ fprintf(stderr, "FASTFORWARD:\n");
+ msg.args[0].i++;
+ }
+
+ // And continue with the delegate
+ songit_handle_message(&_delegate, msg);
return NULL;
}
@@ -1600,7 +1592,6 @@ Audio::AudioStream *TeeSongIterator::getAudioStream() {
for (i = TEE_LEFT; i <= TEE_RIGHT; i++)
if (_status & pcm_masks[i]) {
-
_status &= ~pcm_masks[i];
return _children[i].it->getAudioStream();
}
@@ -1608,52 +1599,39 @@ Audio::AudioStream *TeeSongIterator::getAudioStream() {
return NULL; // No iterator
}
-SongIterator *TeeSongIterator::handleMessage(SongIteratorMessage msg) {
- if (msg.recipient == _SIMSG_BASE) {
- switch (msg.type) {
-
- case _SIMSG_BASEMSG_PRINT:
- print_tabs_id(msg.args[0].i, ID);
- fprintf(stderr, "TEE:\n");
- msg.args[0].i++;
- break; /* And continue with our children */
-
- default:
- break;
- }
- }
-
+SongIterator *TeeSongIterator::handleMessage(Message msg) {
if (msg.recipient == _SIMSG_PLASTICWRAP) {
+ assert(msg.type == _SIMSG_PLASTICWRAP_ACK_MORPH);
+
SongIterator *old_it;
- switch (msg.type) {
+ if (!(_status & (TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE))) {
+ delete this;
+ return NULL;
+ } else if (!(_status & TEE_LEFT_ACTIVE)) {
+ delete _children[TEE_LEFT].it;
+ _children[TEE_LEFT].it = 0;
+ old_it = _children[TEE_RIGHT].it;
+ delete this;
+ return old_it;
+ } else if (!(_status & TEE_RIGHT_ACTIVE)) {
+ delete _children[TEE_RIGHT].it;
+ _children[TEE_RIGHT].it = 0;
+ old_it = _children[TEE_LEFT].it;
+ delete this;
+ return old_it;
+ }
- case _SIMSG_PLASTICWRAP_ACK_MORPH:
- if (!(_status & (TEE_LEFT_ACTIVE | TEE_RIGHT_ACTIVE))) {
- delete this;
- return NULL;
- } else if (!(_status & TEE_LEFT_ACTIVE)) {
- delete _children[TEE_LEFT].it;
- _children[TEE_LEFT].it = 0;
- old_it = _children[TEE_RIGHT].it;
- delete this;
- return old_it;
- } else if (!(_status & TEE_RIGHT_ACTIVE)) {
- delete _children[TEE_RIGHT].it;
- _children[TEE_RIGHT].it = 0;
- old_it = _children[TEE_LEFT].it;
- delete this;
- return old_it;
- } else {
- sciprintf("[tee-iterator] WARNING:"
- " Morphing without need\n");
- return this;
- }
+ warning("[tee-iterator] Morphing without need");
+ return this;
+ }
- default:
- BREAKPOINT();
- }
+ if (msg.recipient == _SIMSG_BASE && msg.type == _SIMSG_BASEMSG_PRINT) {
+ print_tabs_id(msg.args[0].i, ID);
+ fprintf(stderr, "TEE:\n");
+ msg.args[0].i++;
}
+ // And continue with the children
if (_children[TEE_LEFT].it)
songit_handle_message(&(_children[TEE_LEFT].it), msg);
if (_children[TEE_RIGHT].it)
@@ -1785,13 +1763,13 @@ SongIterator *songit_new(byte *data, uint size, int type, songit_id_t id) {
return it;
}
-SongIteratorMessage::SongIteratorMessage() {
+SongIterator::Message::Message() {
ID = 0;
recipient = 0;
type = 0;
}
-SongIteratorMessage::SongIteratorMessage(songit_id_t id, int r, int t, int a1, int a2) {
+SongIterator::Message::Message(songit_id_t id, int r, int t, int a1, int a2) {
ID = id;
recipient = r;
type = t;
@@ -1799,7 +1777,7 @@ SongIteratorMessage::SongIteratorMessage(songit_id_t id, int r, int t, int a1, i
args[1].i = a2;
}
-SongIteratorMessage::SongIteratorMessage(songit_id_t id, int r, int t, void *a1, int a2) {
+SongIterator::Message::Message(songit_id_t id, int r, int t, void *a1, int a2) {
ID = id;
recipient = r;
type = t;
@@ -1807,7 +1785,7 @@ SongIteratorMessage::SongIteratorMessage(songit_id_t id, int r, int t, void *a1,
args[1].i = a2;
}
-int songit_handle_message(SongIterator **it_reg_p, SongIteratorMessage msg) {
+int songit_handle_message(SongIterator **it_reg_p, SongIterator::Message msg) {
SongIterator *it = *it_reg_p;
SongIterator *newit;
diff --git a/engines/sci/sfx/iterator.h b/engines/sci/sfx/iterator.h
index bfcecf5d13..775869e50b 100644
--- a/engines/sci/sfx/iterator.h
+++ b/engines/sci/sfx/iterator.h
@@ -91,49 +91,11 @@ enum {
/*#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), 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))
+#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))
typedef unsigned long songit_id_t;
-struct SongIteratorMessage {
- songit_id_t ID;
- uint recipient; /* Type of iterator supposed to receive this */
- uint type;
- union {
- 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
@@ -141,6 +103,45 @@ class TeeSongIterator;
class SongIterator {
public:
+ struct Message {
+ songit_id_t ID;
+ uint recipient; /* Type of iterator supposed to receive this */
+ uint type;
+ union {
+ uint i;
+ void *p;
+ } args[SONG_ITERATOR_MESSAGE_ARGUMENTS_NR];
+
+ Message();
+
+ /**
+ * 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
+ */
+ Message(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
+ */
+ Message(songit_id_t id, int recipient_class, int type, void *a1, int a2);
+ };
+
+public:
songit_id_t ID;
uint16 channel_mask; /* Bitmask of all channels this iterator will use */
fade_params_t fade;
@@ -165,20 +166,22 @@ public:
/**
* Reads the next MIDI operation _or_ delta time.
- * Parameters: (SongIterator *) self
- * (byte *) buf: The buffer to write to (needs to be able to
- * store at least 4 bytes)
- * Returns : (int) zero if a MIDI operation was written, SI_FINISHED
+ * @param buf The buffer to write to (needs to be able to store at least 4 bytes)
+ * @param result Number of bytes written to the buffer
+ * (equals the number of bytes that need to be passed
+ * to the lower layers) for 0, the cue value for SI_CUE,
+ * or the number of loops remaining for SI_LOOP.
+ * @return zero if a MIDI operation was written, SI_FINISHED
* if the song has finished playing, SI_LOOP if looping
* (after updating the loop variable), SI_CUE if we found
* a cue, SI_PCM if a PCM was found, or the number of ticks
* to wait before this function should be called next.
- * (int) *result: Number of bytes written to the buffer
- * (equals the number of bytes that need to be passed
- * to the lower layers) for 0, the cue value for SI_CUE,
- * or the number of loops remaining for SI_LOOP.
- * If SI_PCM is returned, get_pcm() may be used to retrieve the associated
+ *
+ * @note If SI_PCM is returned, get_pcm() may be used to retrieve the associated
* PCM, but this must be done before any subsequent calls to next().
+ *
+ * @todo The actual buffer size should either be specified or passed in, so that
+ * we can detect buffer overruns.
*/
virtual int nextCommand(byte *buf, int *result) = 0;
@@ -201,7 +204,7 @@ public:
* takes care of that and makes sure that its delegate received the message (and
* was morphed) before self.
*/
- virtual SongIterator *handleMessage(SongIteratorMessage msg) = 0;
+ virtual SongIterator *handleMessage(Message msg) = 0;
/**
* Gets the song position to store in a savegame.
@@ -274,7 +277,7 @@ SongIterator *songit_new(unsigned char *data, uint size, int type, songit_id_t i
*/
-int songit_handle_message(SongIterator **it_reg, SongIteratorMessage msg);
+int songit_handle_message(SongIterator **it_reg, SongIterator::Message msg);
/* Handles a message to the song iterator
** Parameters: (SongIterator **): A reference to the variable storing the song iterator
** Returns : (int) Non-zero if the message was understood
diff --git a/engines/sci/sfx/iterator_internal.h b/engines/sci/sfx/iterator_internal.h
index dc0a4e6647..42c54b215e 100644
--- a/engines/sci/sfx/iterator_internal.h
+++ b/engines/sci/sfx/iterator_internal.h
@@ -118,7 +118,7 @@ public:
int nextCommand(byte *buf, int *result);
Audio::AudioStream *getAudioStream();
- SongIterator *handleMessage(SongIteratorMessage msg);
+ SongIterator *handleMessage(Message msg);
void init();
int getTimepos();
SongIterator *clone(int delta);
@@ -163,7 +163,7 @@ public:
int nextCommand(byte *buf, int *result);
Audio::AudioStream *getAudioStream();
- SongIterator *handleMessage(SongIteratorMessage msg);
+ SongIterator *handleMessage(Message msg);
void init();
int getTimepos();
SongIterator *clone(int delta);
@@ -185,7 +185,7 @@ public:
int nextCommand(byte *buf, int *result);
Audio::AudioStream *getAudioStream();
- SongIterator *handleMessage(SongIteratorMessage msg);
+ SongIterator *handleMessage(Message msg);
int getTimepos();
SongIterator *clone(int delta);
};
@@ -237,7 +237,7 @@ public:
int nextCommand(byte *buf, int *result);
Audio::AudioStream *getAudioStream();
- SongIterator *handleMessage(SongIteratorMessage msg);
+ SongIterator *handleMessage(Message msg);
void init();
int getTimepos() { return 0; }
SongIterator *clone(int delta);
diff --git a/engines/sci/sfx/player.h b/engines/sci/sfx/player.h
index 6c375cb507..d77c12da6e 100644
--- a/engines/sci/sfx/player.h
+++ b/engines/sci/sfx/player.h
@@ -28,16 +28,13 @@
#ifndef SCI_SFX_SFX_PLAYER_H
#define SCI_SFX_SFX_PLAYER_H
-//#include "sci/sfx/core.h"
#include "sci/scicore/resource.h"
+#include "sci/sfx/iterator.h"
#include "common/scummsys.h"
namespace Sci {
-class SongIterator;
-struct SongIteratorMessage;
-
typedef void tell_synth_func(int buf_nr, byte *buf);
struct sfx_player_t {
@@ -81,9 +78,9 @@ struct sfx_player_t {
** Returns : (int) SFX_OK on success, SFX_ERROR on failure
*/
- int (*iterator_message)(const SongIteratorMessage &msg);
+ int (*iterator_message)(const SongIterator::Message &msg);
/* Transmits a song iterator message to the active song
- ** Parameters: (SongIteratorMessage) msg: The message to transmit
+ ** Parameters: (SongIterator::Message) msg: The message to transmit
** Returns : (int) SFX_OK on success, SFX_ERROR on failure
** OPTIONAL -- may be NULL
** If this method is not present, sending messages will stop
diff --git a/engines/sci/sfx/player/polled.cpp b/engines/sci/sfx/player/polled.cpp
index 1df4b2a62a..706e6581b7 100644
--- a/engines/sci/sfx/player/polled.cpp
+++ b/engines/sci/sfx/player/polled.cpp
@@ -359,7 +359,7 @@ static int pp_stop() {
return SFX_OK;
}
-static int pp_send_iterator_message(const SongIteratorMessage &msg) {
+static int pp_send_iterator_message(const SongIterator::Message &msg) {
if (!play_it)
return SFX_ERROR;
diff --git a/engines/sci/sfx/player/realtime.cpp b/engines/sci/sfx/player/realtime.cpp
index ed688176c7..2b6d9a18d0 100644
--- a/engines/sci/sfx/player/realtime.cpp
+++ b/engines/sci/sfx/player/realtime.cpp
@@ -223,7 +223,7 @@ static int rt_stop(void) {
return SFX_OK;
}
-static int rt_send_iterator_message(const SongIteratorMessage &msg) {
+static int rt_send_iterator_message(const SongIterator::Message &msg) {
if (!play_it)
return SFX_ERROR;
diff --git a/engines/sci/sfx/test-iterator.cpp b/engines/sci/sfx/test-iterator.cpp
index 73af09be6e..d4626b5fcb 100644
--- a/engines/sci/sfx/test-iterator.cpp
+++ b/engines/sci/sfx/test-iterator.cpp
@@ -111,7 +111,7 @@ Audio::AudioStream *simple_it_pcm_feed(SongIterator *_self) {
void simple_it_init(SongIterator *_self) {
}
-SongIterator *simple_it_handle_message(SongIterator *_self, SongIteratorMessage msg) {
+SongIterator *simple_it_handle_message(SongIterator *_self, SongIterator::Message msg) {
return NULL;
}