aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2010-01-11 22:46:24 +0200
committerEugene Sandulenko2015-12-27 15:39:52 +0100
commitd9e0667dcc8abb21cbad2d1afd542d3a4bb51873 (patch)
tree4e086a56c579fe3c070d387ae41738afff574da3
parent406a05aec194729a711e13f9be5163069c931ede (diff)
downloadscummvm-rg350-d9e0667dcc8abb21cbad2d1afd542d3a4bb51873.tar.gz
scummvm-rg350-d9e0667dcc8abb21cbad2d1afd542d3a4bb51873.tar.bz2
scummvm-rg350-d9e0667dcc8abb21cbad2d1afd542d3a4bb51873.zip
WAGE: Move MacResManager to Common
Signed-off-by: Eugene Sandulenko <sev@scummvm.org>
-rw-r--r--engines/wage/macresman.cpp396
-rw-r--r--engines/wage/macresman.h94
-rw-r--r--engines/wage/module.mk1
-rw-r--r--engines/wage/wage.cpp3
-rw-r--r--engines/wage/wage.h6
-rw-r--r--engines/wage/world.cpp16
-rw-r--r--engines/wage/world.h2
7 files changed, 13 insertions, 505 deletions
diff --git a/engines/wage/macresman.cpp b/engines/wage/macresman.cpp
deleted file mode 100644
index 02ea6c9156..0000000000
--- a/engines/wage/macresman.cpp
+++ /dev/null
@@ -1,396 +0,0 @@
-/* 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.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/scummsys.h"
-#include "common/debug.h"
-#include "common/file.h"
-#include "common/util.h"
-
-#include "wage/macresman.h"
-
-namespace Wage {
-
-MacResManager::MacResManager(Common::String fileName) : _fileName(fileName), _resOffset(-1) {
- _resFile.open(_fileName);
-
- if (!_resFile.isOpen()) {
- error("Cannot open file %s", _fileName.c_str());
- }
-
- if (!init())
- error("Resource fork is missing in file '%s'", _fileName.c_str());
-}
-
-MacResManager::~MacResManager() {
- for (int i = 0; i < _resMap.numTypes; i++) {
- for (int j = 0; j < _resTypes[i].items; j++) {
- if (_resLists[i][j].nameOffset != -1) {
- delete _resLists[i][j].name;
- }
- }
- delete _resLists[i];
- }
-
- delete _resLists;
- delete _resTypes;
-
- _resFile.close();
-}
-
-#define MBI_INFOHDR 128
-#define MBI_ZERO1 0
-#define MBI_NAMELEN 1
-#define MBI_ZERO2 74
-#define MBI_ZERO3 82
-#define MBI_DFLEN 83
-#define MBI_RFLEN 87
-#define MAXNAMELEN 63
-
-bool MacResManager::init() {
- byte infoHeader[MBI_INFOHDR];
- int32 data_size, rsrc_size;
- int32 data_size_pad, rsrc_size_pad;
- int filelen;
-
- filelen = _resFile.size();
- _resFile.read(infoHeader, MBI_INFOHDR);
-
- // Maybe we have MacBinary?
- if (infoHeader[MBI_ZERO1] == 0 && infoHeader[MBI_ZERO2] == 0 &&
- infoHeader[MBI_ZERO3] == 0 && infoHeader[MBI_NAMELEN] <= MAXNAMELEN) {
-
- // Pull out fork lengths
- data_size = READ_BE_UINT32(infoHeader + MBI_DFLEN);
- rsrc_size = READ_BE_UINT32(infoHeader + MBI_RFLEN);
-
- data_size_pad = (((data_size + 127) >> 7) << 7);
- rsrc_size_pad = (((rsrc_size + 127) >> 7) << 7);
-
- // Length check
- int sumlen = MBI_INFOHDR + data_size_pad + rsrc_size_pad;
-
- if (sumlen == filelen)
- _resOffset = MBI_INFOHDR + data_size_pad;
- }
-
- if (_resOffset == -1) // MacBinary check is failed
- _resOffset = 0; // Maybe we have dumped fork?
-
- _resFile.seek(_resOffset);
-
- _dataOffset = _resFile.readUint32BE() + _resOffset;
- _mapOffset = _resFile.readUint32BE() + _resOffset;
- _dataLength = _resFile.readUint32BE();
- _mapLength = _resFile.readUint32BE();
-
- // do sanity check
- if (_dataOffset >= filelen || _mapOffset >= filelen ||
- _dataLength + _mapLength > filelen) {
- _resOffset = -1;
- return false;
- }
-
- debug(7, "got header: data %d [%d] map %d [%d]",
- _dataOffset, _dataLength, _mapOffset, _mapLength);
-
- readMap();
-
- return true;
-}
-
-MacResIDArray MacResManager::getResIDArray(const char *typeID) {
- int typeNum = -1;
- MacResIDArray res;
-
- for (int i = 0; i < _resMap.numTypes; i++)
- if (strcmp(_resTypes[i].id, typeID) == 0) {
- typeNum = i;
- break;
- }
-
- if (typeNum == -1)
- return res;
-
- res.resize(_resTypes[typeNum].items);
-
- for (int i = 0; i < _resTypes[typeNum].items; i++)
- res[i] = _resLists[typeNum][i].id;
-
- return res;
-}
-
-char *MacResManager::getResName(const char *typeID, int16 resID) {
- int i;
- int typeNum = -1;
-
- for (i = 0; i < _resMap.numTypes; i++)
- if (strcmp(_resTypes[i].id, typeID) == 0) {
- typeNum = i;
- break;
- }
-
- if (typeNum == -1)
- return NULL;
-
- for (i = 0; i < _resTypes[typeNum].items; i++)
- if (_resLists[typeNum][i].id == resID)
- return _resLists[typeNum][i].name;
-
- return NULL;
-}
-
-byte *MacResManager::getResource(const char *typeID, int16 resID, int *size) {
- int i;
- int typeNum = -1;
- int resNum = -1;
- byte *buf;
- int len;
-
- for (i = 0; i < _resMap.numTypes; i++)
- if (strcmp(_resTypes[i].id, typeID) == 0) {
- typeNum = i;
- break;
- }
-
- if (typeNum == -1)
- return NULL;
-
- for (i = 0; i < _resTypes[typeNum].items; i++)
- if (_resLists[typeNum][i].id == resID) {
- resNum = i;
- break;
- }
-
- if (resNum == -1)
- return NULL;
-
- _resFile.seek(_dataOffset + _resLists[typeNum][resNum].dataOffset);
-
- len = _resFile.readUint32BE();
- buf = (byte *)malloc(len);
-
- _resFile.read(buf, len);
-
- *size = len;
-
- return buf;
-}
-
-void MacResManager::readMap() {
- int i, j, len;
-
- _resFile.seek(_mapOffset + 22);
-
- _resMap.resAttr = _resFile.readUint16BE();
- _resMap.typeOffset = _resFile.readUint16BE();
- _resMap.nameOffset = _resFile.readUint16BE();
- _resMap.numTypes = _resFile.readUint16BE();
- _resMap.numTypes++;
-
- _resFile.seek(_mapOffset + _resMap.typeOffset + 2);
- _resTypes = new ResType[_resMap.numTypes];
-
- for (i = 0; i < _resMap.numTypes; i++) {
- _resFile.read(_resTypes[i].id, 4);
- _resTypes[i].id[4] = 0;
- _resTypes[i].items = _resFile.readUint16BE();
- _resTypes[i].offset = _resFile.readUint16BE();
- _resTypes[i].items++;
-
- debug(8, "resType: <%s> items: %d offset: %d (0x%x)", _resTypes[i].id, _resTypes[i].items, _resTypes[i].offset, _resTypes[i].offset);
- }
-
- _resLists = new ResPtr[_resMap.numTypes];
-
- for (i = 0; i < _resMap.numTypes; i++) {
- _resLists[i] = new Resource[_resTypes[i].items];
- _resFile.seek(_resTypes[i].offset + _mapOffset + _resMap.typeOffset);
-
- for (j = 0; j < _resTypes[i].items; j++) {
- ResPtr resPtr = _resLists[i] + j;
-
- resPtr->id = _resFile.readUint16BE();
- resPtr->nameOffset = _resFile.readUint16BE();
- resPtr->dataOffset = _resFile.readUint32BE();
- _resFile.readUint32BE();
- resPtr->name = 0;
-
- resPtr->attr = resPtr->dataOffset >> 24;
- resPtr->dataOffset &= 0xFFFFFF;
- }
-
- for (j = 0; j < _resTypes[i].items; j++) {
- if (_resLists[i][j].nameOffset != -1) {
- _resFile.seek(_resLists[i][j].nameOffset + _mapOffset + _resMap.nameOffset);
-
- len = _resFile.readByte();
- _resLists[i][j].name = new char[len + 1];
- _resLists[i][j].name[len] = 0;
- _resFile.read(_resLists[i][j].name, len);
- }
- }
- }
-}
-
-void MacResManager::convertCursor(byte *data, int datasize, byte **cursor, int *w, int *h,
- int *hotspot_x, int *hotspot_y, int *keycolor, bool colored, byte **palette, int *palSize) {
- Common::MemoryReadStream dis(data, datasize);
- int i, b;
- byte imageByte;
- byte *iconData;
- int numBytes;
- int pixelsPerByte, bpp;
- int ctSize;
- byte bitmask;
- int iconRowBytes, iconBounds[4];
- int ignored;
- int iconDataSize;
-
- dis.readUint16BE(); // type
- dis.readUint32BE(); // offset to pixel map
- dis.readUint32BE(); // offset to pixel data
- dis.readUint32BE(); // expanded cursor data
- dis.readUint16BE(); // expanded data depth
- dis.readUint32BE(); // reserved
-
- // Grab B/W icon data
- *cursor = (byte *)malloc(16 * 16);
- for (i = 0; i < 32; i++) {
- imageByte = dis.readByte();
- for (b = 0; b < 8; b++)
- cursor[0][i*8+b] = (byte)((imageByte &
- (0x80 >> b)) > 0? 0x0F: 0x00);
- }
-
- // Apply mask data
- for (i = 0; i < 32; i++) {
- imageByte = dis.readByte();
- for (b = 0; b < 8; b++)
- if ((imageByte & (0x80 >> b)) == 0)
- cursor[0][i*8+b] = 0xff;
- }
-
- *hotspot_y = dis.readUint16BE();
- *hotspot_x = dis.readUint16BE();
- *w = *h = 16;
-
- // Use b/w cursor on backends which don't support cursor palettes
- if (!colored)
- return;
-
- dis.readUint32BE(); // reserved
- dis.readUint32BE(); // cursorID
-
- // Color version of cursor
- dis.readUint32BE(); // baseAddr
-
- // Keep only lowbyte for now
- dis.readByte();
- iconRowBytes = dis.readByte();
-
- if (!iconRowBytes)
- return;
-
- iconBounds[0] = dis.readUint16BE();
- iconBounds[1] = dis.readUint16BE();
- iconBounds[2] = dis.readUint16BE();
- iconBounds[3] = dis.readUint16BE();
-
- dis.readUint16BE(); // pmVersion
- dis.readUint16BE(); // packType
- dis.readUint32BE(); // packSize
-
- dis.readUint32BE(); // hRes
- dis.readUint32BE(); // vRes
-
- dis.readUint16BE(); // pixelType
- dis.readUint16BE(); // pixelSize
- dis.readUint16BE(); // cmpCount
- dis.readUint16BE(); // cmpSize
-
- dis.readUint32BE(); // planeByte
- dis.readUint32BE(); // pmTable
- dis.readUint32BE(); // reserved
-
- // Pixel data for cursor
- iconDataSize = iconRowBytes * (iconBounds[3] - iconBounds[1]);
- iconData = (byte *)malloc(iconDataSize);
- dis.read(iconData, iconDataSize);
-
- // Color table
- dis.readUint32BE(); // ctSeed
- dis.readUint16BE(); // ctFlag
- ctSize = dis.readUint16BE() + 1;
-
- *palette = (byte *)malloc(ctSize * 4);
-
- // Read just high byte of 16-bit color
- for (int c = 0; c < ctSize; c++) {
- // We just use indices 0..ctSize, so ignore color ID
- dis.readUint16BE(); // colorID[c]
-
- palette[0][c * 4 + 0] = dis.readByte();
- ignored = dis.readByte();
-
- palette[0][c * 4 + 1] = dis.readByte();
- ignored = dis.readByte();
-
- palette[0][c * 4 + 2] = dis.readByte();
- ignored = dis.readByte();
-
- palette[0][c * 4 + 3] = 0;
- }
-
- *palSize = ctSize;
-
- numBytes =
- (iconBounds[2] - iconBounds[0]) *
- (iconBounds[3] - iconBounds[1]);
-
- pixelsPerByte = (iconBounds[2] - iconBounds[0]) / iconRowBytes;
- bpp = 8 / pixelsPerByte;
-
- // build a mask to make sure the pixels are properly shifted out
- bitmask = 0;
- for (int m = 0; m < bpp; m++) {
- bitmask <<= 1;
- bitmask |= 1;
- }
-
- // Extract pixels from bytes
- for (int j = 0; j < iconDataSize; j++)
- for (b = 0; b < pixelsPerByte; b++) {
- int idx = j * pixelsPerByte + (pixelsPerByte - 1 - b);
-
- if (cursor[0][idx] != 0xff) // if mask is not there
- cursor[0][idx] = (byte)((iconData[j] >> (b * bpp)) & bitmask);
- }
-
- free(iconData);
-
- assert(datasize - dis.pos() == 0);
-}
-
-} // End of namespace Wage
diff --git a/engines/wage/macresman.h b/engines/wage/macresman.h
deleted file mode 100644
index c09f4f7a6d..0000000000
--- a/engines/wage/macresman.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/* 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.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/array.h"
-#include "common/file.h"
-
-#ifndef WAGE_MACRESMAN_H
-#define WAGE_MACRESMAN_H
-
-namespace Wage {
-
-typedef Common::Array<int16> MacResIDArray;
-
-class MacResManager {
-
-public:
- MacResManager(Common::String fileName);
- ~MacResManager();
- byte *getResource(const char *typeID, int16 resID, int *size);
- char *getResName(const char *typeID, int16 resID);
- void convertCursor(byte *data, int datasize, byte **cursor, int *w, int *h,
- int *hotspot_x, int *hotspot_y, int *keycolor, bool colored, byte **palette, int *palSize);
-
- MacResIDArray getResIDArray(const char *typeID);
-
- Common::String getFileName() { return _fileName; }
-
-private:
- int extractResource(int id, byte **buf);
- bool init();
- void readMap();
-
- struct ResMap {
- int16 resAttr;
- int16 typeOffset;
- int16 nameOffset;
- int16 numTypes;
- };
-
- struct ResType {
- char id[5];
- int16 items;
- int16 offset;
- };
-
- struct Resource {
- int16 id;
- int16 nameOffset;
- byte attr;
- int32 dataOffset;
- char *name;
- };
-
- typedef Resource *ResPtr;
-
-private:
- int _resOffset;
- int32 _dataOffset;
- int32 _dataLength;
- int32 _mapOffset;
- int32 _mapLength;
- ResMap _resMap;
- ResType *_resTypes;
- ResPtr *_resLists;
-
- Common::String _fileName;
- Common::File _resFile;
-};
-
-} // End of namespace Wage
-
-#endif
diff --git a/engines/wage/module.mk b/engines/wage/module.mk
index e314b1ab8c..19d56cfc67 100644
--- a/engines/wage/module.mk
+++ b/engines/wage/module.mk
@@ -4,7 +4,6 @@ MODULE_OBJS := \
design.o \
detection.o \
entities.o \
- macresman.o \
script.o \
util.o \
wage.o \
diff --git a/engines/wage/wage.cpp b/engines/wage/wage.cpp
index 1efd3f0442..79c48e8a4a 100644
--- a/engines/wage/wage.cpp
+++ b/engines/wage/wage.cpp
@@ -31,7 +31,6 @@
#include "common/fs.h"
#include "wage/wage.h"
-#include "wage/macresman.h"
#include "wage/entities.h"
#include "wage/world.h"
@@ -63,7 +62,7 @@ Common::Error WageEngine::run() {
printf("WageEngine::init\n");
// Your main even loop should be (invoked from) here.
- _resManager = new MacResManager(getGameFile());
+ _resManager = new Common::MacResManager(getGameFile());
_world = new World();
diff --git a/engines/wage/wage.h b/engines/wage/wage.h
index 75a76e1fb2..36ca44bc0f 100644
--- a/engines/wage/wage.h
+++ b/engines/wage/wage.h
@@ -31,13 +31,13 @@
#include "gui/debugger.h"
#include "common/endian.h"
#include "common/rect.h"
+#include "common/macresman.h"
struct ADGameDescription;
namespace Wage {
class Console;
-class MacResManager;
class World;
using Common::String;
@@ -68,7 +68,7 @@ public:
const char *getGameFile() const;
private:
- bool loadWorld(MacResManager *resMan);
+ bool loadWorld(Common::MacResManager *resMan);
private:
Console *_console;
@@ -78,7 +78,7 @@ private:
const ADGameDescription *_gameDescription;
- MacResManager *_resManager;
+ Common::MacResManager *_resManager;
World *_world;
};
diff --git a/engines/wage/world.cpp b/engines/wage/world.cpp
index 0e3850c930..db71b7ea85 100644
--- a/engines/wage/world.cpp
+++ b/engines/wage/world.cpp
@@ -24,7 +24,7 @@
*/
#include "wage/wage.h"
-#include "wage/macresman.h"
+#include "common/macresman.h"
#include "wage/entities.h"
#include "wage/script.h"
#include "wage/world.h"
@@ -39,11 +39,11 @@ World::World() {
_scenes[STORAGESCENE] = &_storageScene;
}
-bool World::loadWorld(MacResManager *resMan) {
+bool World::loadWorld(Common::MacResManager *resMan) {
int resSize;
- MacResIDArray resArray;
+ Common::MacResIDArray resArray;
byte *res;
- MacResIDArray::const_iterator iter;
+ Common::MacResIDArray::const_iterator iter;
if ((resArray = resMan->getResIDArray("GCOD")).size() == 0)
return false;
@@ -169,13 +169,13 @@ void World::loadExternalSounds(String fname) {
}
in.close();
- MacResManager *resMan;
- resMan = new MacResManager(fname);
+ Common::MacResManager *resMan;
+ resMan = new Common::MacResManager(fname);
int resSize;
- MacResIDArray resArray;
+ Common::MacResIDArray resArray;
byte *res;
- MacResIDArray::const_iterator iter;
+ Common::MacResIDArray::const_iterator iter;
resArray = resMan->getResIDArray("ASND");
for (iter = resArray.begin(); iter != resArray.end(); ++iter) {
diff --git a/engines/wage/world.h b/engines/wage/world.h
index 0086db21d9..74bd82a0a1 100644
--- a/engines/wage/world.h
+++ b/engines/wage/world.h
@@ -35,7 +35,7 @@ public:
World();
~World();
- bool loadWorld(MacResManager *resMan);
+ bool loadWorld(Common::MacResManager *resMan);
void loadExternalSounds(String fname);
String _name;