mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-04 17:29:11 +00:00
cleanup and simplify Resource class a bit more
svn-id: r14488
This commit is contained in:
parent
a7b610b25b
commit
8b0e9502ec
@ -30,9 +30,9 @@ namespace Queen {
|
||||
|
||||
Credits::Credits(QueenEngine *vm, const char* filename) :
|
||||
_vm(vm), _running(true), _count(0), _pause(0), _justify(0), _fontSize(0), _color(0), _zone(0) {
|
||||
_credits = new LineReader(
|
||||
(char *)_vm->resource()->loadFile(filename),
|
||||
_vm->resource()->fileSize(filename));
|
||||
uint32 size;
|
||||
char *buf = (char *)_vm->resource()->loadFile(filename, 0, &size);
|
||||
_credits = new LineReader(buf, size);
|
||||
}
|
||||
|
||||
Credits::~Credits() {
|
||||
|
@ -39,7 +39,6 @@ static const uint8 *_palJoeDress;
|
||||
Display::Display(QueenEngine *vm, OSystem *system)
|
||||
: _fullscreen(true), _horizontalScroll(0), _bdWidth(0), _bdHeight(0),
|
||||
_system(system), _vm(vm) {
|
||||
_dynalum.prevColMask = 0xFF;
|
||||
|
||||
if (vm->resource()->getLanguage() == HEBREW)
|
||||
_font = _fontHebrew;
|
||||
@ -76,6 +75,8 @@ Display::Display(QueenEngine *vm, OSystem *system)
|
||||
_pal.dirtyMin = 0;
|
||||
_pal.dirtyMax = 255;
|
||||
_pal.scrollable = true;
|
||||
|
||||
memset(&_dynalum, 0, sizeof(_dynalum));
|
||||
}
|
||||
|
||||
Display::~Display() {
|
||||
@ -96,23 +97,24 @@ Display::~Display() {
|
||||
|
||||
void Display::dynalumInit(const char *roomName, uint16 roomNum) {
|
||||
debug(9, "Display::dynalumInit(%s, %d)", roomName, roomNum);
|
||||
memset(_dynalum.msk, 0, sizeof(_dynalum.msk));
|
||||
memset(_dynalum.lum, 0, sizeof(_dynalum.lum));
|
||||
|
||||
_dynalum.valid = false;
|
||||
_dynalum.prevColMask = 0xFF;
|
||||
delete[] _dynalum.mskBuf;
|
||||
_dynalum.mskBuf = NULL;
|
||||
delete[] _dynalum.lumBuf;
|
||||
_dynalum.lumBuf = NULL;
|
||||
|
||||
if (!(Logic::isAltIntroRoom(roomNum) || Logic::isIntroRoom(roomNum))) {
|
||||
char filename[20];
|
||||
|
||||
sprintf(filename, "%s.msk", roomName);
|
||||
_dynalum.valid = _vm->resource()->fileExists(filename);
|
||||
if (_dynalum.valid)
|
||||
_vm->resource()->loadFile(filename, 0, (uint8*)_dynalum.msk);
|
||||
|
||||
sprintf(filename, "%s.lum", roomName);
|
||||
_dynalum.valid = _vm->resource()->fileExists(filename);
|
||||
if (_dynalum.valid)
|
||||
_vm->resource()->loadFile(filename, 0, (uint8*)_dynalum.lum);
|
||||
if (_vm->resource()->fileExists(filename)) {
|
||||
_dynalum.mskBuf = (uint8 *)_vm->resource()->loadFile(filename, 0, &_dynalum.mskSize);
|
||||
sprintf(filename, "%s.lum", roomName);
|
||||
if (_vm->resource()->fileExists(filename)) {
|
||||
_dynalum.lumBuf = (int8 *)_vm->resource()->loadFile(filename, 0, &_dynalum.lumSize);
|
||||
_dynalum.valid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,17 +133,17 @@ void Display::dynalumUpdate(int16 x, int16 y) {
|
||||
y = ROOM_ZONE_HEIGHT - 1;
|
||||
}
|
||||
|
||||
uint offset = (y / 4) * 160 + (x / 4);
|
||||
assert(offset < sizeof(_dynalum.msk));
|
||||
uint32 offset = (y / 4) * 160 + (x / 4);
|
||||
assert(offset < _dynalum.mskSize);
|
||||
|
||||
uint8 colMask = _dynalum.msk[offset];
|
||||
uint8 colMask = _dynalum.mskBuf[offset];
|
||||
debug(9, "Display::dynalumUpdate(%d, %d) - colMask = %d", x, y, colMask);
|
||||
if (colMask != _dynalum.prevColMask) {
|
||||
uint8 i;
|
||||
for (i = 144; i < 160; ++i) {
|
||||
uint8 j;
|
||||
for (j = 0; j < 3; ++j) {
|
||||
int16 c = (int16)(_pal.room[i * 3 + j] + _dynalum.lum[colMask * 3 + j] * 4);
|
||||
int16 c = (int16)(_pal.room[i * 3 + j] + _dynalum.lumBuf[colMask * 3 + j] * 4);
|
||||
if (c < 0) {
|
||||
c = 0;
|
||||
} else if (c > 255) {
|
||||
@ -635,8 +637,8 @@ void Display::update(bool dynalum, int16 dynaX, int16 dynaY) {
|
||||
}
|
||||
|
||||
void Display::setupPanel() {
|
||||
uint8 *pcxBuf = _vm->resource()->loadFile("panel.pcx");
|
||||
uint32 size = _vm->resource()->fileSize("panel.pcx");
|
||||
uint32 size;
|
||||
uint8 *pcxBuf = _vm->resource()->loadFile("panel.pcx", 0, &size);
|
||||
uint8 *dst = _panelBuf + PANEL_W * 10;
|
||||
readPCX(dst, PANEL_W, pcxBuf + 128, PANEL_W, PANEL_H - 10);
|
||||
const uint8 *pal = pcxBuf + size - 768 + 144 * 3;
|
||||
@ -648,11 +650,10 @@ void Display::setupPanel() {
|
||||
|
||||
void Display::setupNewRoom(const char *name, uint16 room) {
|
||||
dynalumInit(name, room);
|
||||
|
||||
uint32 size;
|
||||
char filename[20];
|
||||
sprintf(filename, "%s.PCX", name);
|
||||
uint8 *pcxBuf = _vm->resource()->loadFile(filename);
|
||||
uint32 size = _vm->resource()->fileSize(filename);
|
||||
uint8 *pcxBuf = _vm->resource()->loadFile(filename, 0, &size);
|
||||
_bdWidth = READ_LE_UINT16(pcxBuf + 12);
|
||||
_bdHeight = READ_LE_UINT16(pcxBuf + 14);
|
||||
readPCX(_backdropBuf, BACKDROP_W, pcxBuf + 128, _bdWidth, _bdHeight);
|
||||
|
@ -136,8 +136,10 @@ private:
|
||||
|
||||
struct Dynalum {
|
||||
bool valid;
|
||||
uint8 msk[50 * 160];
|
||||
int8 lum[8 * 3];
|
||||
uint8 *mskBuf;
|
||||
uint32 mskSize;
|
||||
int8 *lumBuf;
|
||||
uint32 lumSize;
|
||||
uint8 prevColMask;
|
||||
};
|
||||
|
||||
|
@ -181,10 +181,9 @@ void Logic::initialise() {
|
||||
|
||||
delete[] jas;
|
||||
|
||||
|
||||
_queen2jas = new LineReader(
|
||||
(char *)_vm->resource()->loadFile("QUEEN2.JAS"),
|
||||
_vm->resource()->fileSize("QUEEN2.JAS"));
|
||||
uint32 size;
|
||||
char *buf = (char *)_vm->resource()->loadFile("QUEEN2.JAS", 0, &size);
|
||||
_queen2jas = new LineReader(buf, size);
|
||||
|
||||
_objDescription = new char*[_numDescriptions + 1];
|
||||
_objDescription[0] = 0;
|
||||
|
@ -324,11 +324,9 @@ static const byte mt32_to_gm[128] = {
|
||||
|
||||
Music::Music(MidiDriver *driver, QueenEngine *vm) : _vToggle(false) {
|
||||
if (vm->resource()->isDemo()) {
|
||||
_musicData = vm->resource()->loadFile("AQ8.RL", 0, NULL);
|
||||
_musicDataSize = vm->resource()->fileSize("AQ8.RL");
|
||||
_musicData = vm->resource()->loadFile("AQ8.RL", 0, &_musicDataSize);
|
||||
} else {
|
||||
_musicData = vm->resource()->loadFile("AQ.RL", 0, NULL);
|
||||
_musicDataSize = vm->resource()->fileSize("AQ.RL");
|
||||
_musicData = vm->resource()->loadFile("AQ.RL", 0, &_musicDataSize);
|
||||
}
|
||||
|
||||
_player = new MusicPlayer(driver, _musicData, _musicDataSize);
|
||||
|
@ -329,7 +329,7 @@ void QueenEngine::go() {
|
||||
|
||||
void QueenEngine::initialise(void) {
|
||||
_bam = new BamScene(this);
|
||||
_resource = new Resource(_gameDataPath);
|
||||
_resource = new Resource();
|
||||
_bankMan = new BankManager(_resource);
|
||||
_command = new Command(this);
|
||||
_debugger = new Debugger(this);
|
||||
|
@ -52,11 +52,11 @@ static int compareResourceEntry(const void *a, const void *b) {
|
||||
return strcmp(filename, entry->filename);
|
||||
}
|
||||
|
||||
Resource::Resource(const Common::String &datafilePath)
|
||||
: _datafilePath(datafilePath), _resourceEntries(0), _resourceTable(NULL) {
|
||||
Resource::Resource()
|
||||
: _resourceEntries(0), _resourceTable(NULL) {
|
||||
_resourceFile = new File();
|
||||
if (!findCompressedVersion() && !findNormalVersion())
|
||||
error("Could not open resource file '%s%s'", _datafilePath.c_str(), "queen.1");
|
||||
error("Could not open resource file '%s'", "queen.1");
|
||||
checkJASVersion();
|
||||
debug(5, "Detected game version: %s, which has %d resource entries", _versionString, _resourceEntries);
|
||||
}
|
||||
@ -98,26 +98,28 @@ ResourceEntry *Resource::resourceEntry(const char *filename) const {
|
||||
return re;
|
||||
}
|
||||
|
||||
uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) {
|
||||
uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, uint32 *size, bool useMalloc) {
|
||||
ResourceEntry *re = resourceEntry(filename);
|
||||
assert(re != NULL);
|
||||
uint32 size = re->size - skipBytes;
|
||||
uint32 sz = re->size - skipBytes;
|
||||
if (size != NULL) {
|
||||
*size = sz;
|
||||
}
|
||||
byte *dstBuf;
|
||||
#ifndef __PALM_OS__
|
||||
if (dstBuf == NULL)
|
||||
dstBuf = new byte[size];
|
||||
if (useMalloc) {
|
||||
dstBuf = (byte *)malloc(sz);
|
||||
} else {
|
||||
dstBuf = new byte[sz];
|
||||
}
|
||||
#else
|
||||
if (dstBuf == NULL)
|
||||
dstBuf = (byte *)calloc(size, sizeof(byte));
|
||||
dstBuf = (byte *)calloc(sz, sizeof(byte));
|
||||
#endif
|
||||
_resourceFile->seek(re->offset + skipBytes);
|
||||
_resourceFile->read(dstBuf, size);
|
||||
_resourceFile->read(dstBuf, sz);
|
||||
return dstBuf;
|
||||
}
|
||||
|
||||
uint8 *Resource::loadFileMalloc(const char *filename, uint32 skipBytes, byte *dstBuf) {
|
||||
return loadFile(filename, skipBytes, (byte *)malloc(fileSize(filename) - skipBytes));
|
||||
}
|
||||
|
||||
bool Resource::findNormalVersion() {
|
||||
_resourceFile->open("queen.1");
|
||||
if (!_resourceFile->isOpen()) {
|
||||
@ -139,7 +141,7 @@ bool Resource::findNormalVersion() {
|
||||
_resourceEntries = 1076;
|
||||
_resourceTable = _resourceTablePEM10;
|
||||
} else {
|
||||
error("Could not find tablefile '%s%s'", _datafilePath.c_str(), _tableFilename);
|
||||
error("Could not find tablefile '%s'", _tableFilename);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -239,10 +241,13 @@ const GameVersion *Resource::detectGameVersion(uint32 size) const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
File *Resource::giveCompressedSound(const char *filename) {
|
||||
File *Resource::giveCompressedSound(const char *filename, uint32 *size) {
|
||||
assert(strstr(filename, ".SB"));
|
||||
ResourceEntry *re = resourceEntry(filename);
|
||||
assert(re != NULL);
|
||||
if (size != NULL) {
|
||||
*size = re->size;
|
||||
}
|
||||
_resourceFile->seek(re->offset);
|
||||
return _resourceFile;
|
||||
}
|
||||
|
@ -77,15 +77,13 @@ private:
|
||||
class Resource {
|
||||
|
||||
public:
|
||||
Resource(const Common::String &datafilePath);
|
||||
~Resource(void);
|
||||
Resource();
|
||||
~Resource();
|
||||
|
||||
uint8 *loadFile(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
|
||||
uint8 *loadFileMalloc(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
|
||||
uint8 *loadFile(const char *filename, uint32 skipBytes = 0, uint32 *size = NULL, bool useMalloc = false);
|
||||
bool fileExists(const char *filename) const { return resourceEntry(filename) != NULL; }
|
||||
uint32 fileSize(const char *filename) const { return resourceEntry(filename)->size; }
|
||||
|
||||
File *giveCompressedSound(const char *filename);
|
||||
File *giveCompressedSound(const char *filename, uint32 *size);
|
||||
|
||||
bool isDemo() const { return !strcmp(_versionString, "PE100"); }
|
||||
bool isInterview() const { return !strcmp(_versionString, "PEint"); }
|
||||
@ -104,9 +102,7 @@ public:
|
||||
protected:
|
||||
File *_resourceFile;
|
||||
uint8 _compression;
|
||||
const Common::String _datafilePath;
|
||||
char _versionString[6];
|
||||
const char *_savePath;
|
||||
uint32 _resourceEntries;
|
||||
ResourceEntry *_resourceTable;
|
||||
|
||||
|
@ -176,28 +176,40 @@ void SBSound::playSound(byte *sound, uint32 size, bool isSpeech) {
|
||||
}
|
||||
|
||||
void SBSound::sfxPlay(const char *name, bool isSpeech) {
|
||||
if (_vm->resource()->fileExists(name))
|
||||
playSound(_vm->resource()->loadFileMalloc(name, SB_HEADER_SIZE), _vm->resource()->fileSize(name) - SB_HEADER_SIZE, isSpeech);
|
||||
if (_vm->resource()->fileExists(name)) {
|
||||
uint32 size;
|
||||
uint8 *buf = _vm->resource()->loadFile(name, SB_HEADER_SIZE, &size, true);
|
||||
playSound(buf, size, isSpeech);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_MAD
|
||||
void MP3Sound::sfxPlay(const char *name, bool isSpeech) {
|
||||
if (_vm->resource()->fileExists(name))
|
||||
_mixer->playMP3(isSpeech ? &_speechHandle : &_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
|
||||
if (_vm->resource()->fileExists(name)) {
|
||||
uint32 size;
|
||||
File *f = _vm->resource()->giveCompressedSound(name, &size);
|
||||
_mixer->playMP3(isSpeech ? &_speechHandle : &_sfxHandle, f, size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_VORBIS
|
||||
void OGGSound::sfxPlay(const char *name, bool isSpeech) {
|
||||
if (_vm->resource()->fileExists(name))
|
||||
_mixer->playVorbis(isSpeech ? &_speechHandle : &_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
|
||||
if (_vm->resource()->fileExists(name)) {
|
||||
uint32 size;
|
||||
File *f = _vm->resource()->giveCompressedSound(name, &size);
|
||||
_mixer->playVorbis(isSpeech ? &_speechHandle : &_sfxHandle, f, size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_FLAC
|
||||
void FLACSound::sfxPlay(const char *name, bool isSpeech) {
|
||||
if (_vm->resource()->fileExists(name))
|
||||
_mixer->playFlac(isSpeech ? &_speechHandle : &_sfxHandle, _vm->resource()->giveCompressedSound(name), _vm->resource()->fileSize(name));
|
||||
if (_vm->resource()->fileExists(name)) {
|
||||
uint32 size;
|
||||
File *f = _vm->resource()->giveCompressedSound(name, &size);
|
||||
_mixer->playFlac(isSpeech ? &_speechHandle : &_sfxHandle, f, size);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user