Skip to content

Commit

Permalink
DIRECTOR: Add cast pointers to sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Iskrich authored and sev- committed Aug 3, 2016
1 parent 5718268 commit d17805e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 59 deletions.
107 changes: 49 additions & 58 deletions engines/director/score.cpp
Expand Up @@ -64,10 +64,7 @@ Score::Score(Common::SeekableReadStream &stream) {
void Score::loadConfig(Common::SeekableReadStream &stream) {
/*uint16 unk1 = */ stream.readUint16BE();
/*ver1 = */ stream.readUint16BE();
_movieRect.top = stream.readUint16BE();
_movieRect.left = stream.readUint16BE();
_movieRect.bottom = stream.readUint16BE();
_movieRect.right = stream.readUint16BE();
_movieRect = readRect(stream);

_castArrayStart = stream.readUint16BE();
_castArrayEnd = stream.readUint16BE();
Expand All @@ -85,31 +82,38 @@ void Score::readVersion(uint32 rid) {
void Score::loadCastData(Common::SeekableReadStream &stream) {
for (uint16 id = _castArrayStart; id < _castArrayEnd; id++) {
byte size = stream.readByte();
if (size > 0) {
debug("%d", stream.pos());
uint8 castType = stream.readByte();
switch (castType) {
case kCastBitmap:
_casts[id] = getBitmapCast(stream);
_casts[id]->type = kCastBitmap;
break;
case kCastText:
_casts[id] = getTextCast(stream);
_casts[id]->type = kCastText;
break;
case kCastShape:
_casts[id] = getShapeCast(stream);
_casts[id]->type = kCastShape;
break;
case kCastButton:
_casts[id] = getButtonCast(stream);
_casts[id]->type = kCastButton;
break;
default:
warning("Unhandled cast type: %d", castType);
stream.skip(size - 1);
break;
}
if (size == 0)
continue;

uint8 castType = stream.readByte();
switch (castType) {
case kCastBitmap:
_casts[id] = getBitmapCast(stream);
_casts[id]->type = kCastBitmap;
break;
case kCastText:
_casts[id] = getTextCast(stream);
_casts[id]->type = kCastText;
break;
case kCastShape:
_casts[id] = getShapeCast(stream);
_casts[id]->type = kCastShape;
break;
case kCastButton:
_casts[id] = getButtonCast(stream);
_casts[id]->type = kCastButton;
break;
default:
warning("Unhandled cast type: %d", castType);
stream.skip(size - 1);
break;
}
}
//Set cast pointers to sprites
for (uint16 i = 0; i < _frames.size(); i++) {
for (uint16 j = 0; j < _frames[i]->_sprites.size(); j++) {
byte castId = _frames[i]->_sprites[j]->_castId;
_frames[i]->_sprites[j]->_cast = _casts[castId];
}
}
}
Expand All @@ -118,17 +122,8 @@ BitmapCast *Score::getBitmapCast(Common::SeekableReadStream &stream) {
BitmapCast *cast = new BitmapCast();
/*byte flags = */ stream.readByte();
/*uint16 someFlaggyThing = */ stream.readUint16BE();

cast->initialRect.top = stream.readUint16BE();
cast->initialRect.left = stream.readUint16BE();
cast->initialRect.bottom = stream.readUint16BE();
cast->initialRect.right = stream.readUint16BE();

cast->boundingRect.top = stream.readUint16BE();
cast->boundingRect.left = stream.readUint16BE();
cast->boundingRect.bottom = stream.readUint16BE();
cast->boundingRect.right = stream.readUint16BE();

cast->initialRect = readRect(stream);
cast->boundingRect = readRect(stream);
cast->regX = stream.readUint16BE();
cast->regY = stream.readUint16BE();
/*uint16 unk1 =*/ stream.readUint16BE();
Expand All @@ -146,12 +141,7 @@ TextCast *Score::getTextCast(Common::SeekableReadStream &stream) {
cast->textAlign = stream.readUint16BE();
stream.skip(6); //palinfo
/*uint32 unk1 = */ stream.readUint32BE();

cast->initialRect.top = stream.readUint16BE();
cast->initialRect.left = stream.readUint16BE();
cast->initialRect.bottom = stream.readUint16BE();
cast->initialRect.right = stream.readUint16BE();

cast->initialRect = readRect(stream);
cast->textShadow = stream.readByte();
cast->textFlags = stream.readByte();
/*uint16 unk2 =*/ stream.readUint16BE();
Expand All @@ -163,12 +153,7 @@ ShapeCast *Score::getShapeCast(Common::SeekableReadStream &stream) {
/*byte flags = */ stream.readByte();
/*unk1 = */ stream.readByte();
cast->shapeType = stream.readByte();

cast->initialRect.top = stream.readUint16BE();
cast->initialRect.left = stream.readUint16BE();
cast->initialRect.bottom = stream.readUint16BE();
cast->initialRect.right = stream.readUint16BE();

cast->initialRect = readRect(stream);
cast->pattern = stream.readUint16BE();
cast->fgCol = stream.readByte();
cast->bgCol = stream.readByte();
Expand All @@ -188,19 +173,23 @@ ButtonCast *Score::getButtonCast(Common::SeekableReadStream &stream) {
cast->textAlign = stream.readUint16BE();
stream.skip(6); //palinfo
/*uint32 unk1 = */ stream.readUint32BE();

cast->initialRect.top = stream.readUint16BE();
cast->initialRect.left = stream.readUint16BE();
cast->initialRect.bottom = stream.readUint16BE();
cast->initialRect.right = stream.readUint16BE();

cast->initialRect = readRect(stream);
cast->textShadow = stream.readByte();
cast->textFlags = stream.readByte();
/*uint16 unk2 =*/ stream.readUint16BE();
cast->buttonType = stream.readUint16BE();
return cast;
}

Common::Rect Score::readRect(Common::SeekableReadStream &stream) {
Common::Rect rect;
rect.top = stream.readUint16BE();
rect.left = stream.readUint16BE();
rect.bottom = stream.readUint16BE();
rect.right = stream.readUint16BE();
return rect;
}

void Score::play() {
initGraphics(800, 800, true);
uint32 frameId = 0;
Expand Down Expand Up @@ -418,8 +407,10 @@ void Frame::display() {
for (uint16 i = 0; i < CHANNEL_COUNT; i++) {
if (_sprites[i]->_enabled) {
DIBDecoder img;
//TODO check cast type
uint32 castId = 1024 + _sprites[i]->_castId;
img.loadStream(*riff.getResource(MKTAG('D', 'I', 'B', ' '), castId));

g_system->copyRectToScreen(img.getSurface()->getPixels(), img.getSurface()->pitch,
_sprites[i]->_startPoint.x,
_sprites[i]->_startPoint.y,
Expand Down
4 changes: 3 additions & 1 deletion engines/director/score.h
Expand Up @@ -114,8 +114,9 @@ class Sprite {
Sprite();
Sprite(const Sprite &sprite);
bool _enabled;
uint8 _castId;
byte _castId;
//castType type;
Cast *_cast;
uint16 _flags;
Common::Point _startPoint;
uint16 _width;
Expand Down Expand Up @@ -165,6 +166,7 @@ class Score {
TextCast *getTextCast(Common::SeekableReadStream &stream);
ButtonCast *getButtonCast(Common::SeekableReadStream &stream);
ShapeCast *getShapeCast(Common::SeekableReadStream &stream);
Common::Rect readRect(Common::SeekableReadStream &stream);

public:
Common::Array<Frame *> _frames;
Expand Down

0 comments on commit d17805e

Please sign in to comment.