ACCESS: Implemented animation anim methods

This commit is contained in:
Paul Gilbert 2014-08-10 23:17:53 -04:00
parent 69ecc15c02
commit a0b9afded3
3 changed files with 158 additions and 9 deletions

View File

@ -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);
}

View File

@ -36,9 +36,10 @@ class AnimationFrame;
class AnimationFramePart;
class AnimationManager : public Manager {
public:
private:
Common::Array<Animation *> _animationTimers;
AnimationResource *_animation;
public:
Animation *_animStart;
public:
AnimationManager(AccessEngine *vm);
@ -60,16 +61,29 @@ class AnimationResource {
private:
Common::Array<Animation *> _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<AnimationFrame *> _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();

View File

@ -171,7 +171,7 @@ void Scripts::cmdRetPos() {
}
void Scripts::cmdAnim() {
int animId = _data->readUint16LE();
int animId = _data->readByte();
_vm->_animation->animate(animId);
}