aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorjohndoe1232014-03-11 17:36:10 +0100
committerEugene Sandulenko2018-07-20 06:43:33 +0000
commite0a3db43c3eed0c5bb7f94f408e5534aff1ea17a (patch)
treeba209e4a586ba5359514797625c11dd9877fff45 /engines
parentd92e713dea1dacce2bcc5acc842c8450191116e0 (diff)
downloadscummvm-rg350-e0a3db43c3eed0c5bb7f94f408e5534aff1ea17a.tar.gz
scummvm-rg350-e0a3db43c3eed0c5bb7f94f408e5534aff1ea17a.tar.bz2
scummvm-rg350-e0a3db43c3eed0c5bb7f94f408e5534aff1ea17a.zip
ILLUSIONS: Keep backgrounds in new BackgroundItems class instead of the engine class
Diffstat (limited to 'engines')
-rw-r--r--engines/illusions/backgroundresource.cpp194
-rw-r--r--engines/illusions/backgroundresource.h21
-rw-r--r--engines/illusions/illusions.cpp10
-rw-r--r--engines/illusions/illusions.h4
4 files changed, 165 insertions, 64 deletions
diff --git a/engines/illusions/backgroundresource.cpp b/engines/illusions/backgroundresource.cpp
index 246172fd93..11a5957f28 100644
--- a/engines/illusions/backgroundresource.cpp
+++ b/engines/illusions/backgroundresource.cpp
@@ -35,7 +35,7 @@ void BackgroundResourceLoader::load(Resource *resource) {
BackgroundResource *backgroundResource = new BackgroundResource();
backgroundResource->load(resource->_data, resource->_dataSize);
- BackgroundItem *backgroundItem = _vm->allocBackgroundItem();
+ BackgroundItem *backgroundItem = _vm->_backgroundItems->allocBackgroundItem();
backgroundItem->_bgRes = backgroundResource;
backgroundItem->_tag = resource->_tag;
@@ -63,60 +63,6 @@ bool BackgroundResourceLoader::isFlag(int flag) {
flag == kRlfLoadFile;
}
-// BackgroundItem
-
-BackgroundItem::BackgroundItem(IllusionsEngine *vm) : _vm(vm), _tag(0), _pauseCtr(0), _bgRes(0) {
-}
-
-void BackgroundItem::initSurface() {
-
- for (uint i = 0; i < kMaxBackgroundItemSurfaces; ++i)
- _surfaces[i] = 0;
-
- for (uint i = 0; i < _bgRes->_bgInfosCount; ++i) {
- BgInfo *bgInfo = &_bgRes->_bgInfos[i];
- _panPoints[i] = bgInfo->_panPoint;
- _surfaces[i] = _vm->allocSurface(bgInfo->_surfInfo);
- drawTiles(_surfaces[i], bgInfo->_tileMap, bgInfo->_tilePixels);
- }
-
-}
-
-void BackgroundItem::drawTiles(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels) {
- const int kTileWidth = 32;
- const int kTileHeight = 8;
- const int kTileSize = kTileWidth * kTileHeight * 2;
- uint tileMapIndex = 0;
- for (int tileY = 0; tileY < tileMap._height; ++tileY) {
- int tileDestY = tileY * kTileHeight;
- int tileDestH = MIN(kTileHeight, surface->h - tileDestY);
- for (int tileX = 0; tileX < tileMap._width; ++tileX) {
- int tileDestX = tileX * kTileWidth;
- int tileDestW = MIN(kTileWidth, surface->w - tileDestX);
- uint16 tileIndex = READ_LE_UINT16(tileMap._map + 2 * tileMapIndex);
- ++tileMapIndex;
- byte *src = tilePixels + (tileIndex - 1) * kTileSize;
- byte *dst = (byte*)surface->getBasePtr(tileDestX, tileDestY);
- for (int h = 0; h < tileDestH; ++h) {
- for (int w = 0; w < tileDestW; ++w) {
- uint16 pixel = READ_LE_UINT16(src + w * 2);
- WRITE_LE_UINT16(dst + w * 2, pixel);
- }
- dst += surface->pitch;
- src += kTileWidth * 2;
- }
- }
- }
-
- /*
- Common::DumpFile d;
- d.open("dump.000");
- d.write(surface->getPixels(), surface->h * surface->pitch);
- d.close();
- */
-
-}
-
// TileMap
void TileMap::load(byte *dataStart, Common::SeekableReadStream &stream) {
@@ -181,4 +127,142 @@ int BackgroundResource::findMasterBgIndex() {
return index;
}
+// BackgroundItem
+
+BackgroundItem::BackgroundItem(IllusionsEngine *vm) : _vm(vm), _tag(0), _pauseCtr(0), _bgRes(0) {
+}
+
+void BackgroundItem::initSurface() {
+ for (uint i = 0; i < kMaxBackgroundItemSurfaces; ++i)
+ _surfaces[i] = 0;
+ for (uint i = 0; i < _bgRes->_bgInfosCount; ++i) {
+ BgInfo *bgInfo = &_bgRes->_bgInfos[i];
+ _panPoints[i] = bgInfo->_panPoint;
+ _surfaces[i] = _vm->allocSurface(bgInfo->_surfInfo);
+ drawTiles(_surfaces[i], bgInfo->_tileMap, bgInfo->_tilePixels);
+ }
+}
+
+void BackgroundItem::freeSurface() {
+ for (uint i = 0; i < _bgRes->_bgInfosCount; ++i) {
+ _surfaces[i]->free();
+ delete _surfaces[i];
+ _surfaces[i] = 0;
+ }
+}
+
+void BackgroundItem::drawTiles(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels) {
+ const int kTileWidth = 32;
+ const int kTileHeight = 8;
+ const int kTileSize = kTileWidth * kTileHeight * 2;
+ uint tileMapIndex = 0;
+ for (int tileY = 0; tileY < tileMap._height; ++tileY) {
+ int tileDestY = tileY * kTileHeight;
+ int tileDestH = MIN(kTileHeight, surface->h - tileDestY);
+ for (int tileX = 0; tileX < tileMap._width; ++tileX) {
+ int tileDestX = tileX * kTileWidth;
+ int tileDestW = MIN(kTileWidth, surface->w - tileDestX);
+ uint16 tileIndex = READ_LE_UINT16(tileMap._map + 2 * tileMapIndex);
+ ++tileMapIndex;
+ byte *src = tilePixels + (tileIndex - 1) * kTileSize;
+ byte *dst = (byte*)surface->getBasePtr(tileDestX, tileDestY);
+ for (int h = 0; h < tileDestH; ++h) {
+ for (int w = 0; w < tileDestW; ++w) {
+ uint16 pixel = READ_LE_UINT16(src + w * 2);
+ WRITE_LE_UINT16(dst + w * 2, pixel);
+ }
+ dst += surface->pitch;
+ src += kTileWidth * 2;
+ }
+ }
+ }
+}
+
+void BackgroundItem::pause() {
+ // TODO
+ ++_pauseCtr;
+ if (_pauseCtr <= 1) {
+ /* TODO
+ for (uint i = 0; i < _bgRes->_item48sCount; ++i)
+ krndictRemoveID(_bgRes->_item48s[i].id);
+ */
+ // TODO _vm->setDefPointDimensions1();
+ // TODO memcpy(&_savedCamera, &_vm->camera, sizeof(backgroundItem->savedCamera));
+ /* Unused
+ _savedPalette = malloc(1024);
+ savePalette(_savedPalette);
+ */
+ freeSurface();
+ }
+}
+
+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]);
+ */
+ initSurface();
+ /* Unused
+ restorePalette(_savedPalette, 1, 256);
+ free(_savedPalette);
+ _savedPalette = 0;
+ */
+ // TODO _vm->_screen->_fadeClear();
+ // TODO memcpy(&_vm->camera, &_savedCamera, sizeof(SavedCamera));
+ /* TODO
+ currTime = krnxxxGetCurrentTime();
+ _vm->_camera.panStartTime = currTime;
+ _vm->backgroundItem_refreshPan();
+ */
+ }
+}
+
+// BackgroundItems
+
+BackgroundItems::BackgroundItems(IllusionsEngine *vm)
+ : _vm(vm) {
+}
+
+BackgroundItems::~BackgroundItems() {
+}
+
+BackgroundItem *BackgroundItems::allocBackgroundItem() {
+ BackgroundItem *backgroundItem = new BackgroundItem(_vm);
+ _items.push_back(backgroundItem);
+ return backgroundItem;
+}
+
+void BackgroundItems::pauseByTag(uint32 tag) {
+ for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
+ if ((*it)->_tag == tag)
+ (*it)->pause();
+}
+
+void BackgroundItems::unpauseByTag(uint32 tag) {
+ for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
+ if ((*it)->_tag == tag)
+ (*it)->unpause();
+}
+
+BackgroundItem *BackgroundItems::findActiveBackground() {
+ for (ItemsIterator it = _items.begin(); it != _items.end(); ++it)
+ if ((*it)->_pauseCtr == 0)
+ return (*it);
+ return 0;
+}
+
+BackgroundResource *BackgroundItems::getActiveBgResource() {
+ BackgroundItem *background = findActiveBackground();
+ if (background)
+ return background->_bgRes;
+ return 0;
+}
+
+BackgroundItem *BackgroundItems::debugFirst() {
+ return *(_items.begin());
+}
+
} // End of namespace Illusions
diff --git a/engines/illusions/backgroundresource.h b/engines/illusions/backgroundresource.h
index ab8268794f..7fc70ae5c2 100644
--- a/engines/illusions/backgroundresource.h
+++ b/engines/illusions/backgroundresource.h
@@ -29,6 +29,7 @@
#include "common/array.h"
#include "common/file.h"
+#include "common/list.h"
#include "common/memstream.h"
#include "common/rect.h"
#include "common/substream.h"
@@ -88,7 +89,10 @@ public:
BackgroundItem(IllusionsEngine *vm);
~BackgroundItem();
void initSurface();
+ void freeSurface();
void drawTiles(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels);
+ void pause();
+ void unpause();
public:
IllusionsEngine *_vm;
uint32 _tag;
@@ -100,6 +104,23 @@ public:
// TODO? byte *savedPalette;
};
+class BackgroundItems {
+public:
+ BackgroundItems(IllusionsEngine *vm);
+ ~BackgroundItems();
+ BackgroundItem *allocBackgroundItem();
+ void pauseByTag(uint32 tag);
+ void unpauseByTag(uint32 tag);
+ BackgroundItem *findActiveBackground();
+ BackgroundResource *getActiveBgResource();
+ BackgroundItem *debugFirst();
+protected:
+ typedef Common::List<BackgroundItem*> Items;
+ typedef Items::iterator ItemsIterator;
+ IllusionsEngine *_vm;
+ Items _items;
+};
+
} // End of namespace Illusions
#endif // ILLUSIONS_BACKGROUNDRESOURCE_H
diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp
index 69d57bd7d0..6bfecd32c4 100644
--- a/engines/illusions/illusions.cpp
+++ b/engines/illusions/illusions.cpp
@@ -78,10 +78,11 @@ Common::Error IllusionsEngine::run() {
_resSys = new ResourceSystem();
_resSys->addResourceLoader(0x00110000, new BackgroundResourceLoader(this));
+ _backgroundItems = new BackgroundItems(this);
_resSys->loadResource(0x0011000B, 0, 0);
- BackgroundItem *backgroundItem = *(_backgroundItems.begin());
+ BackgroundItem *backgroundItem = _backgroundItems->debugFirst();
_system->copyRectToScreen(backgroundItem->_surfaces[0]->getPixels(), backgroundItem->_surfaces[0]->pitch,
0, 0, 640, 480);
_system->updateScreen();
@@ -90,6 +91,7 @@ Common::Error IllusionsEngine::run() {
updateEvents();
}
+ delete _backgroundItems;
delete _resSys;
return Common::kNoError;
@@ -133,12 +135,6 @@ void IllusionsEngine::updateEvents() {
}
}
-BackgroundItem *IllusionsEngine::allocBackgroundItem() {
- BackgroundItem *backgroundItem = new BackgroundItem(this);
- _backgroundItems.push_back(backgroundItem);
- return backgroundItem;
-}
-
Graphics::Surface *IllusionsEngine::allocSurface(int16 width, int16 height) {
// TODO Use screen pixel format?
Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0);
diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h
index 39e1b86718..6ebf2e7813 100644
--- a/engines/illusions/illusions.h
+++ b/engines/illusions/illusions.h
@@ -49,6 +49,7 @@ class ResourceSystem;
struct SurfInfo;
class BackgroundItem;
+class BackgroundItems;
class BackgroundResource;
class IllusionsEngine : public Engine {
@@ -69,8 +70,7 @@ public:
void updateEvents();
- Common::List<BackgroundItem*> _backgroundItems;
- BackgroundItem *allocBackgroundItem();
+ BackgroundItems *_backgroundItems;
// Screen functions
Graphics::Surface *allocSurface(int16 width, int16 height);