ADL: Use HashMaps for room/global pics

This commit is contained in:
Walter van Niftrik 2016-03-26 16:27:51 +01:00 committed by Walter van Niftrik
parent aa661fae5c
commit bd588d9615
5 changed files with 18 additions and 43 deletions

View file

@ -86,9 +86,7 @@ struct Room {
bool isFirstTime;
};
struct Picture {
DataBlockPtr data;
};
typedef Common::HashMap<byte, DataBlockPtr> PictureMap;
typedef Common::Array<byte> Script;
@ -164,14 +162,9 @@ struct State {
typedef Common::List<Command> Commands;
typedef Common::HashMap<Common::String, uint> WordMap;
struct Picture2 {
byte nr;
DataBlockPtr data;
};
struct RoomData {
Common::String description;
Common::Array<Picture2> pictures;
PictureMap pictures;
Commands commands;
};
@ -272,7 +265,7 @@ protected:
// Message strings in data file
Common::Array<Common::String> _messages;
// Picture data
Common::Array<Picture> _pictures;
PictureMap _pictures;
// Dropped item screen offsets
Common::Array<Common::Point> _itemOffsets;
// <room, verb, noun, script> lists

View file

@ -166,13 +166,11 @@ void HiRes1Engine::init() {
// Load picture data from executable
stream->seek(IDI_HR1_OFS_PICS);
for (uint i = 0; i < IDI_HR1_NUM_PICS; ++i) {
struct Picture pic;
for (uint i = 1; i <= IDI_HR1_NUM_PICS; ++i) {
byte block = stream->readByte();
Common::String name = Common::String::format("BLOCK%i", block);
uint16 offset = stream->readUint16LE();
pic.data = _files->getDataBlock(name, offset);
_pictures.push_back(pic);
_pictures[i] = _files->getDataBlock(name, offset);
}
// Load commands from executable
@ -265,7 +263,7 @@ void HiRes1Engine::restartGame() {
}
void HiRes1Engine::drawPic(byte pic, Common::Point pos) const {
_graphics->drawPic(*_pictures[pic].data->createReadStream(), pos, 0x7f);
_graphics->drawPic(*_pictures[pic]->createReadStream(), pos, 0x7f);
}
void HiRes1Engine::printString(const Common::String &str) {

View file

@ -42,7 +42,7 @@ namespace Adl {
#define IDS_HR1_MESSAGES "MESSAGES"
#define IDI_HR1_NUM_ROOMS 41
#define IDI_HR1_NUM_PICS 98
#define IDI_HR1_NUM_PICS 97
#define IDI_HR1_NUM_VARS 20
#define IDI_HR1_NUM_ITEM_OFFSETS 21
#define IDI_HR1_NUM_MESSAGES 167
@ -79,7 +79,7 @@ namespace Adl {
#define IDI_HR1_OFS_ITEMS 0x0100
#define IDI_HR1_OFS_ROOMS 0x050a
#define IDI_HR1_OFS_PICS 0x4b00
#define IDI_HR1_OFS_PICS 0x4b03
#define IDI_HR1_OFS_CMDS_0 0x3c00
#define IDI_HR1_OFS_CMDS_1 0x3d00

View file

@ -41,11 +41,6 @@ DataBlockPtr HiRes2Engine::readDataBlockPtr(Common::ReadStream &f) const {
return _disk.getDataBlock(track, sector, offset, size);
}
void HiRes2Engine::readPictureMeta(Common::ReadStream &f, Picture2 &pic) const {
pic.nr = f.readByte();
pic.data = readDataBlockPtr(f);
}
void HiRes2Engine::runIntro() const {
StreamPtr stream(_disk.createReadStream(0x00, 0xd, 0x17, 1));
@ -105,9 +100,8 @@ void HiRes2Engine::init() {
// Load item picture data
stream.reset(_disk.createReadStream(0x1e, 0x9, 0x05));
for (uint i = 0; i < IDI_HR2_NUM_ITEM_PICS; ++i) {
Picture2 pic;
readPictureMeta(*stream, pic);
_itemPics.push_back(pic);
stream->readByte(); // number
_itemPics.push_back(readDataBlockPtr(*stream));
}
// Load commands from executable
@ -187,22 +181,14 @@ void HiRes2Engine::restartGame() {
}
void HiRes2Engine::drawPic(byte pic, Common::Point pos) const {
Common::Array<Picture2>::const_iterator roomPic;
for (roomPic = _roomData.pictures.begin(); roomPic != _roomData.pictures.end(); ++roomPic) {
if (roomPic->nr == pic) {
StreamPtr stream(roomPic->data->createReadStream());
_graphics->drawPic(*stream, pos, 0);
return;
}
}
// Check global pic list here
if (_roomData.pictures.contains(pic))
_graphics->drawPic(*_roomData.pictures[pic]->createReadStream(), pos, 0);
else
_graphics->drawPic(*_pictures[pic]->createReadStream(), pos, 0);
}
void HiRes2Engine::drawItem(const Item &item, const Common::Point &pos) const {
const Picture2 &pic = _itemPics[item.picture - 1];
StreamPtr stream(pic.data->createReadStream());
StreamPtr stream(_itemPics[item.picture - 1]->createReadStream());
stream->readByte(); // Skip clear opcode
_graphics->drawPic(*stream, pos, 0);
}
@ -220,9 +206,8 @@ void HiRes2Engine::loadRoom(byte roomNr) {
uint16 picCount = (descOffset - 4) / 5;
for (uint i = 0; i < picCount; ++i) {
Picture2 pic;
readPictureMeta(*stream, pic);
_roomData.pictures.push_back(pic);
byte nr = stream->readByte();
_roomData.pictures[nr] = readDataBlockPtr(*stream);
}
_roomData.description = readStringAt(*stream, descOffset, 0xff);

View file

@ -66,10 +66,9 @@ private:
void showRoom();
DataBlockPtr readDataBlockPtr(Common::ReadStream &f) const;
void readPictureMeta(Common::ReadStream &f, Picture2 &pic) const;
DiskImage_DSK _disk;
Common::Array<Picture2> _itemPics;
Common::Array<DataBlockPtr> _itemPics;
};
} // End of namespace Adl