diff options
-rw-r--r-- | engines/draci/barchive.cpp | 2 | ||||
-rw-r--r-- | engines/draci/barchive.h | 4 | ||||
-rw-r--r-- | engines/draci/draci.cpp | 52 | ||||
-rw-r--r-- | engines/draci/draci.h | 5 | ||||
-rw-r--r-- | engines/draci/game.cpp | 28 | ||||
-rw-r--r-- | engines/draci/mouse.cpp | 2 |
6 files changed, 56 insertions, 37 deletions
diff --git a/engines/draci/barchive.cpp b/engines/draci/barchive.cpp index c6d6354716..cd0d4b2172 100644 --- a/engines/draci/barchive.cpp +++ b/engines/draci/barchive.cpp @@ -391,7 +391,7 @@ void BArchive::clearCache() { } -BAFile *BArchive::operator[](unsigned int i) const { +BAFile *BArchive::getFile(unsigned int i) const { // Check whether requested file exists if (i >= _fileCount) { diff --git a/engines/draci/barchive.h b/engines/draci/barchive.h index 28c34fbcbb..185cfcb38d 100644 --- a/engines/draci/barchive.h +++ b/engines/draci/barchive.h @@ -53,7 +53,7 @@ class BArchive { public: BArchive() : _files(NULL), _fileCount(0), _opened(false) {} - BArchive(Common::String &path) : + BArchive(const Common::String &path) : _files(NULL), _fileCount(0), _opened(false) { openArchive(path); } @@ -72,7 +72,7 @@ public: void clearCache(); - BAFile *operator[](unsigned int i) const; + BAFile *getFile(unsigned int i) const; private: // Archive header data diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp index 4c4ed39ee3..f83a5994fd 100644 --- a/engines/draci/draci.cpp +++ b/engines/draci/draci.cpp @@ -42,6 +42,12 @@ namespace Draci { +// Data file paths + +const Common::String objectsPath("OBJEKTY.DFW"); +const Common::String palettePath("PALETY.DFW"); +const Common::String spritesPath("OBR_AN.DFW"); + DraciEngine::DraciEngine(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst) { // Put your engine in a sane state, but do nothing big yet; @@ -66,6 +72,11 @@ int DraciEngine::init() { // Initialize graphics using following: initGraphics(kScreenWidth, kScreenHeight, false); + // Open game's archives + _objectsArchive = new BArchive(objectsPath); + _spritesArchive = new BArchive(spritesPath); + _paletteArchive = new BArchive(palettePath); + _screen = new Screen(this); _font = new Font(); _mouse = new Mouse(this); @@ -75,6 +86,21 @@ int DraciEngine::init() { // Load default font _font->setFont(kFontBig); + if(!_objectsArchive->isOpen()) { + debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening objects archive failed"); + return Common::kUnknownError; + } + + if(!_spritesArchive->isOpen()) { + debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening sprites archive failed"); + return Common::kUnknownError; + } + + if(!_paletteArchive->isOpen()) { + debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening palette archive failed"); + return Common::kUnknownError; + } + // Basic archive test debugC(2, kDraciGeneralDebugLevel, "Running archive tests..."); Common::String path("INIT.DFW"); @@ -83,7 +109,7 @@ int DraciEngine::init() { debugC(3, kDraciGeneralDebugLevel, "Number of file streams in archive: %d", ar.size()); if(ar.isOpen()) { - f = ar[0]; + f = ar.getFile(0); } else { debugC(2, kDraciGeneralDebugLevel, "ERROR - Archive not opened"); return Common::kUnknownError; @@ -102,18 +128,9 @@ int DraciEngine::go() { debugC(2, kDraciGeneralDebugLevel, "Running graphics/animation test..."); - Common::String path("PALETY.DFW"); - BArchive ar(path); BAFile *f; - ar.openArchive(path); - - if(ar.isOpen()) { - f = ar[0]; - } else { - debugC(2, kDraciGeneralDebugLevel, "ERROR - Archive not opened"); - return Common::kUnknownError; - } + f = _paletteArchive->getFile(0); _screen->setPalette(f->_data, 0, kNumColours); @@ -157,13 +174,6 @@ int DraciEngine::go() { _screen->copyToScreen(); // Draw and animate the dragon - path = "OBR_AN.DFW"; - ar.openArchive(path); - - if(!ar.isOpen()) { - debugC(2, kDraciGeneralDebugLevel, "ERROR - Archive not opened"); - return Common::kUnknownError; - } testString = "I'm transparent"; xpos = (kScreenWidth - _font->getStringWidth(testString, 1)) / 2; @@ -177,7 +187,7 @@ int DraciEngine::go() { debugC(5, kDraciGeneralDebugLevel, "Drawing frame %d...", t); // Load frame to memory - f = ar[t]; + f = _spritesArchive->getFile(t); Sprite sp(f->_data, f->_length, ((kScreenWidth - 50) / 2), 60, 0); // Delete previous frame @@ -227,6 +237,10 @@ DraciEngine::~DraciEngine() { delete _mouse; delete _game; delete _script; + + delete _paletteArchive; + delete _objectsArchive; + delete _spritesArchive; // Remove all of our debug levels here Common::clearAllDebugChannels(); diff --git a/engines/draci/draci.h b/engines/draci/draci.h index ae9826464a..196dc0762e 100644 --- a/engines/draci/draci.h +++ b/engines/draci/draci.h @@ -35,6 +35,7 @@ #include "draci/screen.h" #include "draci/font.h" #include "draci/script.h" +#include "draci/barchive.h" namespace Draci { @@ -55,6 +56,10 @@ public: Game *_game; Script *_script; + BArchive *_objectsArchive; + BArchive *_spritesArchive; + BArchive *_paletteArchive; + private: Common::RandomSource _rnd; }; diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index d13883087c..c423292b0d 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -41,7 +41,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) { // Read in persons - file = initArchive[5]; + file = initArchive.getFile(5); Common::MemoryReadStream personData(file->_data, file->_length); unsigned int numPersons = file->_length / personSize; @@ -55,7 +55,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) { // Read in dialog offsets - file = initArchive[4]; + file = initArchive.getFile(4); Common::MemoryReadStream dialogData(file->_data, file->_length); unsigned int numDialogs = file->_length / sizeof(uint16); @@ -69,7 +69,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) { // Read in game info - file = initArchive[3]; + file = initArchive.getFile(3); Common::MemoryReadStream gameData(file->_data, file->_length); _info = new GameInfo(); @@ -92,7 +92,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) { // Read in variables - file = initArchive[2]; + file = initArchive.getFile(2); unsigned int numVariables = file->_length / sizeof (int16); _variables = new int16[numVariables]; @@ -104,13 +104,13 @@ Game::Game(DraciEngine *vm) : _vm(vm) { // Read in item status - file = initArchive[1]; + file = initArchive.getFile(1); _itemStatus = new byte[file->_length]; memcpy(_itemStatus, file->_data, file->_length); // Read in object status - file = initArchive[0]; + file = initArchive.getFile(0); unsigned int numObjects = file->_length; _objects = new GameObject[numObjects]; @@ -136,15 +136,15 @@ Game::Game(DraciEngine *vm) : _vm(vm) { } void Game::loadObject(uint16 objNum) { - Common::String path("OBJEKTY.DFW"); - - BArchive objArchive(path); BAFile *file; - file = objArchive[objNum * 3]; + // Convert to real index (indexes begin with 1 in the data files) + objNum -= 1; + + file = _vm->_objectsArchive->getFile(objNum * 3); Common::MemoryReadStream objReader(file->_data, file->_length); - GameObject *obj = getObject(objNum); + GameObject *obj = _objects + objNum; obj->_init = objReader.readUint16LE(); obj->_look = objReader.readUint16LE(); @@ -169,11 +169,11 @@ void Game::loadObject(uint16 objNum) { obj->_seqTab = new uint16[obj->_numSeq]; - file = objArchive[objNum * 3 + 1]; + file = _vm->_objectsArchive->getFile(objNum * 3 + 1); obj->_title = new byte[file->_length]; memcpy(obj->_title, file->_data, file->_length); - file = objArchive[objNum * 3 + 2]; + file = _vm->_objectsArchive->getFile(objNum * 3 + 2); obj->_program._bytecode = new byte[file->_length]; obj->_program._length = file->_length; memcpy(obj->_program._bytecode, file->_data, file->_length); @@ -184,7 +184,7 @@ GameObject *Game::getObject(uint16 objNum) { // Convert to real index (indexes begin with 1 in the data files) objNum -= 1; - return &_objects[objNum]; + return _objects + objNum; } Game::~Game() { diff --git a/engines/draci/mouse.cpp b/engines/draci/mouse.cpp index cbd3cd7a59..b4c0aea542 100644 --- a/engines/draci/mouse.cpp +++ b/engines/draci/mouse.cpp @@ -90,7 +90,7 @@ void Mouse::setCursorType(CursorType cur) { ar.openArchive(path); if(ar.isOpen()) { - f = ar[_cursorType]; + f = ar.getFile(_cursorType); } else { debugC(2, kDraciGeneralDebugLevel, "ERROR - Archive not opened - %s", path.c_str()); return; |