aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjohndoe1232014-12-01 14:14:02 +0100
committerEugene Sandulenko2018-07-20 06:43:33 +0000
commite4ce8ad4c9e9c5156270bb4c1c6f4952a011b70f (patch)
tree42700fc258076ed7cb2b3e27656b2bd5d6ae3ff7
parentd7dd74cbe99f8d6d8072f828707e89e43517caca (diff)
downloadscummvm-rg350-e4ce8ad4c9e9c5156270bb4c1c6f4952a011b70f.tar.gz
scummvm-rg350-e4ce8ad4c9e9c5156270bb4c1c6f4952a011b70f.tar.bz2
scummvm-rg350-e4ce8ad4c9e9c5156270bb4c1c6f4952a011b70f.zip
ILLUSIONS: Start refactoring the resource system (not done yet)
-rw-r--r--engines/illusions/actor.cpp8
-rw-r--r--engines/illusions/actorresource.cpp162
-rw-r--r--engines/illusions/actorresource.h27
-rw-r--r--engines/illusions/backgroundresource.cpp176
-rw-r--r--engines/illusions/backgroundresource.h25
-rw-r--r--engines/illusions/camera.cpp8
-rw-r--r--engines/illusions/camera.h4
-rw-r--r--engines/illusions/fontresource.cpp30
-rw-r--r--engines/illusions/fontresource.h11
-rw-r--r--engines/illusions/illusions.cpp8
-rw-r--r--engines/illusions/illusions.h12
-rw-r--r--engines/illusions/illusions_bbdou.cpp12
-rw-r--r--engines/illusions/illusions_duckman.cpp12
-rw-r--r--engines/illusions/resourcesystem.cpp19
-rw-r--r--engines/illusions/resourcesystem.h26
-rw-r--r--engines/illusions/scriptresource.cpp29
-rw-r--r--engines/illusions/scriptresource.h9
-rw-r--r--engines/illusions/sequenceopcodes.cpp12
-rw-r--r--engines/illusions/soundresource.cpp6
-rw-r--r--engines/illusions/talkresource.cpp91
-rw-r--r--engines/illusions/talkresource.h21
21 files changed, 392 insertions, 316 deletions
diff --git a/engines/illusions/actor.cpp b/engines/illusions/actor.cpp
index b524c02e5c..65eff5d1ed 100644
--- a/engines/illusions/actor.cpp
+++ b/engines/illusions/actor.cpp
@@ -688,7 +688,7 @@ void Control::startSubSequence(int linkIndex, uint32 sequenceId) {
Sequence *sequence = _vm->_dict->findSequence(sequenceId);
linkedActor->_seqCodeIp = sequence->_sequenceCode;
- linkedActor->_frames = _vm->_actorItems->findSequenceFrames(sequence);
+ linkedActor->_frames = _vm->findActorSequenceFrames(sequence);
linkedActor->_seqCodeValue3 = 0;
linkedActor->_seqCodeValue1 = 0;
linkedActor->_seqCodeValue2 = 600;
@@ -778,7 +778,7 @@ PointArray *Control::createPath(Common::Point destPt) {
PointArray *walkPoints = (_actor->_flags & 2) ? _actor->_pathWalkPoints->_points : 0;
PathLines *walkRects = (_actor->_flags & 0x10) ? _actor->_pathWalkRects->_rects : 0;
PathFinder pathFinder;
- WidthHeight bgDimensions = _vm->_backgroundItems->getMasterBgDimensions();
+ WidthHeight bgDimensions = _vm->_backgroundInstances->getMasterBgDimensions();
PointArray *path = pathFinder.findPath(_actor->_position, destPt, walkPoints, walkRects, bgDimensions);
for (uint i = 0; i < path->size(); ++i) {
debug(0, "Path(%d) (%d, %d)", i, (*path)[i].x, (*path)[i].y);
@@ -963,7 +963,7 @@ void Control::startSequenceActorIntern(uint32 sequenceId, int value, byte *entry
}
_actor->_seqCodeIp = sequence->_sequenceCode;
- _actor->_frames = _vm->_actorItems->findSequenceFrames(sequence);
+ _actor->_frames = _vm->findActorSequenceFrames(sequence);
_actor->_seqCodeValue3 = 0;
_actor->_seqCodeValue1 = 0;
@@ -1052,7 +1052,7 @@ void Controls::placeActor(uint32 actorTypeId, Common::Point placePt, uint32 sequ
actor->_scale = actorType->_scale;
actor->_namedPoints = &actorType->_namedPoints;
- BackgroundResource *bgRes = _vm->_backgroundItems->getActiveBgResource();
+ BackgroundResource *bgRes = _vm->_backgroundInstances->getActiveBgResource();
if (actorType->_pathWalkPointsIndex) {
actor->_pathWalkPoints = bgRes->getPathWalkPoints(actorType->_pathWalkPointsIndex - 1);
actor->_flags |= 0x02;
diff --git a/engines/illusions/actorresource.cpp b/engines/illusions/actorresource.cpp
index bcff52288a..43cb314709 100644
--- a/engines/illusions/actorresource.cpp
+++ b/engines/illusions/actorresource.cpp
@@ -29,52 +29,11 @@ namespace Illusions {
// ActorResourceLoader
void ActorResourceLoader::load(Resource *resource) {
- debug("ActorResourceLoader::load() Loading actor %08X from %s...", resource->_resId, resource->_filename.c_str());
-
- ActorResource *actorResource = new ActorResource();
- actorResource->load(resource);
- resource->_refId = actorResource;
-
- ActorItem *actorItem = _vm->_actorItems->allocActorItem();
- actorItem->_tag = resource->_tag;
- actorItem->_pauseCtr = 0;
- actorItem->_actRes = actorResource;
-
- for (uint i = 0; i < actorResource->_actorTypes.size(); ++i) {
- ActorType *actorType = &actorResource->_actorTypes[i];
- ActorType *actorType2 = _vm->_dict->findActorType(actorType->_actorTypeId);
- if (actorType2) {
- actorType->_surfInfo._dimensions._width = MAX(actorType->_surfInfo._dimensions._width,
- actorType2->_surfInfo._dimensions._width);
- actorType->_surfInfo._dimensions._height = MAX(actorType->_surfInfo._dimensions._height,
- actorType2->_surfInfo._dimensions._height);
- if (actorType->_color.r == 255 && actorType->_color.g == 255 && actorType->_color.b == 255)
- actorType->_color = actorType2->_color;
- if (actorType->_value1E == 0)
- actorType->_value1E = actorType2->_value1E;
- }
- _vm->_dict->addActorType(actorType->_actorTypeId, actorType);
- }
-
- for (uint i = 0; i < actorResource->_sequences.size(); ++i) {
- Sequence *sequence = &actorResource->_sequences[i];
- _vm->_dict->addSequence(sequence->_sequenceId, sequence);
- }
-
+ resource->_instance = _vm->_actorItems->createActorInstance(resource);
}
void ActorResourceLoader::unload(Resource *resource) {
- debug("ActorResourceLoader::unload() Unloading actor %08X...", resource->_resId);
- // TODO Move to ActorItems
- ActorItem *actorItem = _vm->_actorItems->findActorByResource((ActorResource*)resource->_refId);
- if (actorItem->_pauseCtr <= 0) {
- for (uint i = 0; i < actorItem->_actRes->_actorTypes.size(); ++i)
- _vm->_dict->removeActorType(actorItem->_actRes->_actorTypes[i]._actorTypeId);
- for (uint i = 0; i < actorItem->_actRes->_sequences.size(); ++i)
- _vm->_dict->removeSequence(actorItem->_actRes->_sequences[i]._sequenceId);
- }
- _vm->_actorItems->freeActorItem(actorItem);
- delete actorItem->_actRes;
+ // TODO Remove method
}
void ActorResourceLoader::buildFilename(Resource *resource) {
@@ -220,91 +179,128 @@ bool ActorResource::findNamedPoint(uint32 namedPointId, Common::Point &pt) {
return _namedPoints.findNamedPoint(namedPointId, pt);
}
-// ActorItem
+// ActorInstance
-ActorItem::ActorItem(IllusionsEngine *vm)
+ActorInstance::ActorInstance(IllusionsEngine *vm)
: _vm(vm) {
}
-ActorItem::~ActorItem() {
+void ActorInstance::load(Resource *resource) {
+ _actorResource = new ActorResource();
+ _actorResource->load(resource);
+ _tag = resource->_tag;
+ _pauseCtr = 0;
+ initActorTypes();
+ registerResources();
+}
+
+void ActorInstance::unload() {
+ if (_pauseCtr <= 0)
+ unregisterResources();
+ _vm->_actorItems->removeActorInstance(this);
+ delete _actorResource;
}
-void ActorItem::pause() {
+void ActorInstance::pause() {
++_pauseCtr;
- if (_pauseCtr == 1) {
- for (uint i = 0; i < _actRes->_actorTypes.size(); ++i)
- _vm->_dict->removeActorType(_actRes->_actorTypes[i]._actorTypeId);
- for (uint i = 0; i < _actRes->_sequences.size(); ++i)
- _vm->_dict->removeSequence(_actRes->_sequences[i]._sequenceId);
- }
+ if (_pauseCtr == 1)
+ unregisterResources();
}
-void ActorItem::unpause() {
+void ActorInstance::unpause() {
--_pauseCtr;
- if (_pauseCtr == 0) {
- for (uint i = 0; i < _actRes->_actorTypes.size(); ++i) {
- ActorType *actorType = &_actRes->_actorTypes[i];
- _vm->_dict->addActorType(actorType->_actorTypeId, actorType);
- }
- for (uint i = 0; i < _actRes->_sequences.size(); ++i) {
- Sequence *sequence = &_actRes->_sequences[i];
- _vm->_dict->addSequence(sequence->_sequenceId, sequence);
+ if (_pauseCtr == 0)
+ registerResources();
+}
+
+void ActorInstance::initActorTypes() {
+ for (uint i = 0; i < _actorResource->_actorTypes.size(); ++i) {
+ ActorType *actorType = &_actorResource->_actorTypes[i];
+ ActorType *actorType2 = _vm->_dict->findActorType(actorType->_actorTypeId);
+ if (actorType2) {
+ actorType->_surfInfo._dimensions._width = MAX(actorType->_surfInfo._dimensions._width,
+ actorType2->_surfInfo._dimensions._width);
+ actorType->_surfInfo._dimensions._height = MAX(actorType->_surfInfo._dimensions._height,
+ actorType2->_surfInfo._dimensions._height);
+ if (actorType->_color.r == 255 && actorType->_color.g == 255 && actorType->_color.b == 255)
+ actorType->_color = actorType2->_color;
+ if (actorType->_value1E == 0)
+ actorType->_value1E = actorType2->_value1E;
}
}
}
-// ActorItems
+void ActorInstance::registerResources() {
+ for (uint i = 0; i < _actorResource->_actorTypes.size(); ++i) {
+ ActorType *actorType = &_actorResource->_actorTypes[i];
+ _vm->_dict->addActorType(actorType->_actorTypeId, actorType);
+ }
+ for (uint i = 0; i < _actorResource->_sequences.size(); ++i) {
+ Sequence *sequence = &_actorResource->_sequences[i];
+ _vm->_dict->addSequence(sequence->_sequenceId, sequence);
+ }
+}
+
+void ActorInstance::unregisterResources() {
+ for (uint i = 0; i < _actorResource->_actorTypes.size(); ++i)
+ _vm->_dict->removeActorType(_actorResource->_actorTypes[i]._actorTypeId);
+ for (uint i = 0; i < _actorResource->_sequences.size(); ++i)
+ _vm->_dict->removeSequence(_actorResource->_sequences[i]._sequenceId);
+}
+
+// ActorInstanceList
-ActorItems::ActorItems(IllusionsEngine *vm)
+ActorInstanceList::ActorInstanceList(IllusionsEngine *vm)
: _vm(vm) {
}
-ActorItems::~ActorItems() {
+ActorInstanceList::~ActorInstanceList() {
}
-ActorItem *ActorItems::allocActorItem() {
- ActorItem *actorItem = new ActorItem(_vm);
- _items.push_back(actorItem);
- return actorItem;
+ActorInstance *ActorInstanceList::createActorInstance(Resource *resource) {
+ ActorInstance *actorInstance = new ActorInstance(_vm);
+ actorInstance->load(resource);
+ _items.push_back(actorInstance);
+ return actorInstance;
}
-void ActorItems::freeActorItem(ActorItem *actorItem) {
- _items.remove(actorItem);
- delete actorItem;
+void ActorInstanceList::removeActorInstance(ActorInstance *actorInstance) {
+ _items.remove(actorInstance);
+ debug("removeActorInstance() AFTER _items.size(): %d", _items.size());
}
-void ActorItems::pauseByTag(uint32 tag) {
+void ActorInstanceList::pauseByTag(uint32 tag) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
if ((*it)->_tag == tag)
(*it)->pause();
}
-void ActorItems::unpauseByTag(uint32 tag) {
+void ActorInstanceList::unpauseByTag(uint32 tag) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
if ((*it)->_tag == tag)
(*it)->unpause();
}
-FramesList *ActorItems::findSequenceFrames(Sequence *sequence) {
+FramesList *ActorInstanceList::findSequenceFrames(Sequence *sequence) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it) {
- ActorItem *actorItem = *it;
- if (actorItem->_pauseCtr <= 0 && actorItem->_actRes->containsSequence(sequence))
- return &actorItem->_actRes->_frames;
+ ActorInstance *actorInstance = *it;
+ if (actorInstance->_pauseCtr <= 0 && actorInstance->_actorResource->containsSequence(sequence))
+ return &actorInstance->_actorResource->_frames;
}
return 0;
}
-ActorItem *ActorItems::findActorByResource(ActorResource *actorResource) {
+ActorInstance *ActorInstanceList::findActorByResource(ActorResource *actorResource) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
- if ((*it)->_actRes == actorResource)
+ if ((*it)->_actorResource == actorResource)
return (*it);
return 0;
}
-bool ActorItems::findNamedPoint(uint32 namedPointId, Common::Point &pt) {
+bool ActorInstanceList::findNamedPoint(uint32 namedPointId, Common::Point &pt) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it) {
- ActorItem *actorItem = *it;
- if (actorItem->_pauseCtr == 0 && actorItem->_actRes->findNamedPoint(namedPointId, pt))
+ ActorInstance *actorInstance = *it;
+ if (actorInstance->_pauseCtr == 0 && actorInstance->_actorResource->findNamedPoint(namedPointId, pt))
return true;
}
return false;
diff --git a/engines/illusions/actorresource.h b/engines/illusions/actorresource.h
index 3a4c46213e..cc8feebd44 100644
--- a/engines/illusions/actorresource.h
+++ b/engines/illusions/actorresource.h
@@ -94,32 +94,37 @@ public:
NamedPoints _namedPoints;
};
-class ActorItem {
+class ActorInstance : public ResourceInstance {
public:
- ActorItem(IllusionsEngine *vm);
- ~ActorItem();
+ ActorInstance(IllusionsEngine *vm);
+ virtual void load(Resource *resource);
+ virtual void unload();
void pause();
void unpause();
public:
IllusionsEngine *_vm;
uint32 _tag;
int _pauseCtr;
- ActorResource *_actRes;
+ ActorResource *_actorResource;
+protected:
+ void initActorTypes();
+ void registerResources();
+ void unregisterResources();
};
-class ActorItems {
+class ActorInstanceList {
public:
- ActorItems(IllusionsEngine *vm);
- ~ActorItems();
- ActorItem *allocActorItem();
- void freeActorItem(ActorItem *actorItem);
+ ActorInstanceList(IllusionsEngine *vm);
+ ~ActorInstanceList();
+ ActorInstance *createActorInstance(Resource *resource);
+ void removeActorInstance(ActorInstance *actorInstance);
void pauseByTag(uint32 tag);
void unpauseByTag(uint32 tag);
FramesList *findSequenceFrames(Sequence *sequence);
- ActorItem *findActorByResource(ActorResource *actorResource);
+ ActorInstance *findActorByResource(ActorResource *actorResource);
bool findNamedPoint(uint32 namedPointId, Common::Point &pt);
protected:
- typedef Common::List<ActorItem*> Items;
+ typedef Common::List<ActorInstance*> Items;
typedef Items::iterator ItemsIterator;
IllusionsEngine *_vm;
Items _items;
diff --git a/engines/illusions/backgroundresource.cpp b/engines/illusions/backgroundresource.cpp
index 404ac6f5bc..34a42c72c0 100644
--- a/engines/illusions/backgroundresource.cpp
+++ b/engines/illusions/backgroundresource.cpp
@@ -34,52 +34,11 @@ namespace Illusions {
// BackgroundResourceLoader
void BackgroundResourceLoader::load(Resource *resource) {
- debug("BackgroundResourceLoader::load() Loading background %08X from %s...", resource->_resId, resource->_filename.c_str());
-
- BackgroundResource *backgroundResource = new BackgroundResource();
- backgroundResource->load(resource->_data, resource->_dataSize);
- resource->_refId = backgroundResource;
-
- // TODO Move to BackgroundItems
- BackgroundItem *backgroundItem = _vm->_backgroundItems->allocBackgroundItem();
- backgroundItem->_bgRes = backgroundResource;
- backgroundItem->_tag = resource->_tag;
- backgroundItem->initSurface();
-
- // Insert background objects
- for (uint i = 0; i < backgroundResource->_backgroundObjectsCount; ++i)
- _vm->_controls->placeBackgroundObject(&backgroundResource->_backgroundObjects[i]);
-
- // 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();
- _vm->_camera->set(backgroundItem->_bgRes->_bgInfos[index - 1]._panPoint, backgroundItem->_bgRes->_bgInfos[index - 1]._surfInfo._dimensions);
-
- if (backgroundItem->_bgRes->_palettesCount > 0) {
- Palette *palette = backgroundItem->_bgRes->getPalette(backgroundItem->_bgRes->_paletteIndex - 1);
- _vm->_screen->setPalette(palette->_palette, 1, palette->_count);
- }
-
+ resource->_instance = _vm->_backgroundInstances->createBackgroundInstance(resource);
}
void BackgroundResourceLoader::unload(Resource *resource) {
- debug("BackgroundResourceLoader::unload() Unloading background %08X...", resource->_resId);
- // TODO Move to BackgroundItems
- BackgroundItem *backgroundItem = _vm->_backgroundItems->findBackgroundByResource((BackgroundResource*)resource->_refId);
- backgroundItem->freeSurface();
- 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();
- debug("BackgroundResourceLoader::unload() Unloading background %08X OK", resource->_resId);
+ // TODO Remove method
}
void BackgroundResourceLoader::buildFilename(Resource *resource) {
@@ -414,15 +373,49 @@ bool BackgroundResource::findNamedPoint(uint32 namedPointId, Common::Point &pt)
return _namedPoints.findNamedPoint(namedPointId, pt);
}
-// BackgroundItem
+// BackgroundInstance
+
+BackgroundInstance::BackgroundInstance(IllusionsEngine *vm)
+ : _vm(vm), _tag(0), _pauseCtr(0), _bgRes(0), _savedPalette(0) {
+}
+
+void BackgroundInstance::load(Resource *resource) {
+ debug("BackgroundResourceLoader::load() Loading background %08X from %s...", resource->_resId, resource->_filename.c_str());
+
+ BackgroundResource *backgroundResource = new BackgroundResource();
+ backgroundResource->load(resource->_data, resource->_dataSize);
+
+ _bgRes = backgroundResource;
+ _tag = resource->_tag;
+ initSurface();
+
+ // Insert background objects
+ for (uint i = 0; i < backgroundResource->_backgroundObjectsCount; ++i)
+ _vm->_controls->placeBackgroundObject(&backgroundResource->_backgroundObjects[i]);
+
+ registerResources();
+
+ // TODO camera_fadeClear();
+ int index = _bgRes->findMasterBgIndex();
+ _vm->_camera->set(_bgRes->_bgInfos[index - 1]._panPoint, _bgRes->_bgInfos[index - 1]._surfInfo._dimensions);
+
+ if (_bgRes->_palettesCount > 0) {
+ Palette *palette = _bgRes->getPalette(_bgRes->_paletteIndex - 1);
+ _vm->_screen->setPalette(palette->_palette, 1, palette->_count);
+ }
-BackgroundItem::BackgroundItem(IllusionsEngine *vm) : _vm(vm), _tag(0), _pauseCtr(0), _bgRes(0), _savedPalette(0) {
}
-BackgroundItem::~BackgroundItem() {
+void BackgroundInstance::unload() {
+ debug("BackgroundInstance::unload()");
+ freeSurface();
+ unregisterResources();
+ delete _bgRes;
+ _vm->_backgroundInstances->removeBackgroundInstance(this);
+ _vm->setDefaultTextCoords();
}
-void BackgroundItem::initSurface() {
+void BackgroundInstance::initSurface() {
for (uint i = 0; i < kMaxBackgroundItemSurfaces; ++i)
_surfaces[i] = 0;
for (uint i = 0; i < _bgRes->_bgInfosCount; ++i) {
@@ -433,7 +426,7 @@ void BackgroundItem::initSurface() {
}
}
-void BackgroundItem::freeSurface() {
+void BackgroundInstance::freeSurface() {
for (uint i = 0; i < _bgRes->_bgInfosCount; ++i)
if (_surfaces[i]) {
_surfaces[i]->free();
@@ -442,7 +435,7 @@ void BackgroundItem::freeSurface() {
}
}
-void BackgroundItem::drawTiles(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels) {
+void BackgroundInstance::drawTiles(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels) {
switch (_vm->getGameId()) {
case kGameIdDuckman:
drawTiles8(surface, tileMap, tilePixels);
@@ -453,7 +446,21 @@ void BackgroundItem::drawTiles(Graphics::Surface *surface, TileMap &tileMap, byt
}
}
-void BackgroundItem::drawTiles8(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels) {
+void BackgroundInstance::registerResources() {
+ for (uint i = 0; i < _bgRes->_regionSequencesCount; ++i) {
+ Sequence *sequence = &_bgRes->_regionSequences[i];
+ _vm->_dict->addSequence(sequence->_sequenceId, sequence);
+ }
+}
+
+void BackgroundInstance::unregisterResources() {
+ for (uint i = 0; i < _bgRes->_regionSequencesCount; ++i) {
+ Sequence *sequence = &_bgRes->_regionSequences[i];
+ _vm->_dict->removeSequence(sequence->_sequenceId);
+ }
+}
+
+void BackgroundInstance::drawTiles8(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels) {
const int kTileWidth = 32;
const int kTileHeight = 8;
const int kTileSize = kTileWidth * kTileHeight;
@@ -477,7 +484,7 @@ void BackgroundItem::drawTiles8(Graphics::Surface *surface, TileMap &tileMap, by
}
}
-void BackgroundItem::drawTiles16(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels) {
+void BackgroundInstance::drawTiles16(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels) {
const int kTileWidth = 32;
const int kTileHeight = 8;
const int kTileSize = kTileWidth * kTileHeight * 2;
@@ -504,13 +511,10 @@ void BackgroundItem::drawTiles16(Graphics::Surface *surface, TileMap &tileMap, b
}
}
-void BackgroundItem::pause() {
+void BackgroundInstance::pause() {
++_pauseCtr;
if (_pauseCtr <= 1) {
- for (uint i = 0; i < _bgRes->_regionSequencesCount; ++i) {
- Sequence *sequence = &_bgRes->_regionSequences[i];
- _vm->_dict->removeSequence(sequence->_sequenceId);
- }
+ unregisterResources();
_vm->setDefaultTextCoords();
_vm->_camera->getActiveState(_savedCameraState);
_savedPalette = new byte[1024];
@@ -519,91 +523,89 @@ void BackgroundItem::pause() {
}
}
-void BackgroundItem::unpause() {
+void BackgroundInstance::unpause() {
--_pauseCtr;
if (_pauseCtr <= 0) {
- for (uint i = 0; i < _bgRes->_regionSequencesCount; ++i) {
- Sequence *sequence = &_bgRes->_regionSequences[i];
- _vm->_dict->addSequence(sequence->_sequenceId, sequence);
- }
+ registerResources();
initSurface();
_vm->_screen->setPalette(_savedPalette, 1, 256);
delete[] _savedPalette;
_savedPalette = 0;
// TODO _vm->_screen->_fadeClear();
_vm->_camera->setActiveState(_savedCameraState);
- _vm->_backgroundItems->refreshPan();
+ _vm->_backgroundInstances->refreshPan();
}
}
-// BackgroundItems
+// BackgroundInstanceList
-BackgroundItems::BackgroundItems(IllusionsEngine *vm)
+BackgroundInstanceList::BackgroundInstanceList(IllusionsEngine *vm)
: _vm(vm) {
}
-BackgroundItems::~BackgroundItems() {
+BackgroundInstanceList::~BackgroundInstanceList() {
}
-BackgroundItem *BackgroundItems::allocBackgroundItem() {
- BackgroundItem *backgroundItem = new BackgroundItem(_vm);
- _items.push_back(backgroundItem);
- return backgroundItem;
+BackgroundInstance *BackgroundInstanceList::createBackgroundInstance(Resource *resource) {
+ BackgroundInstance *backgroundInstance = new BackgroundInstance(_vm);
+ backgroundInstance->load(resource);
+ _items.push_back(backgroundInstance);
+ return backgroundInstance;
}
-void BackgroundItems::freeBackgroundItem(BackgroundItem *backgroundItem) {
- _items.remove(backgroundItem);
- delete backgroundItem;
+void BackgroundInstanceList::removeBackgroundInstance(BackgroundInstance *backgroundInstance) {
+ _items.remove(backgroundInstance);
+ debug("removeActorInstance() AFTER _items.size(): %d", _items.size());
}
-void BackgroundItems::pauseByTag(uint32 tag) {
+void BackgroundInstanceList::pauseByTag(uint32 tag) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
if ((*it)->_tag == tag)
(*it)->pause();
}
-void BackgroundItems::unpauseByTag(uint32 tag) {
+void BackgroundInstanceList::unpauseByTag(uint32 tag) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
if ((*it)->_tag == tag)
(*it)->unpause();
}
-BackgroundItem *BackgroundItems::findActiveBackground() {
+BackgroundInstance *BackgroundInstanceList::findActiveBackground() {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
if ((*it)->_pauseCtr == 0)
return (*it);
return 0;
}
-BackgroundItem *BackgroundItems::findBackgroundByResource(BackgroundResource *backgroundResource) {
+BackgroundInstance *BackgroundInstanceList::findBackgroundByResource(BackgroundResource *backgroundResource) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
if ((*it)->_bgRes == backgroundResource)
return (*it);
return 0;
}
-BackgroundResource *BackgroundItems::getActiveBgResource() {
- BackgroundItem *background = findActiveBackground();
+BackgroundResource *BackgroundInstanceList::getActiveBgResource() {
+ BackgroundInstance *background = findActiveBackground();
if (background)
return background->_bgRes;
return 0;
}
-WidthHeight BackgroundItems::getMasterBgDimensions() {
- BackgroundItem *backgroundItem = findActiveBackground();
- int16 index = backgroundItem->_bgRes->findMasterBgIndex();
- return backgroundItem->_bgRes->_bgInfos[index - 1]._surfInfo._dimensions;
+WidthHeight BackgroundInstanceList::getMasterBgDimensions() {
+ BackgroundInstance *backgroundInstance = findActiveBackground();
+ int16 index = backgroundInstance->_bgRes->findMasterBgIndex();
+ return backgroundInstance->_bgRes->_bgInfos[index - 1]._surfInfo._dimensions;
}
-void BackgroundItems::refreshPan() {
- BackgroundItem *backgroundItem = findActiveBackground();
- if (backgroundItem) {
+void BackgroundInstanceList::refreshPan() {
+ BackgroundInstance *backgroundInstance = findActiveBackground();
+ if (backgroundInstance) {
WidthHeight dimensions = getMasterBgDimensions();
- _vm->_camera->refreshPan(backgroundItem, dimensions);
+ _vm->_camera->refreshPan(backgroundInstance, dimensions);
}
}
-bool BackgroundItems::findActiveBackgroundNamedPoint(uint32 namedPointId, Common::Point &pt) {
+bool BackgroundInstanceList::findActiveBackgroundNamedPoint(uint32 namedPointId, Common::Point &pt) {
BackgroundResource *backgroundResource = getActiveBgResource();
return backgroundResource ? backgroundResource->findNamedPoint(namedPointId, pt) : false;
}
diff --git a/engines/illusions/backgroundresource.h b/engines/illusions/backgroundresource.h
index 8d31deb193..673f69f069 100644
--- a/engines/illusions/backgroundresource.h
+++ b/engines/illusions/backgroundresource.h
@@ -183,10 +183,11 @@ public:
const uint kMaxBackgroundItemSurfaces = 3;
-class BackgroundItem {
+class BackgroundInstance : public ResourceInstance {
public:
- BackgroundItem(IllusionsEngine *vm);
- ~BackgroundItem();
+ BackgroundInstance(IllusionsEngine *vm);
+ virtual void load(Resource *resource);
+ virtual void unload();
void initSurface();
void freeSurface();
void drawTiles(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels);
@@ -201,27 +202,29 @@ public:
Graphics::Surface *_surfaces[kMaxBackgroundItemSurfaces];
CameraState _savedCameraState;
byte *_savedPalette;
+ void registerResources();
+ void unregisterResources();
void drawTiles8(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels);
void drawTiles16(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels);
};
-class BackgroundItems {
+class BackgroundInstanceList {
public:
- BackgroundItems(IllusionsEngine *vm);
- ~BackgroundItems();
- BackgroundItem *allocBackgroundItem();
- void freeBackgroundItem(BackgroundItem *backgroundItem);
+ BackgroundInstanceList(IllusionsEngine *vm);
+ ~BackgroundInstanceList();
+ BackgroundInstance *createBackgroundInstance(Resource *resource);
+ void removeBackgroundInstance(BackgroundInstance *backgroundInstance);
void pauseByTag(uint32 tag);
void unpauseByTag(uint32 tag);
- BackgroundItem *findActiveBackground();
- BackgroundItem *findBackgroundByResource(BackgroundResource *backgroundResource);
+ BackgroundInstance *findActiveBackground();
+ BackgroundInstance *findBackgroundByResource(BackgroundResource *backgroundResource);
BackgroundResource *getActiveBgResource();
WidthHeight getMasterBgDimensions();
void refreshPan();
bool findActiveBackgroundNamedPoint(uint32 namedPointId, Common::Point &pt);
//protected:
public:
- typedef Common::List<BackgroundItem*> Items;
+ typedef Common::List<BackgroundInstance*> Items;
typedef Items::iterator ItemsIterator;
IllusionsEngine *_vm;
Items _items;
diff --git a/engines/illusions/camera.cpp b/engines/illusions/camera.cpp
index 92783a198b..4e6281a9d8 100644
--- a/engines/illusions/camera.cpp
+++ b/engines/illusions/camera.cpp
@@ -72,7 +72,7 @@ void Camera::set(Common::Point &panPoint, WidthHeight &dimensions) {
_activeState._currPan = _activeState._panTargetPoint;
_activeState._panXShl = _activeState._currPan.x << 16;
_activeState._panYShl = _activeState._currPan.y << 16;
- _vm->_backgroundItems->refreshPan();
+ _vm->_backgroundInstances->refreshPan();
_activeState._panToPositionPtr = 0;
_activeState._panObjectId = 0;
_activeState._panNotifyId = 0;
@@ -169,7 +169,7 @@ void Camera::stopPan() {
_activeState._panObjectId = 0;
_activeState._panNotifyId = 0;
_activeState._pointFlags = 0;
- _vm->_backgroundItems->refreshPan();
+ _vm->_backgroundInstances->refreshPan();
}
void Camera::pause() {
@@ -267,7 +267,7 @@ void Camera::update(uint32 currTime) {
if (_activeState._cameraMode == 1 || _activeState._cameraMode == 5)
nullsub_2();
*/
- _vm->_backgroundItems->refreshPan();
+ _vm->_backgroundInstances->refreshPan();
}
if (isPanFinished()) {
@@ -336,7 +336,7 @@ void Camera::getActiveState(CameraState &state) {
state = _activeState;
}
-void Camera::refreshPan(BackgroundItem *backgroundItem, WidthHeight &dimensions) {
+void Camera::refreshPan(BackgroundInstance *backgroundItem, WidthHeight &dimensions) {
Common::Point screenOffs = getScreenOffset();
int x = dimensions._width - _screenWidth;
int y = dimensions._height - _screenHeight;
diff --git a/engines/illusions/camera.h b/engines/illusions/camera.h
index 85d308df5f..2e4b760517 100644
--- a/engines/illusions/camera.h
+++ b/engines/illusions/camera.h
@@ -29,7 +29,7 @@
namespace Illusions {
-class BackgroundItem;
+class BackgroundInstance;
struct CameraState {
int _cameraMode;
@@ -87,7 +87,7 @@ public:
bool isAtPanLimit(int limitNum);
void setActiveState(CameraState &state);
void getActiveState(CameraState &state);
- void refreshPan(BackgroundItem *backgroundItem, WidthHeight &dimensions);
+ void refreshPan(BackgroundInstance *backgroundItem, WidthHeight &dimensions);
protected:
IllusionsEngine *_vm;
CameraState _activeState;
diff --git a/engines/illusions/fontresource.cpp b/engines/illusions/fontresource.cpp
index c2c66ac528..4d4caf611d 100644
--- a/engines/illusions/fontresource.cpp
+++ b/engines/illusions/fontresource.cpp
@@ -29,18 +29,13 @@ namespace Illusions {
// FontResourceLoader
void FontResourceLoader::load(Resource *resource) {
- debug("FontResourceLoader::load() Loading font %08X from %s...", resource->_resId, resource->_filename.c_str());
-
- FontResource *fontResource = new FontResource();
- fontResource->load(resource);
- resource->_refId = fontResource;
- _vm->_dict->addFont(resource->_resId, fontResource);
+ FontInstance *fontInstance = new FontInstance(_vm);
+ fontInstance->load(resource);
+ resource->_instance = fontInstance;
}
void FontResourceLoader::unload(Resource *resource) {
- FontResource *fontResource = _vm->_dict->findFont(resource->_resId);
- delete fontResource;
- _vm->_dict->removeFont(resource->_resId);
+ // TODO Remove method
}
void FontResourceLoader::buildFilename(Resource *resource) {
@@ -123,4 +118,21 @@ CharInfo *FontResource::getCharInfo(uint16 c) {
return 0;
}
+// FontInstance
+
+FontInstance::FontInstance(IllusionsEngine *vm) : _vm(vm) {
+}
+
+void FontInstance::load(Resource *resource) {
+ _fontResource = new FontResource();
+ _fontResource->load(resource);
+ _resId = resource->_resId;
+ _vm->_dict->addFont(resource->_resId, _fontResource);
+}
+
+void FontInstance::unload() {
+ delete _fontResource;
+ _vm->_dict->removeFont(_resId);
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/fontresource.h b/engines/illusions/fontresource.h
index 33360d7968..d658ddc0ce 100644
--- a/engines/illusions/fontresource.h
+++ b/engines/illusions/fontresource.h
@@ -79,6 +79,17 @@ public:
CharRange *getCharRange(uint16 c);
};
+class FontInstance : public ResourceInstance {
+public:
+ FontInstance(IllusionsEngine *vm);
+ virtual void load(Resource *resource);
+ virtual void unload();
+public:
+ IllusionsEngine *_vm;
+ FontResource *_fontResource;
+ uint32 _resId;
+};
+
} // End of namespace Illusions
#endif // ILLUSIONS_FONTRESOURCE_H
diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp
index c51eb8707d..771afb7298 100644
--- a/engines/illusions/illusions.cpp
+++ b/engines/illusions/illusions.cpp
@@ -147,8 +147,8 @@ int IllusionsEngine::updateGraphics(uint flags) {
_camera->update(currTime);
updateFader();
- // TODO Move to BackgroundItems class
- BackgroundItem *backgroundItem = _backgroundItems->findActiveBackground();
+ // TODO Move to BackgroundInstanceList class
+ BackgroundInstance *backgroundItem = _backgroundInstances->findActiveBackground();
if (backgroundItem) {
BackgroundResource *bgRes = backgroundItem->_bgRes;
for (uint i = 0; i < bgRes->_bgInfosCount; ++i) {
@@ -325,4 +325,8 @@ void IllusionsEngine::setDefaultTextPosition(Common::Point &position) {
_defaultTextPosition = position;
}
+FramesList *IllusionsEngine::findActorSequenceFrames(Sequence *sequence) {
+ return _actorItems->findSequenceFrames(sequence);
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h
index 522d1dc9c3..59de64ceb1 100644
--- a/engines/illusions/illusions.h
+++ b/engines/illusions/illusions.h
@@ -51,10 +51,10 @@ class ResourceSystem;
struct SurfInfo;
class ActorItem;
-class ActorItems;
+class ActorInstanceList;
class ActorType;
class BackgroundItem;
-class BackgroundItems;
+class BackgroundInstanceList;
class BackgroundResource;
class Camera;
class Control;
@@ -106,8 +106,8 @@ public:
Screen *_screen;
ScreenText *_screenText;
Input *_input;
- ActorItems *_actorItems;
- BackgroundItems *_backgroundItems;
+ ActorInstanceList *_actorItems;
+ BackgroundInstanceList *_backgroundInstances;
Camera *_camera;
Controls *_controls;
TalkItems *_talkItems;
@@ -168,6 +168,8 @@ public:
void getDefaultTextPosition(Common::Point &position);
void setDefaultTextPosition(Common::Point &position);
+ FramesList *findActorSequenceFrames(Sequence *sequence);
+
virtual void setDefaultTextCoords() = 0;
virtual void loadSpecialCode(uint32 resId) = 0;
virtual void unloadSpecialCode(uint32 resId) = 0;
@@ -188,7 +190,7 @@ public:
virtual void startScriptThreadSimple(uint32 threadId, uint32 callingThreadId) = 0;
virtual uint32 startTempScriptThread(byte *scriptCodeIp, uint32 callingThreadId,
uint32 value8, uint32 valueC, uint32 value10) = 0;
-
+
#if 0
// Savegame API
diff --git a/engines/illusions/illusions_bbdou.cpp b/engines/illusions/illusions_bbdou.cpp
index e98d0c1ff2..c73d9f4682 100644
--- a/engines/illusions/illusions_bbdou.cpp
+++ b/engines/illusions/illusions_bbdou.cpp
@@ -205,8 +205,8 @@ Common::Error IllusionsEngine_BBDOU::run() {
_screen = new Screen(this, 640, 480, 16);
_screenText = new ScreenText(this);
_input = new Input();
- _actorItems = new ActorItems(this);
- _backgroundItems = new BackgroundItems(this);
+ _actorItems = new ActorInstanceList(this);
+ _backgroundInstances = new BackgroundInstanceList(this);
_camera = new Camera(this);
_controls = new Controls(this);
_cursor = new Cursor(this);
@@ -260,7 +260,7 @@ Common::Error IllusionsEngine_BBDOU::run() {
delete _cursor;
delete _controls;
delete _camera;
- delete _backgroundItems;
+ delete _backgroundInstances;
delete _actorItems;
delete _input;
delete _screenText;
@@ -370,7 +370,7 @@ Control *IllusionsEngine_BBDOU::getObjectControl(uint32 objectId) {
Common::Point IllusionsEngine_BBDOU::getNamedPointPosition(uint32 namedPointId) {
Common::Point pt;
- if (_backgroundItems->findActiveBackgroundNamedPoint(namedPointId, pt) ||
+ if (_backgroundInstances->findActiveBackgroundNamedPoint(namedPointId, pt) ||
_actorItems->findNamedPoint(namedPointId, pt) ||
_controls->findNamedPoint(namedPointId, pt))
return pt;
@@ -554,13 +554,13 @@ void IllusionsEngine_BBDOU::enterPause(uint32 threadId) {
_threads->suspendThreadsByTag(sceneId, threadId);
_controls->pauseControlsByTag(sceneId);
_actorItems->pauseByTag(sceneId);
- _backgroundItems->pauseByTag(sceneId);
+ _backgroundInstances->pauseByTag(sceneId);
_activeScenes.pauseActiveScene();
}
void IllusionsEngine_BBDOU::leavePause(uint32 threadId) {
uint32 sceneId = _activeScenes.getCurrentScene();
- _backgroundItems->unpauseByTag(sceneId);
+ _backgroundInstances->unpauseByTag(sceneId);
_actorItems->unpauseByTag(sceneId);
_controls->unpauseControlsByTag(sceneId);
_threads->notifyThreadsByTag(sceneId, threadId);
diff --git a/engines/illusions/illusions_duckman.cpp b/engines/illusions/illusions_duckman.cpp
index 5d845a40db..bc5b667a87 100644
--- a/engines/illusions/illusions_duckman.cpp
+++ b/engines/illusions/illusions_duckman.cpp
@@ -99,8 +99,8 @@ Common::Error IllusionsEngine_Duckman::run() {
_screen = new Screen(this, 320, 200, 8);
_screenText = new ScreenText(this);
_input = new Input();
- _actorItems = new ActorItems(this);
- _backgroundItems = new BackgroundItems(this);
+ _actorItems = new ActorInstanceList(this);
+ _backgroundInstances = new BackgroundInstanceList(this);
_camera = new Camera(this);
_controls = new Controls(this);
_talkItems = new TalkItems(this);
@@ -175,7 +175,7 @@ Common::Error IllusionsEngine_Duckman::run() {
delete _talkItems;
delete _controls;
delete _camera;
- delete _backgroundItems;
+ delete _backgroundInstances;
delete _actorItems;
delete _input;
delete _screenText;
@@ -347,7 +347,7 @@ Control *IllusionsEngine_Duckman::getObjectControl(uint32 objectId) {
Common::Point IllusionsEngine_Duckman::getNamedPointPosition(uint32 namedPointId) {
Common::Point pt;
Common::Point currPan = _camera->getCurrentPan();
- if (_backgroundItems->findActiveBackgroundNamedPoint(namedPointId, pt)) {
+ if (_backgroundInstances->findActiveBackgroundNamedPoint(namedPointId, pt)) {
return pt;
} else if (namedPointId - 0x00070001 > 209) {
if (_controls->findNamedPoint(namedPointId, pt)) {
@@ -727,11 +727,11 @@ void IllusionsEngine_Duckman::enterPause(uint32 sceneId, uint32 threadId) {
_threads->suspendThreads(threadId);
_controls->pauseControls();
_actorItems->pauseByTag(sceneId);
- _backgroundItems->pauseByTag(sceneId);
+ _backgroundInstances->pauseByTag(sceneId);
}
void IllusionsEngine_Duckman::leavePause(uint32 sceneId, uint32 threadId) {
- _backgroundItems->unpauseByTag(sceneId);
+ _backgroundInstances->unpauseByTag(sceneId);
_actorItems->unpauseByTag(sceneId);
_controls->unpauseControls();
_threads->notifyThreads(threadId);
diff --git a/engines/illusions/resourcesystem.cpp b/engines/illusions/resourcesystem.cpp
index 3d99541579..bb6048bed2 100644
--- a/engines/illusions/resourcesystem.cpp
+++ b/engines/illusions/resourcesystem.cpp
@@ -28,6 +28,17 @@
namespace Illusions {
+// ResourceInstance
+
+void ResourceInstance::load(Resource *resource) {
+}
+
+void ResourceInstance::unload() {
+}
+
+ResourceInstance::~ResourceInstance() {
+}
+
// Resource
void Resource::loadData() {
@@ -45,7 +56,7 @@ void Resource::loadData() {
void Resource::unloadData() {
debug("Resource::unloadData()");
- delete _data;
+ free(_data);
_data = 0;
_dataSize = 0;
}
@@ -75,7 +86,6 @@ void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) {
resource->_resId = resId;
resource->_tag = tag;
resource->_threadId = threadId;
- resource->_resourceLoader = resourceLoader;
resource->_gameId = _vm->getGameId();
resourceLoader->buildFilename(resource);
@@ -87,8 +97,8 @@ void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) {
resourceLoader->load(resource);
- if (resourceLoader->isFlag(kRlfFreeDataAfterUse)) {
- debug("ResourceSystem::loadResource() kRlfFreeDataAfterUse");
+ if (resourceLoader->isFlag(kRlfFreeDataAfterLoad)) {
+ debug("ResourceSystem::loadResource() kRlfFreeDataAfterLoad");
resource->unloadData();
}
@@ -135,7 +145,6 @@ Resource *ResourceSystem::getResource(uint32 resId) {
void ResourceSystem::unloadResource(Resource *resource) {
debug("Unloading %08X... (tag: %08X)", resource->_resId, resource->_tag);
- resource->_resourceLoader->unload(resource);
ResourcesArrayIterator it = Common::find_if(_resources.begin(), _resources.end(), ResourceEqualByValue(resource));
if (it != _resources.end())
_resources.remove_at(it - _resources.begin());
diff --git a/engines/illusions/resourcesystem.h b/engines/illusions/resourcesystem.h
index 0a214c5a2a..37e843efa5 100644
--- a/engines/illusions/resourcesystem.h
+++ b/engines/illusions/resourcesystem.h
@@ -37,6 +37,14 @@ namespace Illusions {
class BaseResourceLoader;
class IllusionsEngine;
+struct Resource;
+
+class ResourceInstance {
+public:
+ virtual void load(Resource *resource);
+ virtual void unload();
+ virtual ~ResourceInstance();
+};
struct Resource {
bool _loaded;
@@ -45,28 +53,24 @@ struct Resource {
uint32 _threadId;
byte *_data;
uint32 _dataSize;
- BaseResourceLoader *_resourceLoader;
- void *_refId;
int _gameId;
Common::String _filename;
- Resource() : _loaded(false), _resId(0), _tag(0), _threadId(0), _data(0), _dataSize(0),
- _resourceLoader(0), _refId(0) {}
+ ResourceInstance *_instance;
+ Resource() : _loaded(false), _resId(0), _tag(0), _threadId(0), _data(0), _dataSize(0), _instance(0) {
+ }
~Resource() {
+ if (_instance)
+ _instance->unload();
+ delete _instance;
unloadData();
}
void loadData();
void unloadData();
};
-struct ResourceLoaderInfo {
- Resource *_res;
- byte *_data;
- uint32 _dataSize;
-};
-
enum {
kRlfLoadFile,
- kRlfFreeDataAfterUse
+ kRlfFreeDataAfterLoad
};
class BaseResourceLoader {
diff --git a/engines/illusions/scriptresource.cpp b/engines/illusions/scriptresource.cpp
index 5d93e2a9b7..28e56da36f 100644
--- a/engines/illusions/scriptresource.cpp
+++ b/engines/illusions/scriptresource.cpp
@@ -28,18 +28,13 @@ namespace Illusions {
// ScriptResourceLoader
void ScriptResourceLoader::load(Resource *resource) {
- debug(2, "ScriptResourceLoader::load() Loading script %08X from %s...", resource->_resId, resource->_filename.c_str());
-
- ScriptResource *scriptResource = new ScriptResource();
- scriptResource->load(resource);
-
- _vm->_scriptResource = scriptResource;
-
+ ScriptInstance *scriptInstance = new ScriptInstance(_vm);
+ scriptInstance->load(resource);
+ resource->_instance = scriptInstance;
}
void ScriptResourceLoader::unload(Resource *resource) {
- delete _vm->_scriptResource;
- _vm->_scriptResource = 0;
+ // TODO Remove method
}
void ScriptResourceLoader::buildFilename(Resource *resource) {
@@ -370,4 +365,20 @@ void ScriptResource::fixupProgInfosDuckman() {
_progInfos[i].fixupProgInfosDuckman();
}
+// ScriptInstance
+
+ScriptInstance::ScriptInstance(IllusionsEngine *vm)
+ : _vm(vm) {
+}
+
+void ScriptInstance::load(Resource *resource) {
+ _vm->_scriptResource = new ScriptResource();
+ _vm->_scriptResource->load(resource);
+}
+
+void ScriptInstance::unload() {
+ delete _vm->_scriptResource;
+ _vm->_scriptResource = 0;
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/scriptresource.h b/engines/illusions/scriptresource.h
index 35c3ed02c8..c168294c44 100644
--- a/engines/illusions/scriptresource.h
+++ b/engines/illusions/scriptresource.h
@@ -134,6 +134,15 @@ public:
void fixupProgInfosDuckman();
};
+class ScriptInstance : public ResourceInstance {
+public:
+ ScriptInstance(IllusionsEngine *vm);
+ virtual void load(Resource *resource);
+ virtual void unload();
+public:
+ IllusionsEngine *_vm;
+};
+
} // End of namespace Illusions
#endif // ILLUSIONS_ACTORRESOURCE_H
diff --git a/engines/illusions/sequenceopcodes.cpp b/engines/illusions/sequenceopcodes.cpp
index ef76c782e6..f2a0225ee1 100644
--- a/engines/illusions/sequenceopcodes.cpp
+++ b/engines/illusions/sequenceopcodes.cpp
@@ -283,7 +283,7 @@ void SequenceOpcodes::opSetPathCtrY(Control *control, OpCall &opCall) {
void SequenceOpcodes::opSetPathWalkPoints(Control *control, OpCall &opCall) {
ARG_INT16(pathWalkPointsIndex);
- BackgroundResource *bgRes = _vm->_backgroundItems->getActiveBgResource();
+ BackgroundResource *bgRes = _vm->_backgroundInstances->getActiveBgResource();
control->_actor->_flags |= 2;
control->_actor->_pathWalkPoints = bgRes->getPathWalkPoints(pathWalkPointsIndex - 1);
}
@@ -301,7 +301,7 @@ void SequenceOpcodes::opSetScale(Control *control, OpCall &opCall) {
void SequenceOpcodes::opSetScaleLayer(Control *control, OpCall &opCall) {
ARG_INT16(scaleLayerIndex);
- BackgroundResource *bgRes = _vm->_backgroundItems->getActiveBgResource();
+ BackgroundResource *bgRes = _vm->_backgroundInstances->getActiveBgResource();
control->_actor->_flags |= 4;
control->_actor->_scaleLayer = bgRes->getScaleLayer(scaleLayerIndex - 1);
int scale = control->_actor->_scaleLayer->getScale(control->_actor->_position);
@@ -314,7 +314,7 @@ void SequenceOpcodes::opDeactivatePathWalkRects(Control *control, OpCall &opCall
void SequenceOpcodes::opSetPathWalkRects(Control *control, OpCall &opCall) {
ARG_INT16(pathWalkRectsIndex);
- BackgroundResource *bgRes = _vm->_backgroundItems->getActiveBgResource();
+ BackgroundResource *bgRes = _vm->_backgroundInstances->getActiveBgResource();
control->_actor->_flags |= 0x0010;
control->_actor->_pathWalkRects = bgRes->getPathWalkRects(pathWalkRectsIndex - 1);
}
@@ -327,7 +327,7 @@ void SequenceOpcodes::opSetPriority(Control *control, OpCall &opCall) {
void SequenceOpcodes::opSetPriorityLayer(Control *control, OpCall &opCall) {
ARG_INT16(priorityLayerIndex);
- BackgroundResource *bgRes = _vm->_backgroundItems->getActiveBgResource();
+ BackgroundResource *bgRes = _vm->_backgroundInstances->getActiveBgResource();
control->_actor->_flags |= 8;
control->_actor->_priorityLayer = bgRes->getPriorityLayer(priorityLayerIndex - 1);
int priority = control->_actor->_priorityLayer->getPriority(control->_actor->_position);
@@ -340,7 +340,7 @@ void SequenceOpcodes::opDisableAutoRegionLayer(Control *control, OpCall &opCall)
void SequenceOpcodes::opSetRegionLayer(Control *control, OpCall &opCall) {
ARG_INT16(regionLayerIndex);
- BackgroundResource *bgRes = _vm->_backgroundItems->getActiveBgResource();
+ BackgroundResource *bgRes = _vm->_backgroundInstances->getActiveBgResource();
control->_actor->_flags |= 0x20;
control->_actor->_regionLayer = bgRes->getRegionLayer(regionLayerIndex - 1);
}
@@ -348,7 +348,7 @@ void SequenceOpcodes::opSetRegionLayer(Control *control, OpCall &opCall) {
void SequenceOpcodes::opSetPalette(Control *control, OpCall &opCall) {
ARG_INT16(paletteIndex);
ARG_BYTE(fromIndex);
- BackgroundResource *bgRes = _vm->_backgroundItems->getActiveBgResource();
+ BackgroundResource *bgRes = _vm->_backgroundInstances->getActiveBgResource();
Palette *palette = bgRes->getPalette(paletteIndex - 1);
_vm->_screen->setPalette(palette->_palette, fromIndex, palette->_count);
}
diff --git a/engines/illusions/soundresource.cpp b/engines/illusions/soundresource.cpp
index 2e658431f5..1f14e2ce9d 100644
--- a/engines/illusions/soundresource.cpp
+++ b/engines/illusions/soundresource.cpp
@@ -29,6 +29,7 @@ namespace Illusions {
// SoundGroupResourceLoader
void SoundGroupResourceLoader::load(Resource *resource) {
+#if 0 // ### TODO
debug("SoundGroupResourceLoader::load() Loading sound group %08X...", resource->_resId);
SoundGroupResource *soundGroupResource = new SoundGroupResource();
soundGroupResource->load(resource->_data, resource->_dataSize);
@@ -38,12 +39,15 @@ void SoundGroupResourceLoader::load(Resource *resource) {
SoundEffect *soundEffect = &soundGroupResource->_soundEffects[i];
_vm->_soundMan->loadSound(soundEffect->_soundEffectId, resource->_resId, soundEffect->_looping);
}
+#endif
}
void SoundGroupResourceLoader::unload(Resource *resource) {
+#if 0 // ### TODO
debug("SoundGroupResourceLoader::unload() Unloading sound group %08X...", resource->_resId);
_vm->_soundMan->unloadSounds(resource->_resId);
delete (SoundGroupResource*)resource->_refId;
+#endif
}
void SoundGroupResourceLoader::buildFilename(Resource *resource) {
@@ -53,7 +57,7 @@ void SoundGroupResourceLoader::buildFilename(Resource *resource) {
bool SoundGroupResourceLoader::isFlag(int flag) {
return
flag == kRlfLoadFile/* ||
- flag == kRlfFreeDataAfterUse*/;
+ flag == kRlfFreeDataAfterLoad*/;
}
// SoundEffect
diff --git a/engines/illusions/talkresource.cpp b/engines/illusions/talkresource.cpp
index f100aebcc8..e9d54331e5 100644
--- a/engines/illusions/talkresource.cpp
+++ b/engines/illusions/talkresource.cpp
@@ -29,20 +29,11 @@ namespace Illusions {
// TalkResourceLoader
void TalkResourceLoader::load(Resource *resource) {
- debug("TalkResourceLoader::load() Loading text %08X from %s...", resource->_resId, resource->_filename.c_str());
-
- TalkResource *talkResource = new TalkResource();
- talkResource->load(resource->_data, resource->_dataSize);
- resource->_refId = talkResource;
-
- TalkItem *talkItem = _vm->_talkItems->newTalkItem(resource->_resId, resource->_tag, talkResource);
- talkItem->registerResources();
+ resource->_instance = _vm->_talkItems->createTalkInstance(resource);
}
void TalkResourceLoader::unload(Resource *resource) {
- TalkItem *talkItem = _vm->_talkItems->findTalkItem(resource->_resId);
- talkItem->unregisterResources();
- _vm->_talkItems->freeTalkItem(talkItem);
+ // TODO Remove method
}
void TalkResourceLoader::buildFilename(Resource *resource) {
@@ -91,41 +82,53 @@ void TalkResource::load(byte *data, uint32 dataSize) {
}
}
-// TalkItem
+// TalkInstance
-TalkItem::TalkItem(IllusionsEngine *vm, uint32 talkId, uint32 tag, TalkResource *talkResource)
- : _vm(vm), _talkId(talkId), _tag(tag), _talkRes(talkResource), _pauseCtr(0) {
+TalkInstance::TalkInstance(IllusionsEngine *vm)
+ : _vm(vm), _pauseCtr(0) {
}
-TalkItem::~TalkItem() {
-}
-
-void TalkItem::registerResources() {
- for (uint i = 0; i < _talkRes->_talkEntriesCount; ++i) {
- TalkEntry *talkEntry = &_talkRes->_talkEntries[i];
- _vm->_dict->addTalkEntry(talkEntry->_talkId, talkEntry);
- }
+void TalkInstance::load(Resource *resource) {
+ TalkResource *talkResource = new TalkResource();
+ talkResource->load(resource->_data, resource->_dataSize);
+ _talkRes = talkResource;
+ _talkId = resource->_resId;
+ _tag = resource->_tag;
+ registerResources();
}
-void TalkItem::unregisterResources() {
- for (uint i = 0; i < _talkRes->_talkEntriesCount; ++i) {
- TalkEntry *talkEntry = &_talkRes->_talkEntries[i];
- _vm->_dict->removeTalkEntry(talkEntry->_talkId);
- }
+void TalkInstance::unload() {
+ unregisterResources();
+ _vm->_talkItems->removeTalkInstance(this);
+ delete _talkRes;
}
-void TalkItem::pause() {
+void TalkInstance::pause() {
++_pauseCtr;
if (_pauseCtr == 1)
unregisterResources();
}
-void TalkItem::unpause() {
+void TalkInstance::unpause() {
--_pauseCtr;
if (_pauseCtr == 0)
registerResources();
}
+void TalkInstance::registerResources() {
+ for (uint i = 0; i < _talkRes->_talkEntriesCount; ++i) {
+ TalkEntry *talkEntry = &_talkRes->_talkEntries[i];
+ _vm->_dict->addTalkEntry(talkEntry->_talkId, talkEntry);
+ }
+}
+
+void TalkInstance::unregisterResources() {
+ for (uint i = 0; i < _talkRes->_talkEntriesCount; ++i) {
+ TalkEntry *talkEntry = &_talkRes->_talkEntries[i];
+ _vm->_dict->removeTalkEntry(talkEntry->_talkId);
+ }
+}
+
// TalkItems
TalkItems::TalkItems(IllusionsEngine *vm)
@@ -135,25 +138,25 @@ TalkItems::TalkItems(IllusionsEngine *vm)
TalkItems::~TalkItems() {
}
-TalkItem *TalkItems::newTalkItem(uint32 talkId, uint32 tag, TalkResource *talkResource) {
- TalkItem *talkItem = new TalkItem(_vm, talkId, tag, talkResource);
- _items.push_back(talkItem);
- return talkItem;
+TalkInstance *TalkItems::createTalkInstance(Resource *resource) {
+ TalkInstance *talkInstance = new TalkInstance(_vm);
+ talkInstance->load(resource);
+ _items.push_back(talkInstance);
+ return talkInstance;
}
-void TalkItems::freeTalkItem(TalkItem *talkItem) {
- _items.remove(talkItem);
- delete talkItem;
+void TalkItems::removeTalkInstance(TalkInstance *talkInstance) {
+ _items.remove(talkInstance);
}
-TalkItem *TalkItems::findTalkItem(uint32 talkId) {
+TalkInstance *TalkItems::findTalkItem(uint32 talkId) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
if ((*it)->_talkId == talkId)
return (*it);
return 0;
}
-TalkItem *TalkItems::findTalkItemByTag(uint32 tag) {
+TalkInstance *TalkItems::findTalkItemByTag(uint32 tag) {
for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
if ((*it)->_tag == tag)
return (*it);
@@ -161,15 +164,15 @@ TalkItem *TalkItems::findTalkItemByTag(uint32 tag) {
}
void TalkItems::pauseByTag(uint32 tag) {
- TalkItem *talkItem = findTalkItemByTag(tag);
- if (talkItem)
- talkItem->pause();
+ TalkInstance *talkInstance = findTalkItemByTag(tag);
+ if (talkInstance)
+ talkInstance->pause();
}
void TalkItems::unpauseByTag(uint32 tag) {
- TalkItem *talkItem = findTalkItemByTag(tag);
- if (talkItem)
- talkItem->unpause();
+ TalkInstance *talkInstance = findTalkItemByTag(tag);
+ if (talkInstance)
+ talkInstance->unpause();
}
} // End of namespace Illusions
diff --git a/engines/illusions/talkresource.h b/engines/illusions/talkresource.h
index ff82645508..7f86a36bcc 100644
--- a/engines/illusions/talkresource.h
+++ b/engines/illusions/talkresource.h
@@ -61,12 +61,11 @@ public:
TalkEntry *_talkEntries;
};
-class TalkItem {
+class TalkInstance : public ResourceInstance {
public:
- TalkItem(IllusionsEngine *vm, uint32 talkId, uint32 tag, TalkResource *talkResource);
- ~TalkItem();
- void registerResources();
- void unregisterResources();
+ TalkInstance(IllusionsEngine *vm);
+ virtual void load(Resource *resource);
+ virtual void unload();
void pause();
void unpause();
public:
@@ -75,21 +74,23 @@ public:
uint32 _tag;
TalkResource *_talkRes;
int _pauseCtr;
+ void registerResources();
+ void unregisterResources();
};
class TalkItems {
public:
TalkItems(IllusionsEngine *vm);
~TalkItems();
- TalkItem *newTalkItem(uint32 talkId, uint32 tag, TalkResource *talkResource);
- void freeTalkItem(TalkItem *talkItem);
- TalkItem *findTalkItem(uint32 talkId);
- TalkItem *findTalkItemByTag(uint32 tag);
+ TalkInstance *createTalkInstance(Resource *resource);
+ void removeTalkInstance(TalkInstance *talkInstance);
+ TalkInstance *findTalkItem(uint32 talkId);
+ TalkInstance *findTalkItemByTag(uint32 tag);
void pauseByTag(uint32 tag);
void unpauseByTag(uint32 tag);
//protected:
public:
- typedef Common::List<TalkItem*> Items;
+ typedef Common::List<TalkInstance*> Items;
typedef Items::iterator ItemsIterator;
IllusionsEngine *_vm;
Items _items;