From a0b9afded37693673485549d41d3b3513bcb2dab Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Aug 2014 23:17:53 -0400 Subject: ACCESS: Implemented animation anim methods --- engines/access/animation.cpp | 143 +++++++++++++++++++++++++++++++++++++++++-- engines/access/animation.h | 22 +++++-- engines/access/scripts.cpp | 2 +- 3 files changed, 158 insertions(+), 9 deletions(-) (limited to 'engines/access') diff --git a/engines/access/animation.cpp b/engines/access/animation.cpp index 0d8589d4f1..705fd7bf8f 100644 --- a/engines/access/animation.cpp +++ b/engines/access/animation.cpp @@ -22,11 +22,12 @@ #include "common/endian.h" #include "common/memstream.h" +#include "access/access.h" #include "access/animation.h" namespace Access { -AnimationResource::AnimationResource(const byte *data, int size) { +AnimationResource::AnimationResource(AccessEngine *vm, const byte *data, int size) { Common::MemoryReadStream stream(data, size); int count = stream.readUint16LE(); @@ -37,7 +38,7 @@ AnimationResource::AnimationResource(const byte *data, int size) { _animations.reserve(count); for (int i = 0; i < count; ++i) { stream.seek(offsets[i]); - Animation *anim = new Animation(stream); + Animation *anim = new Animation(vm, stream); _animations.push_back(anim); } } @@ -49,7 +50,8 @@ AnimationResource::~AnimationResource() { /*------------------------------------------------------------------------*/ -Animation::Animation(Common::MemoryReadStream &stream) { +Animation::Animation(AccessEngine *vm, Common::MemoryReadStream &stream): + Manager(vm) { uint32 startOfs = stream.pos(); _type = stream.readByte(); @@ -82,10 +84,143 @@ Animation::~Animation() { delete _frames[i]; } +typedef void(Animation::*AnimationMethodPtr)(); + void Animation::animate() { + static const AnimationMethodPtr METHODS[8] = + { &Animation::anim0, &Animation::anim1, &Animation::anim2, &Animation::anim3, + &Animation::anim4, &Animation::animNone, &Animation::animNone, &Animation::anim7 }; + + (this->*METHODS[_type])(); +} + +void Animation::anim0() { + if (_currentLoopCount != -1) { + if (_countdownTicks != 0) { + calcFrame(); + setFrame1(); + } else { + _countdownTicks = _initialTicks; + ++_frameNumber; + calcFrame(); + + if (this == _vm->_animation->_animStart) { + _frameNumber = 0; + _currentLoopCount = -1; + } + + setFrame(); + } + } +} + +void Animation::anim1() { + if (_currentLoopCount == -1 || _countdownTicks != 0) { + calcFrame(); + setFrame1(); + } else { + _countdownTicks = _initialTicks; + ++_frameNumber; + calcFrame(); + + if (this == _vm->_animation->_animStart) { + --_frameNumber; + _currentLoopCount = -1; + } + + setFrame(); + } +} + +void Animation::anim2() { + if (_countdownTicks != 0) { + calcFrame(); + setFrame1(); + } else { + _countdownTicks = _initialTicks; + ++_frameNumber; + calcFrame(); + + if (this == _vm->_animation->_animStart) { + _frameNumber = 0; + calcFrame(); + } + + setFrame(); + } +} + +void Animation::anim3() { + if (_currentLoopCount != -1) { + if (_countdownTicks != 0) { + calcFrame(); + setFrame1(); + } else { + _countdownTicks = _initialTicks; + ++_frameNumber; + calcFrame(); + + if (this == _vm->_animation->_animStart) { + --_currentLoopCount; + _frameNumber = 0; + calcFrame(); + } + + setFrame(); + } + } +} + +void Animation::anim4() { + if (_currentLoopCount == -1 || _countdownTicks != 0) { + calcFrame(); + setFrame1(); + } else { + _countdownTicks = _initialTicks; + ++_frameNumber; + calcFrame(); + + if (this == _vm->_animation->_animStart) { + if (--_currentLoopCount == -1) { + calcFrame(); + setFrame1(); + return; + } else { + _frameNumber = 0; + calcFrame(); + } + } + + setFrame(); + } +} + +void Animation::animNone() { + // No implementation +} + +void Animation::anim7() { + calcFrame1(); + setFrame(); +} + +void Animation::calcFrame() { + error("TODO"); +} + +void Animation::calcFrame1() { + error("TODO"); +} + +void Animation::setFrame() { error("TODO"); } +void Animation::setFrame1() { + error("TODO"); +} + + /*------------------------------------------------------------------------*/ AnimationFrame::AnimationFrame(Common::MemoryReadStream &stream, int startOffset) { @@ -150,7 +285,7 @@ void AnimationManager::clearTimers() { void AnimationManager::loadAnimations(const byte *data, int size) { _animationTimers.clear(); delete _animation; - _animation = new AnimationResource(data, size); + _animation = new AnimationResource(_vm, data, size); } diff --git a/engines/access/animation.h b/engines/access/animation.h index 45a59efb68..38065bb4c9 100644 --- a/engines/access/animation.h +++ b/engines/access/animation.h @@ -36,9 +36,10 @@ class AnimationFrame; class AnimationFramePart; class AnimationManager : public Manager { -public: +private: Common::Array _animationTimers; AnimationResource *_animation; +public: Animation *_animStart; public: AnimationManager(AccessEngine *vm); @@ -60,16 +61,29 @@ class AnimationResource { private: Common::Array _animations; public: - AnimationResource(const byte *data, int size); + AnimationResource(AccessEngine *vm, const byte *data, int size); ~AnimationResource(); int getCount() { return _animations.size(); } Animation *getAnimation(int idx) { return _animations[idx]; } }; -class Animation { +class Animation: public Manager { private: Common::Array _frames; + + void anim0(); + void anim1(); + void anim2(); + void anim3(); + void anim4(); + void animNone(); + void anim7(); + + void calcFrame(); + void calcFrame1(); + void setFrame(); + void setFrame1(); public: int _type; int _scaling; @@ -80,7 +94,7 @@ public: int _currentLoopCount; int _field10; public: - Animation(Common::MemoryReadStream &stream); + Animation(AccessEngine *vm, Common::MemoryReadStream &stream); ~Animation(); void animate(); diff --git a/engines/access/scripts.cpp b/engines/access/scripts.cpp index fd42530eb9..8018f503a3 100644 --- a/engines/access/scripts.cpp +++ b/engines/access/scripts.cpp @@ -171,7 +171,7 @@ void Scripts::cmdRetPos() { } void Scripts::cmdAnim() { - int animId = _data->readUint16LE(); + int animId = _data->readByte(); _vm->_animation->animate(animId); } -- cgit v1.2.3