ACCESS: Added screen loading and file index load fixes

This commit is contained in:
Paul Gilbert 2014-08-02 17:09:28 -04:00
parent a35ba4caf9
commit 7a63e12edb
7 changed files with 139 additions and 39 deletions

View File

@ -35,8 +35,14 @@ void AmazonEngine::doTitle() {
_screen->forceFadeOut();
_events->hideCursor();
_sound->loadSound(98, 30);
_sound->_soundTable[0] = _sound->loadSound(98, 30);
_sound->_soundPriority[0] = 1;
_sound->_soundTable[1] = _sound->loadSound(98, 8);
_sound->_soundPriority[1] = 2;
_screen->_loadPalFlag = false;
byte *scr = _files->loadScreen(0, 3);
_screen->copyBuffer(scr);
}
} // End of namespace Amazon

View File

@ -44,41 +44,72 @@ FileManager::~FileManager() {
_file.close();
}
void FileManager::loadFile(int fileNum, int subfile) {
byte *FileManager::loadFile(int fileNum, int subfile) {
setAppended(fileNum);
gotoAppended(subfile);
handleFile();
return handleFile();
}
void FileManager::loadFile(const Common::String &filename) {
// Open up the file
_fileNumber = -1;
_file.close();
if (_file.open(filename))
error("Could not open file - %s", filename.c_str());
byte *FileManager::loadFile(const Common::String &filename) {
// Open the file
openFile(filename);
// Get a stream for the entire file
delete _stream;
_stream = _file.readStream(_file.size());
handleFile();
return handleFile();
}
void FileManager::handleFile() {
void FileManager::openFile(const Common::String &filename) {
// Open up the file
_fileNumber = -1;
_file.close();
if (_file.open(filename))
error("Could not open file - %s", filename.c_str());
}
byte *FileManager::loadScreen(int fileNum, int subfile) {
setAppended(fileNum);
gotoAppended(subfile);
_vm->_screen->loadPalette(_stream);
return handleFile();
}
byte *FileManager::loadScreen(const Common::String &filename) {
// Open the file
openFile(filename);
// Get the palette
_vm->_screen->loadPalette(_stream);
// Get a stream for the remainder of the file
delete _stream;
_stream = _file.readStream(_file.size());
return handleFile();
}
byte *FileManager::handleFile() {
char header[3];
_stream->read(&header[0], 3);
if (!strncmp(header, "BDE", 3))
if (!strncmp(header, "DBE", 3))
// Decompress the resource
decompressFile();
else
// Not compressed, so move back to start of data
_stream->seek(0);
return decompressFile();
// Not compressed, so pass out all of the file
_stream->seek(0);
byte *data = new byte[_stream->size()];
_stream->read(data, _stream->size());
return data;
}
void FileManager::decompressFile() {
// TODO
byte *FileManager::decompressFile() {
error("TODO: decompression");
}
void FileManager::setAppended(int fileNum) {
@ -90,17 +121,17 @@ void FileManager::setAppended(int fileNum) {
error("Could not open file %s", _filenames[fileNum]);
// Read in the file index
_fileIndex.resize(50);
for (int i = 0; i < 50; ++i) {
_fileIndex[i]._offset = _file.readUint32LE();
_fileIndex[i]._nextOffset = _file.readUint32LE();
}
int count = _file.readUint16LE();
assert(count <= 100);
_fileIndex.resize(count);
for (int i = 0; i < count; ++i)
_fileIndex[i] = _file.readUint32LE();
}
}
void FileManager::gotoAppended(int subfile) {
uint32 offset = _fileIndex[subfile]._offset;
uint32 size = _fileIndex[subfile]._nextOffset - offset;
uint32 offset = _fileIndex[subfile];
uint32 size = _fileIndex[subfile + 1] - offset;
_file.seek(offset);
delete _stream;

View File

@ -24,47 +24,60 @@
#define ACCESS_FILES_H
#include "common/scummsys.h"
#include "common/array.h"
#include "common/file.h"
namespace Access {
class AccessEngine;
struct FileEntry {
uint32 _offset;
uint32 _nextOffset;
};
class FileManager {
private:
AccessEngine *_vm;
const char * const *_filenames;
void handleFile();
void openFile(const Common::String &filename);
void decompressFile();
byte *handleFile();
byte *decompressFile();
public:
int _fileNumber;
Common::File _file;
Common::SeekableReadStream *_stream;
Common::Array<FileEntry> _fileIndex;
Common::Array<uint32> _fileIndex;
uint32 _entryOffset;
uint32 _nextOffset;
public:
FileManager(AccessEngine *vm);
~FileManager();
void loadFile(int fileNum, int subfile);
/**
* Load a given subfile from a container file
*/
byte *loadFile(int fileNum, int subfile);
void loadFile(const Common::String &filename);
/**
* Load a given file by name
*/
byte *loadFile(const Common::String &filename);
/**
* Load a given scren from a container file
*/
byte *loadScreen(int fileNum, int subfile);
/**
* Load a given screen by name
*/
byte *loadScreen(const Common::String &filename);
/**
* Open up a sub-file container file
*/
void setAppended(int fileNum);
/**
* Open up a sub-file resource within an alrady opened container file.
*/

View File

@ -32,6 +32,7 @@ namespace Access {
Screen::Screen(AccessEngine *vm) : _vm(vm) {
create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
Common::fill(&_tempPalette[0], &_tempPalette[PALETTE_SIZE], 0);
_loadPalFlag = false;
}
void Screen::setDisplayScan() {
@ -49,6 +50,16 @@ void Screen::setInitialPalettte() {
g_system->getPaletteManager()->setPalette(INITIAL_PALETTE, 0, 18);
}
void Screen::loadPalette(Common::SeekableReadStream *stream) {
stream->read(&_rawPalette[0], PALETTE_SIZE);
setPalette();
_loadPalFlag = true;
}
void Screen::setPalette() {
g_system->getPaletteManager()->setPalette(&_rawPalette[0], 0, PALETTE_COUNT);
}
void Screen::updatePalette() {
g_system->getPaletteManager()->setPalette(&_tempPalette[0], 0, PALETTE_COUNT);
updateScreen();
@ -97,4 +108,10 @@ void Screen::forceFadeIn() {
} while (repeatFlag);
}
void Screen::copyBuffer(const byte *data) {
byte *destP = (byte *)getPixels();
Common::copy(data, data + (h * w), destP);
g_system->copyRectToScreen(destP, w, 0, 0, w, h);
}
} // End of namespace Access

View File

@ -25,6 +25,7 @@
#include "common/scummsys.h"
#include "common/rect.h"
#include "common/stream.h"
#include "graphics/surface.h"
namespace Access {
@ -40,7 +41,11 @@ private:
byte _tempPalette[PALETTE_SIZE];
byte _rawPalette[PALETTE_SIZE];
void setPalette();
void updatePalette();
public:
bool _loadPalFlag;
public:
Screen(AccessEngine *vm);
@ -65,6 +70,13 @@ public:
* Set the initial palette
*/
void setInitialPalettte();
void loadPalette(Common::SeekableReadStream *stream);
/**
* Copy a buffer to the screen
*/
void copyBuffer(const byte *data);
};
} // End of namespace Access

View File

@ -20,10 +20,25 @@
*
*/
#include "common/algorithm.h"
#include "access/access.h"
#include "access/sound.h"
namespace Access {
SoundManager::SoundManager(AccessEngine *vm) : _vm(vm) {}
SoundManager::SoundManager(AccessEngine *vm) : _vm(vm) {
Common::fill(&_soundTable[0], &_soundTable[MAX_SOUNDS], (byte *)nullptr);
Common::fill(&_soundPriority[0], &_soundPriority[MAX_SOUNDS], 0);
}
SoundManager::~SoundManager() {
for (int i = 0; i < MAX_SOUNDS; ++i)
delete _soundTable[i];
}
byte *SoundManager::loadSound(int fileNum, int subfile) {
return _vm->_files->loadFile(fileNum, subfile);
}
} // End of namespace Access

View File

@ -23,6 +23,10 @@
#ifndef ACCESS_SOUND_H
#define ACCESS_SOUND_H
#include "common/scummsys.h"
#define MAX_SOUNDS 20
namespace Access {
class AccessEngine;
@ -31,11 +35,13 @@ class SoundManager {
private:
AccessEngine *_vm;
public:
int _soundPriority;
byte *_soundTable[MAX_SOUNDS];
int _soundPriority[MAX_SOUNDS];
public:
SoundManager(AccessEngine *vm);
~SoundManager();
void loadSound(int fileNum, int subfile) {}
byte *loadSound(int fileNum, int subfile);
};
} // End of namespace Access