ILLUSIONS: Implement RegionLayer and related code

This commit is contained in:
johndoe123 2014-04-14 13:48:24 +02:00 committed by Eugene Sandulenko
parent e131362590
commit 097d130e7d
6 changed files with 134 additions and 18 deletions

View File

@ -71,11 +71,13 @@ Actor::Actor(IllusionsEngine *vm)
_frames = 0;
_scaleLayer = 0;
_priorityLayer = 0;
_regionLayer = 0;
_position.x = 0;
_position.y = 0;
_position2.x = 0;
_position2.y = 0;
_facing = 64;
_regionIndex = 0;
_fontId = 0;
_actorIndex = 0;
_parentObjectId = 0;
@ -1069,7 +1071,7 @@ void Controls::placeActor(uint32 actorTypeId, Common::Point placePt, uint32 sequ
}
if (actorType->_regionLayerIndex) {
// TODO actor->_regionLayer = bgRes->getPriorityLayer(actorType->_regionLayerIndex - 1);
actor->_regionLayer = bgRes->getRegionLayer(actorType->_regionLayerIndex - 1);
actor->_flags |= 0x20;
}
@ -1355,7 +1357,28 @@ void Controls::actorControlRoutine(Control *control, uint32 deltaTime) {
}
if (actor->_flags & 0x20) {
// TODO Update transition sequence (seems to be unused in BBDOU?)
// Update transition sequence
int regionIndex = actor->_regionLayer->getRegionIndex(actor->_position);
if (actor->_regionIndex != regionIndex) {
if (regionIndex) {
uint32 savedSequenceId = actor->_sequenceId;
byte *savedSeqCodeIp = actor->_seqCodeIp;
int savedSeqCodeValue1 = actor->_seqCodeValue1;
int savedSeqCodeValue3 = actor->_seqCodeValue3;
uint32 regionSequenceId = actor->_regionLayer->getRegionSequenceId(regionIndex);
debug("Running transition sequence %08X", regionSequenceId);
Sequence *sequence = _vm->_dict->findSequence(regionSequenceId);
actor->_sequenceId = regionSequenceId;
actor->_seqCodeIp = sequence->_sequenceCode;
actor->_seqCodeValue3 = 0;
control->sequenceActor();
actor->_sequenceId = savedSequenceId;
actor->_seqCodeIp = savedSeqCodeIp;
actor->_seqCodeValue3 = savedSeqCodeValue3;
actor->_seqCodeValue1 = savedSeqCodeValue1;
}
actor->_regionIndex = regionIndex;
}
}
}

View File

@ -101,6 +101,7 @@ public:
ScaleLayer *_scaleLayer;
PriorityLayer *_priorityLayer;
RegionLayer *_regionLayer;
uint _seqStackCount;
int16 _seqStack[5];
@ -108,6 +109,7 @@ public:
Common::Point _position;
Common::Point _position2;
uint _facing;
int _regionIndex;
uint32 _fontId;
int16 _actorIndex;
@ -129,10 +131,10 @@ public:
ActorControlRoutine *_controlRoutine;
byte *_seqCodeIp;
uint32 _sequenceId;
int _seqCodeValue1;
int _seqCodeValue2;
byte *_seqCodeIp;
int _seqCodeValue1;
int _seqCodeValue3;
int _pathCtrX, _pathCtrY;

View File

