DRAGONS: Work on executing actor sequences

This commit is contained in:
Eric Fry 2018-12-18 22:52:18 +11:00 committed by Eugene Sandulenko
parent ac1f5a5984
commit 012652068f
8 changed files with 45 additions and 4 deletions

View file

@ -120,4 +120,8 @@ void Actor::updateSequence(uint16 newSequenceID) {
flags |= Dragons::ACTOR_FLAG_1;
}
void Actor::resetSequenceIP() {
_seqCodeIp = _actorResource->getSequenceData(_sequenceID);
}
} // End of namespace Dragons

View file

@ -73,7 +73,7 @@ public:
ActorResource*_actorResource;
uint16 actorFileDictionaryIndex;
int16 resourceID;
int16 _seqCodeIp;
byte *_seqCodeIp;
void* frame_pointer_maybe;
uint16 field_c;
int16 var_e;
@ -109,6 +109,7 @@ public:
void init(ActorResource *resource, int16 x, int16 y, uint32 sequenceID);
Graphics::Surface *getCurrentFrame();
void updateSequence(uint16 newSequenceID);
void resetSequenceIP();
};
} // End of namespace Dragons

View file

@ -47,8 +47,9 @@ ActorResource *ActorResourceLoader::load(uint32 resourceId) {
}
bool ActorResource::load(byte *dataStart, Common::SeekableReadStream &stream) {
_data = dataStart;
stream.seek(0x6);
uint16 sequenceOffset = stream.readUint16LE();
_sequenceTableOffset = stream.readUint16LE();
uint16 frameOffset = stream.readUint16LE();
uint16 paletteOffset = stream.readUint16LE();
@ -153,4 +154,10 @@ ActorFrame *ActorResource::getFrameHeader(uint16 frameNumber) {
return &_frames[frameNumber];
}
byte *ActorResource::getSequenceData(int16 sequenceId)
{
uint16 offset = READ_LE_UINT16(_data + _sequenceTableOffset + (sequenceId * 2));
return &_data[offset];
}
} // End of namespace Dragons

View file

@ -50,15 +50,19 @@ public:
class ActorResource {
private:
byte *data;
byte *_data;
ActorFrame *_frames;
uint16 _framesCount;
byte _palette[512];
uint16 _sequenceTableOffset;
uint16 _sequenceCount;
public:
bool load(byte *dataStart, Common::SeekableReadStream &stream);
Graphics::Surface *loadFrame(uint16 frameNumber);
ActorFrame *getFrameHeader(uint16 frameNumber);
byte *getSequenceData(int16 sequenceId);
private:
void writePixelBlock(byte *pixels, byte *data);
};

View file

@ -31,6 +31,7 @@
#include "dragons.h"
#include "scene.h"
#include "screen.h"
#include "sequenceopcodes.h"
namespace Dragons {
@ -43,10 +44,11 @@ DragonsEngine::DragonsEngine(OSystem *syst) : Engine(syst) {
_screen = NULL;
_nextUpdatetime = 0;
_flags = 0;
_sequenceOpcodes = new SequenceOpcodes(this);
}
DragonsEngine::~DragonsEngine() {
delete _sequenceOpcodes;
}
void DragonsEngine::updateEvents() {
@ -179,7 +181,19 @@ void DragonsEngine::updateActorSequences() {
!(actor->flags & Dragons::ACTOR_FLAG_400) &&
(actor->frameIndex_maybe == 0 || actor->flags & Dragons::ACTOR_FLAG_1)) {
debug("Actor[%d] execute sequenceOp", actorId);
if (actor->flags & Dragons::ACTOR_FLAG_1) {
actor->resetSequenceIP();
actor->flags &= 0xeff6; //TODO rewrite using ACTOR_FLAG_nnn
actor->field_7a = 0;
}
//TODO execute sequence Opcode here.
OpCall opCall;
opCall._op = (byte)READ_LE_UINT16(actor->_seqCodeIp);
opCall._opSize = (byte)READ_LE_UINT16(actor->_seqCodeIp + 2);
opCall._code = actor->_seqCodeIp + 4;
opCall._deltaOfs = opCall._opSize;
_sequenceOpcodes->execOpcode(actor, opCall);
return;
}
}

View file

@ -71,6 +71,7 @@ class DragonINIResource;
class Scene;
class Screen;
class ActorManager;
class SequenceOpcodes;
class DragonsEngine : public Engine {
private:
@ -81,6 +82,7 @@ private:
BackgroundResourceLoader *_backgroundResourceLoader;
ActorManager *_actorManager;
Scene *_scene;
SequenceOpcodes *_sequenceOpcodes;
uint32 _nextUpdatetime;
uint32 _flags;

View file

@ -78,6 +78,9 @@ void SequenceOpcodes::initOpcodes() {
// Register opcodes
OPCODE(1, opSetFramePointer);
OPCODE(4, opSetFieldC);
}
#undef OPCODE
@ -97,6 +100,11 @@ void SequenceOpcodes::opSetFramePointer(Actor *actor, OpCall &opCall) {
actor->frameIndex_maybe = actor->field_c;
}
void SequenceOpcodes::opSetFieldC(Actor *actor, OpCall &opCall) {
ARG_INT16(newFieldC);
actor->field_c = (uint16)newFieldC;
}
//void SequenceOpcodes::opYield(Control *control, OpCall &opCall) {
// opCall._result = 2;
//}

View file

@ -67,6 +67,7 @@ protected:
// Opcodes
void opSetFramePointer(Actor *actor, OpCall &opCall);
void opSetFieldC(Actor *actor, OpCall &opCall);
};