diff options
Diffstat (limited to 'engines/illusions')
-rw-r--r-- | engines/illusions/backgroundresource.cpp | 137 | ||||
-rw-r--r-- | engines/illusions/backgroundresource.h | 52 | ||||
-rw-r--r-- | engines/illusions/graphics.cpp | 51 | ||||
-rw-r--r-- | engines/illusions/graphics.h | 46 | ||||
-rw-r--r-- | engines/illusions/illusions.cpp | 26 | ||||
-rw-r--r-- | engines/illusions/illusions.h | 15 | ||||
-rw-r--r-- | engines/illusions/module.mk | 3 | ||||
-rw-r--r-- | engines/illusions/resourcesystem.cpp | 13 |
8 files changed, 338 insertions, 5 deletions
diff --git a/engines/illusions/backgroundresource.cpp b/engines/illusions/backgroundresource.cpp index 34d1e985cd..246172fd93 100644 --- a/engines/illusions/backgroundresource.cpp +++ b/engines/illusions/backgroundresource.cpp @@ -29,7 +29,26 @@ namespace Illusions { // BackgroundResourceLoader void BackgroundResourceLoader::load(Resource *resource) { + // TODO debug("BackgroundResourceLoader::load() Loading background %08X from %s...", resource->_resId, resource->_filename.c_str()); + + BackgroundResource *backgroundResource = new BackgroundResource(); + backgroundResource->load(resource->_data, resource->_dataSize); + + BackgroundItem *backgroundItem = _vm->allocBackgroundItem(); + backgroundItem->_bgRes = backgroundResource; + backgroundItem->_tag = resource->_tag; + + backgroundItem->initSurface(); + + // TODO Insert objects from item44s + // TODO Insert IDs from item48s + + // TODO camera_fadeClear(); + // TODO bgInfo = &bgResourceb->bgInfos[(unsigned __int16)BgResource_findMasterBgIndex(bgResourceb)]; + // TODO camera_set(bgInfo[-1].panPoint, bgInfo[-1].surfInfo.dimensions); + + // NOTE Skipped palette loading (not used in BBDOU) } void BackgroundResourceLoader::unload(Resource *resource) { @@ -44,4 +63,122 @@ 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) { + _width = stream.readSint16LE(); + _height = stream.readSint16LE(); + stream.skip(4); // Unknown + uint32 mapOffs = stream.pos(); + _map = dataStart + mapOffs; + + debug("TileMap::load() _width: %d; _height: %d", + _width, _height); +} + +// BgInfo + +void BgInfo::load(byte *dataStart, Common::SeekableReadStream &stream) { + _flags = stream.readUint32LE(); + stream.skip(2); // Unknown + _priorityBase = stream.readSint16LE(); + _surfInfo.load(stream); + loadPoint(stream, _panPoint); + uint32 tileMapOffs = stream.readUint32LE(); + uint32 tilePixelsOffs = stream.readUint32LE(); + stream.seek(tileMapOffs); + _tileMap.load(dataStart, stream); + _tilePixels = dataStart + tilePixelsOffs; + + debug("BgInfo::load() _flags: %08X; _priorityBase: %d; tileMapOffs: %08X; tilePixelsOffs: %08X", + _flags, _priorityBase, tileMapOffs, tilePixelsOffs); +} + +// BackgroundResource + +BackgroundResource::BackgroundResource() { +} + +BackgroundResource::~BackgroundResource() { + // TODO Free stuff +} + +void BackgroundResource::load(byte *data, uint32 dataSize) { + Common::MemoryReadStream stream(data, dataSize, DisposeAfterUse::NO); + // TODO A lot + + // Load background pixels + stream.seek(0x0A); + _bgInfosCount = stream.readUint16LE(); + _bgInfos = new BgInfo[_bgInfosCount]; + stream.seek(0x20); + uint32 bgInfosOffs = stream.readUint32LE(); + for (uint i = 0; i < _bgInfosCount; ++i) { + stream.seek(bgInfosOffs + i * 0x1C); + _bgInfos[i].load(data, stream); + } + +} + +int BackgroundResource::findMasterBgIndex() { + int index = 1; + while (!_bgInfos[index - 1]._flags & 1) + ++index; + return index; +} + } // End of namespace Illusions diff --git a/engines/illusions/backgroundresource.h b/engines/illusions/backgroundresource.h index 58eed03f70..ab8268794f 100644 --- a/engines/illusions/backgroundresource.h +++ b/engines/illusions/backgroundresource.h @@ -23,11 +23,14 @@ #ifndef ILLUSIONS_BACKGROUNDRESOURCE_H #define ILLUSIONS_BACKGROUNDRESOURCE_H +#include "illusions/graphics.h" #include "illusions/resourcesystem.h" +#include "graphics/surface.h" #include "common/array.h" #include "common/file.h" #include "common/memstream.h" +#include "common/rect.h" #include "common/substream.h" #include "common/system.h" @@ -47,6 +50,55 @@ protected: IllusionsEngine *_vm; }; +struct TileMap { + int16 _width, _height; + //field_4 dd + byte *_map; + void load(byte *dataStart, Common::SeekableReadStream &stream); +}; + +struct BgInfo { + uint32 _flags; + //field_4 dw + int16 _priorityBase; + SurfInfo _surfInfo; + Common::Point _panPoint; + TileMap _tileMap; + byte *_tilePixels; + void load(byte *dataStart, Common::SeekableReadStream &stream); +}; + +class BackgroundResource { +public: + BackgroundResource(); + ~BackgroundResource(); + void load(byte *data, uint32 dataSize); + int findMasterBgIndex(); +public: + + uint _bgInfosCount; + BgInfo *_bgInfos; + +}; + +const uint kMaxBackgroundItemSurfaces = 3; + +class BackgroundItem { +public: + BackgroundItem(IllusionsEngine *vm); + ~BackgroundItem(); + void initSurface(); + void drawTiles(Graphics::Surface *surface, TileMap &tileMap, byte *tilePixels); +public: + IllusionsEngine *_vm; + uint32 _tag; + int _pauseCtr; + BackgroundResource *_bgRes; + Common::Point _panPoints[kMaxBackgroundItemSurfaces]; + Graphics::Surface *_surfaces[kMaxBackgroundItemSurfaces]; + // TODO SavedCamera savedCamera; + // TODO? byte *savedPalette; +}; } // End of namespace Illusions diff --git a/engines/illusions/graphics.cpp b/engines/illusions/graphics.cpp new file mode 100644 index 0000000000..0f27a36e11 --- /dev/null +++ b/engines/illusions/graphics.cpp @@ -0,0 +1,51 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "illusions/graphics.h" + +namespace Illusions { + +void WidthHeight::load(Common::SeekableReadStream &stream) { + _width = stream.readSint16LE(); + _height = stream.readSint16LE(); + + debug("WidthHeight::load() _width: %d; _height: %d", + _width, _height); +} + +void SurfInfo::load(Common::SeekableReadStream &stream) { + _pixelSize = stream.readUint32LE(); + _dimensions.load(stream); + + debug("SurfInfo::load() _pixelSize: %d", + _pixelSize); +} + +void loadPoint(Common::SeekableReadStream &stream, Common::Point &pt) { + pt.x = stream.readSint16LE(); + pt.y = stream.readSint16LE(); + + debug("loadPoint() x: %d; y: %d", + pt.x, pt.y); +} + +} // End of namespace Illusions diff --git a/engines/illusions/graphics.h b/engines/illusions/graphics.h new file mode 100644 index 0000000000..0b16a0c91d --- /dev/null +++ b/engines/illusions/graphics.h @@ -0,0 +1,46 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef ILLUSIONS_GRAPHICS_H +#define ILLUSIONS_GRAPHICS_H + +#include "common/rect.h" +#include "common/stream.h" + +namespace Illusions { + +struct WidthHeight { + int16 _width, _height; + void load(Common::SeekableReadStream &stream); +}; + +struct SurfInfo { + uint32 _pixelSize; + WidthHeight _dimensions; + void load(Common::SeekableReadStream &stream); +}; + +void loadPoint(Common::SeekableReadStream &stream, Common::Point &pt); + +} // End of namespace Illusions + +#endif // ILLUSIONS_GRAPHICS_H diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp index a2e8ee4a55..d0e5b59fa7 100644 --- a/engines/illusions/illusions.cpp +++ b/engines/illusions/illusions.cpp @@ -23,6 +23,7 @@ #include "illusions/illusions.h" #include "illusions/resourcesystem.h" #include "illusions/backgroundresource.h" +#include "illusions/graphics.h" #include "audio/audiostream.h" #include "common/config-manager.h" @@ -72,7 +73,12 @@ Common::Error IllusionsEngine::run() { _resSys = new ResourceSystem(); _resSys->addResourceLoader(0x00110000, new BackgroundResourceLoader(this)); - _resSys->loadResource(0x00110002, 0, 0); + _resSys->loadResource(0x0011000B, 0, 0); + + BackgroundItem *backgroundItem = *(_backgroundItems.begin()); + _system->copyRectToScreen(backgroundItem->_surfaces[0]->getPixels(), backgroundItem->_surfaces[0]->pitch, + 0, 0, 640, 480); + _system->updateScreen(); while (!shouldQuit()) { updateEvents(); @@ -121,4 +127,22 @@ 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); + Graphics::Surface *surface = new Graphics::Surface(); + surface->create(width, height, pixelFormat16); + return surface; +} + +Graphics::Surface *IllusionsEngine::allocSurface(SurfInfo &surfInfo) { + return allocSurface(surfInfo._dimensions._width, surfInfo._dimensions._height); +} + } // End of namespace Illusions diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h index f35f1bb7df..4ab829add0 100644 --- a/engines/illusions/illusions.h +++ b/engines/illusions/illusions.h @@ -36,6 +36,7 @@ #include "common/winexe.h" #include "common/winexe_pe.h" #include "engines/engine.h" +#include "graphics/surface.h" struct ADGameDescription; @@ -45,6 +46,11 @@ namespace Illusions { class ResourceSystem; +struct SurfInfo; + +class BackgroundItem; +class BackgroundResource; + class IllusionsEngine : public Engine { protected: Common::Error run(); @@ -53,15 +59,22 @@ public: IllusionsEngine(OSystem *syst, const ADGameDescription *gd); ~IllusionsEngine(); const Common::String getTargetName() { return _targetName; } + private: const ADGameDescription *_gameDescription; Graphics::PixelFormat _pixelFormat; public: Common::RandomSource *_random; ResourceSystem *_resSys; - + void updateEvents(); + Common::List<BackgroundItem*> _backgroundItems; + BackgroundItem *allocBackgroundItem(); + + Graphics::Surface *allocSurface(int16 width, int16 height); + Graphics::Surface *allocSurface(SurfInfo &surfInfo); + #if 0 // Savegame API diff --git a/engines/illusions/module.mk b/engines/illusions/module.mk index 3cf4e1f6ea..1799409f5c 100644 --- a/engines/illusions/module.mk +++ b/engines/illusions/module.mk @@ -2,8 +2,9 @@ MODULE := engines/illusions MODULE_OBJS := \ backgroundresource.o \ - illusions.o \ detection.o \ + graphics.o \ + illusions.o \ resourcesystem.o # This module can be built as a plugin diff --git a/engines/illusions/resourcesystem.cpp b/engines/illusions/resourcesystem.cpp index f30f46b2c1..01a076bac0 100644 --- a/engines/illusions/resourcesystem.cpp +++ b/engines/illusions/resourcesystem.cpp @@ -23,12 +23,15 @@ #include "illusions/resourcesystem.h" #include "common/algorithm.h" +#include "common/debug.h" namespace Illusions { // Resource void Resource::loadData() { + debug("Resource::loadData()"); + Common::File fd; if (!fd.open(_filename)) error("Resource::loadData() Could not open %s for reading", _filename.c_str()); @@ -38,6 +41,8 @@ void Resource::loadData() { } void Resource::unloadData() { + debug("Resource::unloadData()"); + delete _data; _data = 0; _dataSize = 0; @@ -70,13 +75,17 @@ void ResourceSystem::loadResource(uint32 resId, uint32 tag, uint32 threadId) { resourceLoader->buildFilename(resource); - if (resourceLoader->isFlag(kRlfLoadFile)) + if (resourceLoader->isFlag(kRlfLoadFile)) { + debug("ResourceSystem::loadResource() kRlfLoadFile"); resource->loadData(); + } resourceLoader->load(resource); - if (resourceLoader->isFlag(kRlfFreeDataAfterUse)) + if (resourceLoader->isFlag(kRlfFreeDataAfterUse)) { + debug("ResourceSystem::loadResource() kRlfFreeDataAfterUse"); resource->unloadData(); + } resource->_loaded = true; |