@ -23,7 +23,9 @@
#include "illusions/illusions.h"
#include "illusions/backgroundresource.h"
#include "illusions/actor.h"
#include "illusions/actorresource.h"
#include "illusions/camera.h"
#include "illusions/dictionary.h"
#include "illusions/screen.h"
#include "common/str.h"
@ -44,11 +46,15 @@ void BackgroundResourceLoader::load(Resource *resource) {
backgroundItem->_tag = resource->_tag;
backgroundItem->initSurface();
// TODO Insert background objects
// Insert background objects
for (uint i = 0; i < backgroundResource->_backgroundObjectsCount; ++i)
_vm->_controls->placeBackgroundObject(&backgroundResource->_backgroundObjects[i]);
// TODO Insert IDs from item48s
// Insert region sequences
for (uint i = 0; i < backgroundResource->_regionSequencesCount; ++i) {
Sequence *sequence = &backgroundResource->_regionSequences[i];
_vm->_dict->addSequence(sequence->_sequenceId, sequence);
}
// TODO camera_fadeClear();
int index = backgroundItem->_bgRes->findMasterBgIndex();
@ -66,7 +72,10 @@ void BackgroundResourceLoader::unload(Resource *resource) {
// TODO Move to BackgroundItems
BackgroundItem *backgroundItem = _vm->_backgroundItems->findBackgroundByResource((BackgroundResource*)resource->_refId);
backgroundItem->freeSurface();
// TODO Remove IDs from item48s
for (uint i = 0; i < backgroundItem->_bgRes->_regionSequencesCount; ++i) {
Sequence *sequence = &backgroundItem->_bgRes->_regionSequences[i];
_vm->_dict->removeSequence(sequence->_sequenceId);
}
delete backgroundItem->_bgRes;
_vm->_backgroundItems->freeBackgroundItem(backgroundItem);
_vm->setDefaultTextCoords();
@ -154,6 +163,39 @@ int ScaleLayer::getScale(Common::Point pos) {
return _values[pos.y];
}
// RegionLayer
void RegionLayer::load(byte *dataStart, Common::SeekableReadStream &stream) {
_unk = stream.readUint32LE();
uint32 regionSequenceIdsOffs = stream.readUint32LE();
_width = stream.readUint16LE();
_height = stream.readUint16LE();
uint32 mapOffs = stream.readUint32LE();
uint32 valuesOffs = stream.readUint32LE();
_regionSequenceIds = dataStart + regionSequenceIdsOffs;
_map = dataStart + mapOffs;
_values = dataStart + valuesOffs;
_mapWidth = READ_LE_UINT16(_map + 0);
_mapHeight = READ_LE_UINT16(_map + 2);
_map += 8;
debug("RegionLayer::load() %d; regionSequenceIdsOffs: %08X; _width: %d; _height: %d; mapOffs: %08X; valuesOffs: %08X",
_unk, regionSequenceIdsOffs, _width, _height, mapOffs, valuesOffs);
}
int RegionLayer::getRegionIndex(Common::Point pos) {
pos.x = CLIP<int16>(pos.x, 0, _width - 1);
pos.y = CLIP<int16>(pos.y, 0, _height - 1);
const int16 tx = pos.x / 32, sx = pos.x % 32;
const int16 ty = pos.y / 8, sy = pos.y % 8;
uint16 mapIndex = READ_LE_UINT16(_map + 2 * (tx + ty * _mapWidth)) - 1;
return _values[mapIndex * 32 * 8 + sx + sy * 32];
}
uint32 RegionLayer::getRegionSequenceId(int regionIndex) {
return READ_LE_UINT32(_regionSequenceIds + 4 * regionIndex);
}
// Palette
void Palette::load(byte *dataStart, Common::SeekableReadStream &stream) {
@ -227,6 +269,28 @@ void BackgroundResource::load(byte *data, uint32 dataSize) {
_priorityLayers[i].load(data, stream);
}
// Load region layers
stream.seek(0x16);
_regionLayersCount = stream.readUint16LE();
_regionLayers = new RegionLayer[_regionLayersCount];
stream.seek(0x38);
uint32 regionLayersOffs = stream.readUint32LE();
debug("_regionLayersCount: %d", _regionLayersCount);
for (uint i = 0; i < _regionLayersCount; ++i) {
stream.seek(regionLayersOffs + i * 20);
_regionLayers[i].load(data, stream);
}
// Load region sequences
stream.seek(0x1E);
_regionSequencesCount = stream.readUint16LE();
_regionSequences = new Sequence[_regionSequencesCount];
stream.seek(0x48);
uint32 regionSequencesOffs = stream.readUint32LE();
stream.seek(regionSequencesOffs);
for (uint i = 0; i < _regionSequencesCount; ++i)
_regionSequences[i].load(data, stream);
// Load background objects
stream.seek(0x1C);
_backgroundObjectsCount = stream.readUint16LE();
@ -276,6 +340,10 @@ ScaleLayer *BackgroundResource::getScaleLayer(uint index) {
return &_scaleLayers[index];
}
RegionLayer *BackgroundResource::getRegionLayer(uint index) {
return &_regionLayers[index];
}
bool BackgroundResource::findNamedPoint(uint32 namedPointId, Common::Point &pt) {
return _namedPoints.findNamedPoint(namedPointId, pt);
}
@ -374,10 +442,10 @@ void BackgroundItem::pause() {
// TODO
++_pauseCtr;
if (_pauseCtr <= 1) {
/* TODO
for (uint i = 0; i < _bgRes->_item48sCount; ++i)
krndictRemoveID(_bgRes->_item48s[i].id);
*/
for (uint i = 0; i < _bgRes->_regionSequencesCount; ++i) {
Sequence *sequence = &_bgRes->_regionSequences[i];
_vm->_dict->removeSequence(sequence->_sequenceId);
}
_vm->setDefaultTextCoords();
_vm->_camera->getActiveState(_savedCameraState);
_savedPalette = new byte[1024];
@ -390,10 +458,10 @@ void BackgroundItem::unpause() {
// TODO
--_pauseCtr;
if (_pauseCtr <= 0) {
/* TODO
for (uint i = 0; i < _bgRes->_item48sCount; ++i)
krndictAddID(_bgRes->_item48s[i].id, _bgRes->_item48s[i]);
*/
for (uint i = 0; i < _bgRes->_regionSequencesCount; ++i) {
Sequence *sequence = &_bgRes->_regionSequences[i];
_vm->_dict->addSequence(sequence->_sequenceId, sequence);
}
initSurface();
_vm->_screen->setPalette(_savedPalette, 1, 256);
delete[] _savedPalette;

View File

@ -39,6 +39,7 @@
namespace Illusions {
class IllusionsEngine;
struct Sequence;
class BackgroundResourceLoader : public BaseResourceLoader {
public:
@ -89,6 +90,20 @@ protected:
byte *_values;
};
class RegionLayer {
public:
void load(byte *dataStart, Common::SeekableReadStream &stream);
int getRegionIndex(Common::Point pos);
uint32 getRegionSequenceId(int regionIndex);
protected:
uint32 _unk;
byte *_regionSequenceIds;
int16 _width, _height;
int16 _mapWidth, _mapHeight;
byte *_map, *_values;
};
#if 0
BgResource_PathWalkRects struc ; (sizeof=0x8)
count dd ?
@ -124,6 +139,7 @@ public:
int findMasterBgIndex();
PriorityLayer *getPriorityLayer(uint index);
ScaleLayer *getScaleLayer(uint index);
RegionLayer *getRegionLayer(uint index);
bool findNamedPoint(uint32 namedPointId, Common::Point &pt);
public:
@ -137,7 +153,13 @@ public:
uint _scaleLayersCount;
ScaleLayer *_scaleLayers;
uint _regionLayersCount;
RegionLayer *_regionLayers;
uint _regionSequencesCount;
Sequence *_regionSequences;
uint _backgroundObjectsCount;
BackgroundObject *_backgroundObjects;

View File

@ -242,7 +242,7 @@ void ScriptOpcodes_Duckman::opEnterScene18(ScriptThread *scriptThread, OpCall &o
_vm->enterScene(sceneId, 0);
}
static uint dsceneId = 0, dthreadId = 0;
//static uint dsceneId = 0, dthreadId = 0;
//static uint dsceneId = 0x00010008, dthreadId = 0x00020029;//Beginning in Jac
//static uint dsceneId = 0x00010012, dthreadId = 0x0002009D;//Paramount
//static uint dsceneId = 0x00010039, dthreadId = 0x00020089;//Map
@ -252,6 +252,7 @@ static uint dsceneId = 0, dthreadId = 0;
//static uint dsceneId = 0x0001002D, dthreadId = 0x00020141;
//static uint dsceneId = 0x0001004B, dthreadId = 0x0002029B;
//static uint dsceneId = 0x00010021, dthreadId = 0x00020113;
static uint dsceneId = 0x0001000A, dthreadId = 0x00020043;
void ScriptOpcodes_Duckman::opChangeScene(ScriptThread *scriptThread, OpCall &opCall) {
ARG_SKIP(2);

View File

@ -332,7 +332,7 @@ void SequenceOpcodes::opSetRegionLayer(Control *control, OpCall &opCall) {
ARG_INT16(regionLayerIndex);
BackgroundResource *bgRes = _vm->_backgroundItems->getActiveBgResource();
control->_actor->_flags |= 0x20;
//TODO control->_actor->_regionLayer = bgRes->getRegionLayer(regionLayerIndex - 1);
control->_actor->_regionLayer = bgRes->getRegionLayer(regionLayerIndex - 1);
}
void SequenceOpcodes::opPlaySound(Control *control, OpCall &opCall) {