Skip to content

Commit

Permalink
DIRECTOR: Implement function 'marker'.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhoefel committed Jan 16, 2017
1 parent 5fbb4fc commit 8638273
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 54 deletions.
5 changes: 2 additions & 3 deletions engines/director/lingo/lingo-builtins.cpp
Expand Up @@ -905,9 +905,8 @@ void Lingo::b_label(int nargs) {
void Lingo::b_marker(int nargs) {
Datum d = g_lingo->pop();
d.toInt();
warning("STUB: b_marker(%d)", d.u.i);

g_lingo->push(Datum(0));
int marker = g_lingo->func_marker(d.u.i);
g_lingo->push(marker);
}

void Lingo::b_moveableSprite(int nargs) {
Expand Down
23 changes: 19 additions & 4 deletions engines/director/lingo/lingo-funcs.cpp
Expand Up @@ -212,21 +212,21 @@ void Lingo::func_gotoloop() {
if (!_vm->_currentScore)
return;

_vm->_currentScore->gotoloop();
_vm->_currentScore->gotoLoop();
}

void Lingo::func_gotonext() {
if (!_vm->_currentScore)
return;

_vm->_currentScore->gotonext();
_vm->_currentScore->gotoNext();
}

void Lingo::func_gotoprevious() {
if (!_vm->_currentScore)
return;

_vm->_currentScore->gotoprevious();
_vm->_currentScore->gotoPrevious();
}

void Lingo::func_cursor(int c) {
Expand Down Expand Up @@ -265,4 +265,19 @@ void Lingo::func_beep(int repeats) {
_vm->getSoundManager()->systemBeep();
}

int Lingo::func_marker(int m) {
int labelNumber = _vm->getCurrentScore()->getCurrentLabelNumber();
if (m != 0) {
if (m < 0) {
for (int marker = 0; marker > m; marker--)
labelNumber = _vm->getCurrentScore()->getPreviousLabelNumber(labelNumber);
} else {
for (int marker = 0; marker < m; marker++)
labelNumber = _vm->getCurrentScore()->getNextLabelNumber(labelNumber);
}
}

return labelNumber;
}

}
1 change: 1 addition & 0 deletions engines/director/lingo/lingo.h
Expand Up @@ -460,6 +460,7 @@ class Lingo {
void func_gotonext();
void func_gotoprevious();
void func_cursor(int c);
int func_marker(int m);

public:
void setTheEntity(int entity, Datum &id, int field, Datum &d);
Expand Down
110 changes: 66 additions & 44 deletions engines/director/score.cpp
Expand Up @@ -157,19 +157,19 @@ Score::Score(DirectorEngine *vm, Archive *archive) {
_stopPlay = false;
_stageColor = 0;

if (archive->hasResource(MKTAG('M','C','N','M'), 0)) {
_macName = archive->getName(MKTAG('M','C','N','M'), 0).c_str();
if (archive->hasResource(MKTAG('M', 'C', 'N', 'M'), 0)) {
_macName = archive->getName(MKTAG('M', 'C', 'N', 'M'), 0).c_str();
} else {
_macName = archive->getFileName();
}

if (archive->hasResource(MKTAG('V','W','L','B'), 1024)) {
loadLabels(*archive->getResource(MKTAG('V','W','L','B'), 1024));
if (archive->hasResource(MKTAG('V', 'W', 'L', 'B'), 1024)) {
loadLabels(*archive->getResource(MKTAG('V', 'W', 'L', 'B'), 1024));
}
}

void Score::loadArchive() {
Common::Array<uint16> clutList = _movieArchive->getResourceIDList(MKTAG('C','L','U','T'));
Common::Array<uint16> clutList = _movieArchive->getResourceIDList(MKTAG('C', 'L', 'U', 'T'));

if (clutList.size() > 1)
warning("More than one palette was found (%d)", clutList.size());
Expand All @@ -185,36 +185,36 @@ void Score::loadArchive() {
g_system->getPaletteManager()->setPalette(_vm->getPalette(), 0, _vm->getPaletteColorCount());
}

assert(_movieArchive->hasResource(MKTAG('V','W','S','C'), 1024));
assert(_movieArchive->hasResource(MKTAG('V','W','C','F'), 1024));
assert(_movieArchive->hasResource(MKTAG('V', 'W', 'S', 'C'), 1024));
assert(_movieArchive->hasResource(MKTAG('V', 'W', 'C', 'F'), 1024));

loadFrames(*_movieArchive->getResource(MKTAG('V','W','S','C'), 1024));
loadConfig(*_movieArchive->getResource(MKTAG('V','W','C','F'), 1024));
loadFrames(*_movieArchive->getResource(MKTAG('V', 'W', 'S', 'C'), 1024));
loadConfig(*_movieArchive->getResource(MKTAG('V', 'W', 'C', 'F'), 1024));

if (_vm->getVersion() < 4) {
assert(_movieArchive->hasResource(MKTAG('V','W','C','R'), 1024));
loadCastDataVWCR(*_movieArchive->getResource(MKTAG('V','W','C','R'), 1024));
assert(_movieArchive->hasResource(MKTAG('V', 'W', 'C', 'R'), 1024));
loadCastDataVWCR(*_movieArchive->getResource(MKTAG('V', 'W', 'C', 'R'), 1024));
}

if (_movieArchive->hasResource(MKTAG('V','W','A','C'), 1024)) {
loadActions(*_movieArchive->getResource(MKTAG('V','W','A','C'), 1024));
if (_movieArchive->hasResource(MKTAG('V', 'W', 'A', 'C'), 1024)) {
loadActions(*_movieArchive->getResource(MKTAG('V', 'W', 'A', 'C'), 1024));
}

if (_movieArchive->hasResource(MKTAG('V','W','F','I'), 1024)) {
loadFileInfo(*_movieArchive->getResource(MKTAG('V','W','F','I'), 1024));
if (_movieArchive->hasResource(MKTAG('V', 'W', 'F', 'I'), 1024)) {
loadFileInfo(*_movieArchive->getResource(MKTAG('V', 'W', 'F', 'I'), 1024));
}

if (_movieArchive->hasResource(MKTAG('V','W','F','M'), 1024)) {
loadFontMap(*_movieArchive->getResource(MKTAG('V','W','F','M'), 1024));
if (_movieArchive->hasResource(MKTAG('V', 'W', 'F', 'M'), 1024)) {
loadFontMap(*_movieArchive->getResource(MKTAG('V', 'W', 'F', 'M'), 1024));
}

Common::Array<uint16> vwci = _movieArchive->getResourceIDList(MKTAG('V','W','C','I'));
Common::Array<uint16> vwci = _movieArchive->getResourceIDList(MKTAG('V', 'W', 'C', 'I'));
if (vwci.size() > 0) {
for (Common::Array<uint16>::iterator iterator = vwci.begin(); iterator != vwci.end(); ++iterator)
loadCastInfo(*_movieArchive->getResource(MKTAG('V','W','C','I'), *iterator), *iterator);
loadCastInfo(*_movieArchive->getResource(MKTAG('V', 'W', 'C', 'I'), *iterator), *iterator);
}

Common::Array<uint16> cast = _movieArchive->getResourceIDList(MKTAG('C','A','S','t'));
Common::Array<uint16> cast = _movieArchive->getResourceIDList(MKTAG('C', 'A', 'S', 't'));
if (cast.size() > 0) {
for (Common::Array<uint16>::iterator iterator = cast.begin(); iterator != cast.end(); ++iterator) {
Common::SeekableSubReadStreamEndian *stream = _movieArchive->getResource(MKTAG('C', 'A', 'S', 't'), *iterator);
Expand Down Expand Up @@ -444,7 +444,7 @@ void Score::loadCastData(Common::SeekableSubReadStreamEndian &stream, uint16 id,
}

debugC(3, kDebugLoading, "CASt: id: %d type: %x size1: %d size2: %d (%x) size3: %d unk1: %d unk2: %d unk3: %d",
id, castType, size1, size2, size2, size3, unk1, unk2, unk3);
id, castType, size1, size2, size2, size3, unk1, unk2, unk3);

byte *data = (byte *)calloc(size1 + 16, 1); // 16 is for bounding rects
stream.read(data, size1 + 16);
Expand Down Expand Up @@ -717,7 +717,7 @@ void Score::loadCastInfo(Common::SeekableSubReadStreamEndian &stream, uint16 id)
_castsInfo[id] = ci;
}

void Score::gotoloop() {
void Score::gotoLoop() {
// This command has the playback head contonuously return to the first marker to to the left and then loop back.
// If no marker are to the left of the playback head, the playback head continues to the right.
Common::SortedArray<Label *>::iterator i;
Expand All @@ -730,49 +730,71 @@ void Score::gotoloop() {
}
}

void Score::gotonext() {
int Score::getCurrentLabelNumber() {
Common::SortedArray<Label *>::iterator i;

int frame = 0;

for (i = _labels->begin(); i != _labels->end(); ++i) {
if ((*i)->name == _currentLabel) {
if ((*i)->number <= _currentFrame)
frame = (*i)->number;
}

return frame;
}

void Score::gotoNext() {
//we can just try to use the current frame and get the next label
_currentFrame = getNextLabelNumber(_currentFrame);
}

void Score::gotoPrevious() {
//we actually need the frame of the label prior to the most recent label.
_currentFrame = getPreviousLabelNumber(getCurrentLabelNumber());
}

int Score::getNextLabelNumber(int referenceFrame) {
if (_labels == NULL || _labels->size() == 0)
return 0;

Common::SortedArray<Label *>::iterator i;

for (i = _labels->begin(); i != _labels->end(); ++i) {
if ((*i)->number >= referenceFrame) {
if (i != _labels->end()) {
// return to the first marker to to the right
++i;
_currentFrame = (*i)->number;
return;
return (*i)->number;
} else {
// if no markers are to the right of the playback head,
// the playback head goes to the first marker to the left
_currentFrame = (*i)->number;
return;
return (*i)->number;
}
}
}

// If there are not markers to the left,
// the playback head goes to frame 1, (Director frame array start from 1, engine from 0)
_currentFrame = 0;
return 0;
}

void Score::gotoprevious() {
int Score::getPreviousLabelNumber(int referenceFrame) {
if (_labels == NULL || _labels->size() == 0)
return 0;

// One label
if (_labels->begin() == _labels->end()) {
_currentFrame = (*_labels->begin())->number;
return;
}
if (_labels->begin() == _labels->end())
return (*_labels->begin())->number;

Common::SortedArray<Label *>::iterator previous = _labels->begin();
Common::SortedArray<Label *>::iterator i = previous++;
Common::SortedArray<Label *>::iterator i;

for (i = _labels->begin(); i != _labels->end(); ++i, ++previous) {
if ((*i)->name == _currentLabel) {
_currentFrame = (*previous)->number;
return;
} else {
_currentFrame = (*i)->number;
return;
}
for (i = (previous + 1); i != _labels->end(); ++i, ++previous) {
if ((*i)->number >= referenceFrame)
return (*previous)->number;
}
_currentFrame = 0;

return 0;
}

Common::String Score::getString(Common::String str) {
Expand Down
10 changes: 7 additions & 3 deletions engines/director/score.h
Expand Up @@ -61,9 +61,9 @@ class Score {
static int compareLabels(const void *a, const void *b);
void loadArchive();
void setStartToLabel(Common::String label);
void gotoloop();
void gotonext();
void gotoprevious();
void gotoLoop();
void gotoNext();
void gotoPrevious();
void startLoop();
void processEvents();
Archive *getArchive() const { return _movieArchive; };
Expand All @@ -77,6 +77,10 @@ class Score {
void setSpriteCasts();
Graphics::ManagedSurface *getSurface() { return _surface; }

int getPreviousLabelNumber(int referenceFrame);
int getCurrentLabelNumber();
int getNextLabelNumber(int referenceFrame);

private:
void update();
void readVersion(uint32 rid);
Expand Down

0 comments on commit 8638273

Please sign in to comment.