diff options
author | Paul Gilbert | 2010-07-04 12:45:33 +0000 |
---|---|---|
committer | Paul Gilbert | 2010-07-04 12:45:33 +0000 |
commit | 587ba8a90ee1d85cab07107293d96311fcc00c50 (patch) | |
tree | 987631a7d6876f10996e3a7f9d526d95a281123a /engines/m4 | |
parent | dde6dabac9d6ae6f86cec11607ac15cb748aaf73 (diff) | |
download | scummvm-rg350-587ba8a90ee1d85cab07107293d96311fcc00c50.tar.gz scummvm-rg350-587ba8a90ee1d85cab07107293d96311fcc00c50.tar.bz2 scummvm-rg350-587ba8a90ee1d85cab07107293d96311fcc00c50.zip |
Implemented more of the support methods for player display
svn-id: r50644
Diffstat (limited to 'engines/m4')
-rw-r--r-- | engines/m4/assets.cpp | 37 | ||||
-rw-r--r-- | engines/m4/assets.h | 23 | ||||
-rw-r--r-- | engines/m4/mads_player.cpp | 100 | ||||
-rw-r--r-- | engines/m4/mads_player.h | 17 | ||||
-rw-r--r-- | engines/m4/mads_views.cpp | 10 | ||||
-rw-r--r-- | engines/m4/mads_views.h | 3 |
6 files changed, 178 insertions, 12 deletions
diff --git a/engines/m4/assets.cpp b/engines/m4/assets.cpp index 0c0bf330a7..9cfb7afc4c 100644 --- a/engines/m4/assets.cpp +++ b/engines/m4/assets.cpp @@ -98,7 +98,8 @@ long *DataAsset::getRow(int index) { return &_data[_recSize * index]; } -SpriteAsset::SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int size, const char *name, bool asStream) : +SpriteAsset::SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int size, const char *name, + bool asStream, int flags) : BaseAsset(vm) { _stream = stream; _palInterface = NULL; @@ -107,7 +108,7 @@ SpriteAsset::SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, i if (_vm->isM4()) { loadM4SpriteAsset(vm, stream, asStream); } else { - loadMadsSpriteAsset(vm, stream); + loadMadsSpriteAsset(vm, stream, flags); } } @@ -119,7 +120,7 @@ SpriteAsset::SpriteAsset(MadsM4Engine *vm, const char *name): BaseAsset(vm) { if (_vm->isM4()) { loadM4SpriteAsset(vm, _stream, true); } else { - loadMadsSpriteAsset(vm, _stream); + loadMadsSpriteAsset(vm, _stream, 0); } vm->res()->toss(name); @@ -136,6 +137,8 @@ SpriteAsset::~SpriteAsset() { for (Common::Array<SpriteAssetFrame>::iterator it = _frames.begin(); it != _frames.end(); ++it) { delete (*it).frame; } + + delete _charInfo; } void SpriteAsset::loadM4SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, bool asStream) { @@ -200,7 +203,7 @@ void SpriteAsset::loadM4SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream } -void SpriteAsset::loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream) { +void SpriteAsset::loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int flags) { int curFrame = 0; uint32 frameOffset = 0; MadsPack sprite(stream); @@ -217,7 +220,12 @@ void SpriteAsset::loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStre _isBackground = (type1 != 0) && (type2 < 4); spriteStream->skip(32); _frameCount = spriteStream->readUint16LE(); - // we skip the rest of the data + + if (_vm->isM4() || ((flags & SPRITE_SET_CHAR_INFO) == 0)) + _charInfo = NULL; + else + _charInfo = new MadsSpriteSetCharInfo(spriteStream); + delete spriteStream; // Get the palette data @@ -621,4 +629,23 @@ int32 AssetManager::getSpriteFrameCount(int32 hash) { return _CELS[hash]->getCount(); } +//-------------------------------------------------------------------------- + +MadsSpriteSetCharInfo::MadsSpriteSetCharInfo(Common::SeekableReadStream *s) { + _frameNumber = s->readByte(); + s->skip(1); + _hasIdling = s->readUint16LE() != 0; + + for (int i = 0; i < 16; ++i) + _frameList[i] = s->readUint16LE(); + for (int i = 0; i < 16; ++i) + _frameList2[i] = s->readUint16LE(); + for (int i = 0; i < 16; ++i) + _ticksList[i] = s->readUint16LE(); + + _unk1 = s->readUint16LE(); + _ticksAmount = s->readByte(); + _yScale = s->readByte(); +} + } // End of namespace M4 diff --git a/engines/m4/assets.h b/engines/m4/assets.h index e5beffbcae..e9902d8aa6 100644 --- a/engines/m4/assets.h +++ b/engines/m4/assets.h @@ -44,6 +44,8 @@ namespace M4 { #define CELS__PAL MKID_BE(' PAL') //' PAL' #define CELS___SS MKID_BE(' SS') //' SS' +#define SPRITE_SET_CHAR_INFO 4 + class MadsM4Engine; class Palette; @@ -100,13 +102,28 @@ struct SpriteAssetFrame { M4Sprite *frame; }; +class MadsSpriteSetCharInfo { +public: + MadsSpriteSetCharInfo(Common::SeekableReadStream *s); + + int _frameNumber; + int _hasIdling; + int _frameList2[16]; + int _frameList[16]; + int _ticksList[16]; + int _unk1; + int _ticksAmount; + int _yScale; +}; + class SpriteAsset : public BaseAsset { public: - SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int size, const char *name, bool asStream = false); + SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int size, const char *name, + bool asStream = false, int flags = 0); SpriteAsset(MadsM4Engine *vm, const char *name); ~SpriteAsset(); void loadM4SpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, bool asStream); - void loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream); + void loadMadsSpriteAsset(MadsM4Engine *vm, Common::SeekableReadStream* stream, int flags); int32 getCount() { return _frameCount; } int32 getFrameRate() const { return _frameRate; } int32 getPixelSpeed() const { return _pixelSpeed; } @@ -124,6 +141,8 @@ public: void translate(Palette *palette); int32 getFrameSize(int index); M4Sprite *operator[](int index) { return getFrame(index); } +public: + MadsSpriteSetCharInfo *_charInfo; protected: Common::SeekableReadStream *_stream; RGB8 _palette[256]; diff --git a/engines/m4/mads_player.cpp b/engines/m4/mads_player.cpp index 53ee857093..2ba009459e 100644 --- a/engines/m4/mads_player.cpp +++ b/engines/m4/mads_player.cpp @@ -29,6 +29,10 @@ namespace M4 { +const int MadsPlayer::_directionListIndexes[32] = { + 0, 7, 4, 3, 6, 0, 2, 5, 0, 1, 9, 4, 1, 2, 7, 9, 3, 8, 9, 6, 7, 2, 3, 6, 1, 7, 9, 4, 7, 8, 0, 0 +}; + MadsPlayer::MadsPlayer() { _playerPos = Common::Point(160, 78); _direction = 0; @@ -48,6 +52,11 @@ MadsPlayer::MadsPlayer() { _spriteSetIndexes[idx] = 0; _frameNum = 0; _frameOffset = 0; + _unk1 = 0; + _newFrame = 0; + _frameListIndex = 0; + _actionIndex = 0; + resetActionList(); } /** @@ -79,7 +88,7 @@ bool MadsPlayer::loadSprites(const char *prefix) { *digitP = suffixList[idx]; _spriteSetIndexes[idx] = -1; - int setIndex = _madsVm->scene()->_spriteSlots.addSprites(setName, true); + int setIndex = _madsVm->scene()->_spriteSlots.addSprites(setName, true, SPRITE_SET_CHAR_INFO); if (setIndex < 0) { if (idx < 7) break; @@ -165,7 +174,66 @@ void MadsPlayer::update() { _forceRefresh = false; } +/** + * Idling animation for player + */ void MadsPlayer::idle() { + SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2); + assert(spriteSet._charInfo); + + if (!spriteSet._charInfo->_hasIdling) { + _frameNum = 1; + } else { + _frameListIndex = _actionList[_actionIndex]; + + if (!_visible) { + _unk2 = 0; + } else { + _unk2 = _actionList2[_actionIndex]; + + if (_actionIndex > 0) + --_actionIndex; + } + + // Set the player frame number + int frameIndex = ABS(_frameListIndex); + _frameNum = (_frameListIndex <= 0) ? spriteSet._charInfo->_frameList[frameIndex] : + spriteSet._charInfo->_frameList2[frameIndex]; + + // Set next waiting period in ticks + if (frameIndex == 0) + setTicksAmount(); + else + _madsVm->scene()->_ticksAmount = spriteSet._charInfo->_ticksList[frameIndex]; + } +} + +void MadsPlayer::setupFrame() { + resetActionList(); + _frameOffset = 0; + _spriteListIdx2 = _directionListIndexes[_direction]; + if (_spriteSetIndexes[_spriteListIdx2] == 0) { + _spriteListIdx2 = 4; + _frameOffset = 0x8000; + } + + SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2); + assert(spriteSet._charInfo); + _unk1 = MAX(spriteSet._charInfo->_unk1, 100); + setTicksAmount(); + + _newFrame = spriteSet._charInfo->_frameNumber; + if (_newFrame == 0) + _newFrame = spriteSet.getCount(); + + _yScale = spriteSet._charInfo->_yScale; + + if ((_frameNum <= 0) || (_frameNum > _newFrame)) + _frameNum = 1; + _forceRefresh = true; +} + +void MadsPlayer::step() { } @@ -190,4 +258,34 @@ int MadsPlayer::getSpriteSlot() { return -1; } +void MadsPlayer::setTicksAmount() { + SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2); + assert(spriteSet._charInfo); + _madsVm->scene()->_ticksAmount = spriteSet._charInfo->_ticksAmount; + if (_madsVm->scene()->_ticksAmount == 0) + _madsVm->scene()->_ticksAmount = 6; +} + +void MadsPlayer::resetActionList() { + _actionList[0] = 0; + _actionList2[0] = 0; + _actionIndex = 0; + _unk2 = 0; + _unk3 = 0; +} + +int MadsPlayer::queueAction(int action1, int action2) { + SpriteAsset &spriteSet = _madsVm->scene()->_spriteSlots.getSprite(_spriteListIdx + _spriteListIdx2); + assert(spriteSet._charInfo); + + if ((spriteSet._charInfo->_hasIdling) && (_actionIndex < 11)) { + ++_actionIndex; + _actionList[_actionIndex] = action1; + _actionList2[_actionIndex] = action2; + return false; + } + + return true; +} + } // End of namespace M4 diff --git a/engines/m4/mads_player.h b/engines/m4/mads_player.h index c84c1d0c60..0a746575f1 100644 --- a/engines/m4/mads_player.h +++ b/engines/m4/mads_player.h @@ -36,6 +36,9 @@ class MadsPlayer { private: int getScale(int yp); int getSpriteSlot(); + void setTicksAmount(); + void resetActionList(); + int queueAction(int v0, int v1); public: char _spritesPrefix[16]; int _spriteSetCount; @@ -51,14 +54,26 @@ public: int16 _currentDepth; int16 _spriteListIdx, _spriteListIdx2; bool _spritesChanged; - int16 _frameOffset, _frameNum; + uint16 _frameOffset, _frameNum; bool _moving; + int _unk1; + int _newFrame; + int _frameListIndex; + int _actionIndex; + int _actionList[12]; + int _actionList2[12]; + int _unk2; + int _unk3; + + static const int _directionListIndexes[32]; public: MadsPlayer(); bool loadSprites(const char *prefix); void update(); void idle(); + void setupFrame(); + void step(); }; } // End of namespace M4 diff --git a/engines/m4/mads_views.cpp b/engines/m4/mads_views.cpp index 9845db7203..d6d71c8eee 100644 --- a/engines/m4/mads_views.cpp +++ b/engines/m4/mads_views.cpp @@ -86,7 +86,7 @@ int MadsSpriteSlots::getIndex() { return startIndex++; } -int MadsSpriteSlots::addSprites(const char *resName, bool suppressErrors) { +int MadsSpriteSlots::addSprites(const char *resName, bool suppressErrors, int flags) { // If errors are suppressed, first check if the resource exists if (suppressErrors) { if (!_vm->res()->resourceExists(resName)) @@ -95,7 +95,7 @@ int MadsSpriteSlots::addSprites(const char *resName, bool suppressErrors) { // Get the sprite set Common::SeekableReadStream *data = _vm->res()->get(resName); - SpriteAsset *spriteSet = new SpriteAsset(_vm, data, data->size(), resName); + SpriteAsset *spriteSet = new SpriteAsset(_vm, data, data->size(), resName, flags); spriteSet->translate(_madsVm->_palette); assert(spriteSet != NULL); @@ -105,6 +105,12 @@ int MadsSpriteSlots::addSprites(const char *resName, bool suppressErrors) { return _sprites.size() - 1; } +int MadsSpriteSlots::addSprites(SpriteAsset *spriteSet) { + _sprites.push_back(spriteSet); + + return _sprites.size() - 1; +} + void MadsSpriteSlots::deleteSprites(int listIndex) { if (listIndex < 0) return; diff --git a/engines/m4/mads_views.h b/engines/m4/mads_views.h index 38c7ed0712..ead6ae94bf 100644 --- a/engines/m4/mads_views.h +++ b/engines/m4/mads_views.h @@ -92,7 +92,8 @@ public: } int getIndex(); - int addSprites(const char *resName, bool suppressErrors = false); + int addSprites(const char *resName, bool suppressErrors = false, int flags = 0); + int addSprites(SpriteAsset *spriteSet); void deleteSprites(int listIndex); void clear(); void deleteTimer(int seqIndex); |