Skip to content

Commit

Permalink
ADL: Use HashMaps for room/global pics
Browse files Browse the repository at this point in the history
  • Loading branch information
waltervn committed Jun 6, 2016
1 parent aa661fa commit bd588d9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 43 deletions.
13 changes: 3 additions & 10 deletions engines/adl/adl.h
Expand Up @@ -86,9 +86,7 @@ struct Room {
bool isFirstTime;
};

struct Picture {
DataBlockPtr data;
};
typedef Common::HashMap<byte, DataBlockPtr> PictureMap;

typedef Common::Array<byte> Script;

Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -272,7 +265,7 @@ class AdlEngine : public Engine {
// 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
Expand Down
8 changes: 3 additions & 5 deletions engines/adl/hires1.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions engines/adl/hires1.h
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
33 changes: 9 additions & 24 deletions engines/adl/hires2.cpp
Expand Up @@ -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));

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions engines/adl/hires2.h
Expand Up @@ -66,10 +66,9 @@ class HiRes2Engine : public AdlEngine_v2 {
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
Expand Down

0 comments on commit bd588d9

Please sign in to comment.